sapling/addons/verify-addons-folder.py
Jun Wu 8bc196d689 move reviewstack to a different npm workspace
Summary:
The reviestack has diveraged from the main ISL project in terms of key dependencies.
Namely, ISL no longer uses `react-scripts` (which depends on many ancient
packages and makes them hard to upgrade), no longer used the webpack eco-system,
and is going to drop `recoil` soon. Per discussion, we think it's beneficial
to move ReviewStack to its own place. This diff does that. For shared code
they are simply duplicated.

Reviewed By: evangrayk

Differential Revision: D53649151

fbshipit-source-id: 7bcaf10a4c70a79b73c56d75765dfba3ec33e5f7
2024-02-12 15:28:10 -08:00

128 lines
3.2 KiB
Python
Executable File

#!/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
""",
formatter_class=RawTextHelpFormatter,
)
parser.add_argument(
"--use-vendored-grammars",
help=("No-op. Provided for compatibility."),
action="store_true",
)
args = parser.parse_args()
asyncio.run(verify())
async def verify():
await asyncio.gather(
verify_prettier(),
verify_shared(),
verify_textmate(),
verify_isl(),
)
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_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():
"""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),
)
timer.report(ok("ISL"))
async def lint_and_test(cwd: Path):
await asyncio.gather(
run(["yarn", "run", "eslint"], 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()