Skip to content

Commit d7e29fc

Browse files
committed
Add smoke test script in Python
1 parent 80b0d4c commit d7e29fc

File tree

3 files changed

+96
-14
lines changed

3 files changed

+96
-14
lines changed

.github/workflows/ci.yml

+33-14
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ jobs:
714714
name: "smoke test | linux"
715715
runs-on: ubuntu-latest
716716
steps:
717+
- uses: actions/checkout@v4
718+
717719
- name: "Download binary"
718720
uses: actions/download-artifact@v4
719721
with:
@@ -726,9 +728,10 @@ jobs:
726728
727729
- name: "Smoke test"
728730
run: |
729-
./uv venv -v
730-
./uv pip install ruff -v
731-
./uvx -v ruff --version
731+
./uv run scripts/smoke-test
732+
733+
- name: "Test shell completions"
734+
run: |
732735
eval "$(./uv generate-shell-completion bash)"
733736
eval "$(./uvx --generate-shell-completion bash)"
734737
@@ -738,6 +741,8 @@ jobs:
738741
name: "smoke test | macos"
739742
runs-on: macos-latest
740743
steps:
744+
- uses: actions/checkout@v4
745+
741746
- name: "Download binary"
742747
uses: actions/download-artifact@v4
743748
with:
@@ -750,9 +755,10 @@ jobs:
750755
751756
- name: "Smoke test"
752757
run: |
753-
./uv venv -v
754-
./uv pip install ruff -v
755-
./uvx -v ruff --version
758+
./uv run scripts/smoke-test
759+
760+
- name: "Test shell completions"
761+
run: |
756762
eval "$(./uv generate-shell-completion bash)"
757763
eval "$(./uvx --generate-shell-completion bash)"
758764
@@ -762,6 +768,8 @@ jobs:
762768
name: "smoke test | windows x86_64"
763769
runs-on: windows-latest
764770
steps:
771+
- uses: actions/checkout@v4
772+
765773
- name: "Download binary"
766774
uses: actions/download-artifact@v4
767775
with:
@@ -770,10 +778,16 @@ jobs:
770778
- name: "Smoke test"
771779
working-directory: ${{ env.UV_WORKSPACE }}
772780
run: |
773-
./uv venv -v
774-
./uv pip install ruff -v
775-
./uvx -v ruff --version
781+
./uv run scripts/smoke-test
782+
783+
- name: "Test uv shell completions"
784+
working-directory: ${{ env.UV_WORKSPACE }}
785+
run: |
776786
(& ./uv generate-shell-completion powershell) | Out-String | Invoke-Expression
787+
788+
- name: "Test uvx shell completions"
789+
working-directory: ${{ env.UV_WORKSPACE }}
790+
run: |
777791
(& ./uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression
778792
779793
smoke-test-windows-aarch64:
@@ -782,6 +796,8 @@ jobs:
782796
name: "smoke test | windows aarch64"
783797
runs-on: github-windows-11-aarch64-4
784798
steps:
799+
- uses: actions/checkout@v4
800+
785801
- name: "Download binary"
786802
uses: actions/download-artifact@v4
787803
with:
@@ -790,13 +806,16 @@ jobs:
790806
- name: "Smoke test"
791807
working-directory: ${{ env.UV_WORKSPACE }}
792808
run: |
793-
$ErrorActionPreference = "Stop"
794-
$PSNativeCommandUseErrorActionPreference = $true
809+
./uv run scripts/smoke-test
795810
796-
./uv venv -v
797-
./uv pip install ruff -v
798-
./uvx -v ruff --version
811+
- name: "Test uv shell completions"
812+
working-directory: ${{ env.UV_WORKSPACE }}
813+
run: |
799814
(& ./uv generate-shell-completion powershell) | Out-String | Invoke-Expression
815+
816+
- name: "Test uvx shell completions"
817+
working-directory: ${{ env.UV_WORKSPACE }}
818+
run: |
800819
(& ./uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression
801820
802821
integration-test-conda:

scripts/smoke-test/__main__.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
import pathlib
3+
import subprocess
4+
import sys
5+
6+
SELF_FILE = pathlib.Path(__file__)
7+
COMMANDS_FILE = SELF_FILE.parent / "commands.sh"
8+
9+
10+
def read_commands() -> list[list[str]]:
11+
return [
12+
line.split()
13+
for line in COMMANDS_FILE.read_text().splitlines()
14+
# Skip empty lines and comments
15+
if line.strip() and not line.strip().startswith("#")
16+
]
17+
18+
19+
def run_command(command: list[str]) -> subprocess.CompletedProcess:
20+
env = os.environ.copy()
21+
# Prepend either the parent uv path to the PATH or the current directory
22+
env = {
23+
**env,
24+
"PATH": str(
25+
pathlib.Path(env.get("UV")).parent if "UV" in env else pathlib.Path.cwd()
26+
)
27+
+ os.pathsep
28+
+ env.get("PATH"),
29+
}
30+
return subprocess.run(command, capture_output=True, text=True, env=env)
31+
32+
33+
def report_result(result: subprocess.CompletedProcess) -> str:
34+
print("=============================================")
35+
print(f"command: {' '.join(result.args)}")
36+
print(f"exit code: {result.returncode}")
37+
print()
38+
print("------- stdout -------")
39+
print(result.stdout)
40+
print()
41+
print("------- stderr -------")
42+
print(result.stderr)
43+
44+
45+
def main():
46+
results = [run_command(command) for command in read_commands()]
47+
failed = sum(result.returncode != 0 for result in results)
48+
for result in results:
49+
report_result(result)
50+
51+
if failed:
52+
print("{failed}/{len(results)} commands failed")
53+
sys.exit(1)
54+
55+
56+
main()

scripts/smoke-test/commands.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Note this is not a real shell-script, it's parsed by `smoke-test/__main__.py` and executed
2+
# serially via Python.
3+
4+
uv venv -v
5+
uv pip install ruff -v
6+
uvx -v ruff --version
7+

0 commit comments

Comments
 (0)