Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smoke test script in Python #11628

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)"

Expand All @@ -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:
Expand All @@ -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)"

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
59 changes: 59 additions & 0 deletions scripts/smoke-test/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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):
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)

print("=============================================")
if failed:
print(f"FAILURE - {failed}/{len(results)} commands failed")
sys.exit(1)
else:
print(f"SUCCESS - {len(results)}/{len(results)} commands succeeded")


main()
7 changes: 7 additions & 0 deletions scripts/smoke-test/commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Note this is not a real shell-script, it's parsed by `smoke-test/__main__.py` and executed
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably could just have a list of shell scripts here and actually run them with a shell, but just doing something that fulfills the current needs right now.

# serially via Python.

uv venv -v
uv pip install ruff -v
uvx -v ruff --version

Loading