From d7e29fc08323505159352badf53ab4ca34c4a6d7 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Feb 2025 11:37:39 -0600 Subject: [PATCH 1/2] Add smoke test script in Python --- .github/workflows/ci.yml | 47 +++++++++++++++++++--------- scripts/smoke-test/__main__.py | 56 ++++++++++++++++++++++++++++++++++ scripts/smoke-test/commands.sh | 7 +++++ 3 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 scripts/smoke-test/__main__.py create mode 100644 scripts/smoke-test/commands.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab0f72b78464..a5cb18bfe08f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -714,6 +714,8 @@ jobs: name: "smoke test | linux" runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + - name: "Download binary" uses: actions/download-artifact@v4 with: @@ -726,9 +728,10 @@ jobs: - name: "Smoke test" run: | - ./uv venv -v - ./uv pip install ruff -v - ./uvx -v ruff --version + ./uv run scripts/smoke-test + + - name: "Test shell completions" + run: | eval "$(./uv generate-shell-completion bash)" eval "$(./uvx --generate-shell-completion bash)" @@ -738,6 +741,8 @@ jobs: name: "smoke test | macos" runs-on: macos-latest steps: + - uses: actions/checkout@v4 + - name: "Download binary" uses: actions/download-artifact@v4 with: @@ -750,9 +755,10 @@ jobs: - name: "Smoke test" run: | - ./uv venv -v - ./uv pip install ruff -v - ./uvx -v ruff --version + ./uv run scripts/smoke-test + + - name: "Test shell completions" + run: | eval "$(./uv generate-shell-completion bash)" eval "$(./uvx --generate-shell-completion bash)" @@ -762,6 +768,8 @@ jobs: name: "smoke test | windows x86_64" runs-on: windows-latest steps: + - uses: actions/checkout@v4 + - name: "Download binary" uses: actions/download-artifact@v4 with: @@ -770,10 +778,16 @@ jobs: - name: "Smoke test" working-directory: ${{ env.UV_WORKSPACE }} run: | - ./uv venv -v - ./uv pip install ruff -v - ./uvx -v ruff --version + ./uv run scripts/smoke-test + + - name: "Test uv shell completions" + working-directory: ${{ env.UV_WORKSPACE }} + run: | (& ./uv generate-shell-completion powershell) | Out-String | Invoke-Expression + + - name: "Test uvx shell completions" + working-directory: ${{ env.UV_WORKSPACE }} + run: | (& ./uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression smoke-test-windows-aarch64: @@ -782,6 +796,8 @@ jobs: name: "smoke test | windows aarch64" runs-on: github-windows-11-aarch64-4 steps: + - uses: actions/checkout@v4 + - name: "Download binary" uses: actions/download-artifact@v4 with: @@ -790,13 +806,16 @@ jobs: - name: "Smoke test" working-directory: ${{ env.UV_WORKSPACE }} run: | - $ErrorActionPreference = "Stop" - $PSNativeCommandUseErrorActionPreference = $true + ./uv run scripts/smoke-test - ./uv venv -v - ./uv pip install ruff -v - ./uvx -v ruff --version + - name: "Test uv shell completions" + working-directory: ${{ env.UV_WORKSPACE }} + run: | (& ./uv generate-shell-completion powershell) | Out-String | Invoke-Expression + + - name: "Test uvx shell completions" + working-directory: ${{ env.UV_WORKSPACE }} + run: | (& ./uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression integration-test-conda: diff --git a/scripts/smoke-test/__main__.py b/scripts/smoke-test/__main__.py new file mode 100644 index 000000000000..30696c290d30 --- /dev/null +++ b/scripts/smoke-test/__main__.py @@ -0,0 +1,56 @@ +import os +import pathlib +import subprocess +import sys + +SELF_FILE = pathlib.Path(__file__) +COMMANDS_FILE = SELF_FILE.parent / "commands.sh" + + +def read_commands() -> list[list[str]]: + return [ + line.split() + for line in COMMANDS_FILE.read_text().splitlines() + # Skip empty lines and comments + if line.strip() and not line.strip().startswith("#") + ] + + +def run_command(command: list[str]) -> subprocess.CompletedProcess: + env = os.environ.copy() + # Prepend either the parent uv path to the PATH or the current directory + env = { + **env, + "PATH": str( + pathlib.Path(env.get("UV")).parent if "UV" in env else pathlib.Path.cwd() + ) + + os.pathsep + + env.get("PATH"), + } + return subprocess.run(command, capture_output=True, text=True, env=env) + + +def report_result(result: subprocess.CompletedProcess) -> str: + print("=============================================") + print(f"command: {' '.join(result.args)}") + print(f"exit code: {result.returncode}") + print() + print("------- stdout -------") + print(result.stdout) + print() + print("------- stderr -------") + print(result.stderr) + + +def main(): + results = [run_command(command) for command in read_commands()] + failed = sum(result.returncode != 0 for result in results) + for result in results: + report_result(result) + + if failed: + print("{failed}/{len(results)} commands failed") + sys.exit(1) + + +main() diff --git a/scripts/smoke-test/commands.sh b/scripts/smoke-test/commands.sh new file mode 100644 index 000000000000..2512cca5c13a --- /dev/null +++ b/scripts/smoke-test/commands.sh @@ -0,0 +1,7 @@ +# Note this is not a real shell-script, it's parsed by `smoke-test/__main__.py` and executed +# serially via Python. + +uv venv -v +uv pip install ruff -v +uvx -v ruff --version + From 6585fc1872087fd152a211a983334796a5822c5e Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Feb 2025 12:09:53 -0600 Subject: [PATCH 2/2] Fix final output --- scripts/smoke-test/__main__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/smoke-test/__main__.py b/scripts/smoke-test/__main__.py index 30696c290d30..8381a34c464d 100644 --- a/scripts/smoke-test/__main__.py +++ b/scripts/smoke-test/__main__.py @@ -30,7 +30,7 @@ def run_command(command: list[str]) -> subprocess.CompletedProcess: return subprocess.run(command, capture_output=True, text=True, env=env) -def report_result(result: subprocess.CompletedProcess) -> str: +def report_result(result: subprocess.CompletedProcess): print("=============================================") print(f"command: {' '.join(result.args)}") print(f"exit code: {result.returncode}") @@ -48,9 +48,12 @@ def main(): for result in results: report_result(result) + print("=============================================") if failed: - print("{failed}/{len(results)} commands failed") + print(f"FAILURE - {failed}/{len(results)} commands failed") sys.exit(1) + else: + print(f"SUCCESS - {len(results)}/{len(results)} commands succeeded") main()