Repository navigation
182 lines (156 loc) · 5.28 KB
/
Copy pathtest_python_test.yml
File metadata and controls
182 lines (156 loc) · 5.28 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Test python_test
# End-to-end test: build a tiny Python package on a throwaway orphan branch (with a conda environment file and a
# freshly generated pixi.lock), upload a fake external tool as an artifact, then run the python_test_pip, _conda and
# _pixi wrappers against it with pip (with the tool on PATH), conda and pixi. Each call fails if its tests fail; the branch is deleted
# afterwards.
on:
workflow_dispatch:
push:
branches: [main]
paths:
- .github/workflows/python_test.yml
- .github/workflows/python_test_pip.yml
- .github/workflows/python_test_conda.yml
- .github/workflows/python_test_pixi.yml
- .github/workflows/test_python_test.yml
concurrency:
group: test-python-test
cancel-in-progress: false
permissions:
contents: write
env:
BASE: test/python-${{ github.run_id }}
jobs:
setup:
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.fixture.outputs.ref }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Write fixture package
run: |
git switch --orphan "$BASE"
mkdir -p src/fixturepkg tests
cat > pyproject.toml <<'TOML'
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "fixturepkg"
version = "0.1.0"
requires-python = ">=3.10"
[project.optional-dependencies]
dev = ["pytest"]
TOML
cat > src/fixturepkg/__init__.py <<'PY'
def answer() -> int:
return 42
PY
cat > tests/test_fixturepkg.py <<'PY'
import fixturepkg
def test_answer() -> None:
assert fixturepkg.answer() == 42
PY
cat > environment.yml <<'YML'
name: fixture
channels:
- conda-forge
dependencies:
- python
- pip
- pytest
- pip:
- -e .
YML
cat > pixi.toml <<'TOML'
[workspace]
name = "fixture"
channels = ["conda-forge"]
platforms = ["linux-64"]
[dependencies]
python = "3.12.*"
pytest = "*"
[pypi-dependencies]
fixturepkg = { path = ".", editable = true }
TOML
- name: Set up pixi
uses: prefix-dev/setup-pixi@ad1da6449d9e506fd127fd67ab2d054a769f6a94 # v0.11.2
with:
run-install: false
- name: Generate pixi.lock and push fixture branch
id: fixture
run: |
pixi lock
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Test fixture"
git push origin "$BASE"
echo "ref=$BASE" >> "$GITHUB_OUTPUT"
- name: Create fake external tool
run: |
mkdir tool
printf '#!/bin/sh\necho fixture-tool ok\n' > tool/fixture-tool
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: tool-fixture
path: tool/fixture-tool
pip:
needs: setup
uses: ./.github/workflows/python_test_pip.yml
with:
ref: ${{ needs.setup.outputs.ref }}
python_versions: '["3.10", "3.13"]'
tools_artifact_pattern: tool-*
# fixture-tool fails unless the tool artifact is on PATH and executable
test_command: |
fixture-tool
python -c "import fixturepkg, sys; print(sys.version)"
pytest -v
conda:
needs: setup
uses: ./.github/workflows/python_test_conda.yml
with:
ref: ${{ needs.setup.outputs.ref }}
python_versions: '["3.12"]'
# Fails unless the tests run inside the conda environment with the requested Python
test_command: |
python -c 'import sys; assert sys.version_info[:2] == (3, 12), sys.version'
python -c 'import fixturepkg, sys; assert sys.prefix.endswith("/envs/test"), sys.prefix'
pytest -v
pixi:
needs: setup
uses: ./.github/workflows/python_test_pixi.yml
with:
ref: ${{ needs.setup.outputs.ref }}
# Fails unless the tests run inside the pixi environment
test_command: |
python -c 'import fixturepkg, sys; assert "/.pixi/envs/default" in sys.prefix, sys.prefix'
pytest -v
cleanup:
needs: [setup, pip, conda, pixi]
if: always()
runs-on: ubuntu-latest
steps:
- name: Delete fixture branch
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
failed=0
# Deletes refs/<$1>. A ref that is already gone is fine; any other error fails the job after all deletions
# have been attempted, so leftovers are noticed.
delete_ref() {
local out
if out=$(gh api -X DELETE "repos/${REPO}/git/refs/$1" 2>&1); then
echo "Deleted $1"
elif grep -q "Reference does not exist" <<<"$out"; then
echo "Already gone: $1"
else
echo "::error::Could not delete $1: $out"
failed=1
fi
}
delete_ref "heads/${BASE}"
exit "$failed"