forked from facebook/sapling
-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify-addons-folder.py
executable file
·150 lines (119 loc) · 4.08 KB
/
verify-addons-folder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import asyncio
import shutil
import time
from argparse import RawTextHelpFormatter
from pathlib import Path
from typing import List
addons = Path(__file__).parent
def main():
parser = argparse.ArgumentParser(
description="""\
Verifies the contents of this folder by running tests and linters.
Requirements:
- `node` and `yarn` are on the `$PATH`
- `yarn install` has already been run in the addons/ folder
- `sl` required to be on the PATH for isl integration tests
""",
formatter_class=RawTextHelpFormatter,
)
parser.add_argument(
"--use-vendored-grammars",
help=("No-op. Provided for compatibility."),
action="store_true",
)
parser.add_argument(
"--skip-integration-tests",
help=("Don't run isl integrations tests"),
action="store_true",
)
args = parser.parse_args()
asyncio.run(verify(args))
async def verify(args):
await asyncio.gather(
verify_prettier(),
verify_shared(),
verify_components(),
verify_textmate(),
verify_isl(args),
)
async def verify_prettier():
timer = Timer("verifying prettier")
await run(["yarn", "run", "prettier-check"], cwd=addons)
timer.report(ok("prettier"))
async def verify_shared():
timer = Timer("verifying shared/")
shared = addons / "shared"
await lint_and_test(shared)
timer.report(ok("shared/"))
async def verify_components():
timer = Timer("verifying components/")
components = addons / "components"
await lint_and_test(components)
timer.report(ok("components/"))
async def verify_textmate():
timer = Timer("verifying textmate/")
textmate = addons / "textmate"
await asyncio.gather(
run(["yarn", "run", "tsc", "--noEmit"], cwd=textmate),
run(["yarn", "run", "eslint"], cwd=textmate),
)
timer.report(ok("textmate/"))
async def verify_isl(args):
"""Verifies isl/ and isl-server/ and vscode/ as the builds are interdependent"""
timer = Timer("verifying ISL")
isl = addons / "isl"
isl_server = addons / "isl-server"
vscode = addons / "vscode"
await run(["yarn", "codegen"], cwd=isl_server)
await asyncio.gather(
run(["yarn", "build"], cwd=isl_server),
run(["yarn", "build"], cwd=isl),
)
await asyncio.gather(
run(["yarn", "build-extension"], cwd=vscode),
run(["yarn", "build-webview"], cwd=vscode),
)
await asyncio.gather(
lint_and_test(isl),
lint_and_test(isl_server),
lint_and_test(vscode),
)
if not args.skip_integration_tests:
timer.report("running isl integration tests")
# run integration tests separately to reduce flakiness from CPU contention with normal unit tests
await run_isl_integration_tests()
timer.report(ok("ISL"))
async def run_isl_integration_tests():
await run(["yarn", "integration", "--watchAll=false"], cwd="isl")
async def lint_and_test(cwd: Path):
await asyncio.gather(
run(["yarn", "run", "eslint"], cwd=cwd),
run(["yarn", "run", "tsc", "--noEmit"], cwd=cwd),
run(["yarn", "test", "--watchAll=false"], cwd=cwd),
)
async def run(args: List[str], cwd: str):
process = await asyncio.create_subprocess_exec(
*args, cwd=cwd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
print(f"[stdout]\n{stdout.decode()}")
print(f"[stderr]\n{stderr.decode()}")
raise RuntimeError(f"command failed: {' '.join(args)}")
def ok(message: str) -> str:
return f"\033[0;32mOK\033[00m {message}"
class Timer:
def __init__(self, message):
self._start = time.time()
print(message)
def report(self, message: str):
end = time.time()
duration = end - self._start
print(f"{message} in {duration:.2f}s")
main()