Repository navigation
263 lines (258 loc) · 9.99 KB
/
Copy pathtest.yml
File metadata and controls
263 lines (258 loc) · 9.99 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Test
on:
workflow_call:
inputs:
extras:
type: string
default: dev
description: Comma-separated extras installed with the wheel (library mode).
pixi-add:
type: string
default: ''
description: Space-separated conda specs added to the env (library mode).
uv-locked:
type: boolean
default: false
description: Install dependencies from uv.lock before the wheel (library mode).
cooldown:
type: string
default: 7d
description: Ignore conda and PyPI releases newer than this age, e.g. 7d. Empty disables. uv-locked installs ignore it.
matrix:
type: string
default: auto
description: auto, single, lean or full.
python-versions:
type: string
default: ''
description: JSON list of Python versions. Default from trove classifiers.
os-full:
type: string
default: '["ubuntu-latest","macos-latest","windows-latest"]'
description: JSON list of runners for the full matrix.
pytest-args:
type: string
default: ''
description: Extra arguments for pytest or the pixi task.
test-command:
type: string
default: ''
description: Command run inside the env instead of the default test command.
pixi-task:
type: string
default: ''
description: pixi task to run. Non-empty switches to project mode.
pixi-environments:
type: string
default: '["default"]'
description: Project mode. JSON list of pixi environments or a regex matched against them.
manifest-path:
type: string
default: ''
description: Project mode manifest, relative to working-directory.
pixi-version:
type: string
default: v0.81.0
description: pixi version.
cache-path:
type: string
default: ''
description: Extra path to cache, e.g. data downloads.
cache-key:
type: string
default: ''
description: Key for cache-path.
coverage:
type: boolean
default: false
description: Upload coverage to Codecov from the ubuntu x last-version leg.
cov-source:
type: string
default: ""
description: Import name passed to `--cov` in library mode. Empty means the distribution name with `-` replaced by `_`.
artifact-suffix:
type: string
default: ''
description: Suffix of the Packages artifact name. Set it if test.yml runs more than once in a workflow run.
coverage-file:
type: string
default: coverage.xml
description: Coverage report path, relative to working-directory.
vars-env:
type: string
default: ''
description: Space-separated repository or organization variable (`vars`) names to export to the job env.
working-directory:
type: string
default: .
description: Directory of the package or pixi project.
secrets:
CDSAPI_KEY:
required: false
EARTHDATAHUB_API_KEY:
required: false
MOSEKLM_LICENSE_FILE:
required: false
GUROBI_LIC:
required: false
permissions: {}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
include: ${{ steps.matrix.outputs.include }}
last: ${{ steps.versions.outputs.last }}
cov-source: ${{ inputs.cov-source || steps.baipp.outputs.package_name }}
steps:
- uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- id: baipp
if: inputs.pixi-task == ''
uses: hynek/build-and-inspect-python-package@67230f7b8410ae0052b39c1efc89d89fff43ff10 # v3.0.2
with:
path: ${{ inputs.working-directory }}
upload-name-suffix: ${{ inputs.artifact-suffix }}
- if: inputs.pixi-task != '' && !startsWith(inputs.pixi-environments, '[')
uses: prefix-dev/setup-pixi@ad1da6449d9e506fd127fd67ab2d054a769f6a94 # v0.11.2
with:
pixi-version: ${{ inputs.pixi-version }}
run-install: false
- id: versions
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
PIXI_TASK: ${{ inputs.pixi-task }}
PYTHON_VERSIONS: ${{ inputs.python-versions }}
CLASSIFIERS: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
PIXI_ENVIRONMENTS: ${{ inputs.pixi-environments }}
MANIFEST_PATH: ${{ inputs.manifest-path }}
run: |
set -euo pipefail
if [ -z "$PIXI_TASK" ]; then
versions="${PYTHON_VERSIONS:-$CLASSIFIERS}"
elif [[ "$PIXI_ENVIRONMENTS" == \[* ]]; then
versions="$PIXI_ENVIRONMENTS"
else
manifest_args=()
[ -z "$MANIFEST_PATH" ] || manifest_args=(--manifest-path "$MANIFEST_PATH")
versions=$(pixi info --json ${manifest_args[@]+"${manifest_args[@]}"} | jq -c --arg re "$PIXI_ENVIRONMENTS" '[.environments_info[].name | select(test($re))]')
fi
jq -e 'type == "array" and length > 0' <<<"${versions:-null}" >/dev/null || { echo "::error::no Python versions or pixi environments found: '${versions:-}'" >&2; exit 1; }
echo "versions=$versions" >>"$GITHUB_OUTPUT"
echo "last=$(jq -r '.[-1]' <<<"$versions")" >>"$GITHUB_OUTPUT"
- id: matrix
uses: $/.github/actions/matrix
with:
versions: ${{ steps.versions.outputs.versions }}
mode: ${{ inputs.matrix }}
os-full: ${{ inputs.os-full }}
test:
needs: build
name: test (${{ matrix.os }}, ${{ matrix.version }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.build.outputs.include) }}
env:
COVERAGE_LEG: ${{ inputs.coverage && matrix.os == 'ubuntu-latest' && matrix.version == needs.build.outputs.last }}
steps:
- uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: ${{ inputs.pixi-task == '' && 1 || 0 }}
persist-credentials: false
- if: inputs.pixi-task == ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: Packages${{ inputs.artifact-suffix }}
path: ${{ runner.temp }}/packages
- if: inputs.cache-path != ''
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key || format('test-cache-{0}', runner.os) }}
- id: env
uses: $/.github/actions/setup-env
with:
mode: ${{ inputs.pixi-task == '' && 'library' || 'project' }}
python-version: ${{ inputs.pixi-task == '' && matrix.version || '' }}
pixi-environment: ${{ inputs.pixi-task != '' && matrix.version || 'default' }}
pixi-add: ${{ inputs.pixi-add }}
extras: ${{ inputs.extras }}
uv-locked: ${{ inputs.uv-locked }}
cooldown: ${{ inputs.cooldown }}
wheel-dir: ${{ runner.temp }}/packages
manifest-path: ${{ inputs.manifest-path }}
pixi-version: ${{ inputs.pixi-version }}
vars-json: ${{ toJSON(vars) }}
vars-env: ${{ inputs.vars-env }}
working-directory: ${{ inputs.working-directory }}
- name: Test
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
PIXI_TASK: ${{ inputs.pixi-task }}
PYTEST_ARGS: ${{ inputs.pytest-args }}
TEST_COMMAND: ${{ inputs.test-command }}
COV_REPORT_FILE: ${{ inputs.coverage-file }}
COV_SOURCE: ${{ needs.build.outputs.cov-source }}
CDSAPI_KEY: ${{ secrets.CDSAPI_KEY }}
EARTHDATAHUB_API_KEY: ${{ secrets.EARTHDATAHUB_API_KEY }}
MOSEKLM_LICENSE_FILE: ${{ secrets.MOSEKLM_LICENSE_FILE }}
GUROBI_LIC: ${{ secrets.GUROBI_LIC }}
run: |
set -euo pipefail
if [ -n "$TEST_COMMAND" ]; then
cmd="$TEST_COMMAND"
elif [ -n "$PIXI_TASK" ]; then
cmd="$PIXI_TASK $PYTEST_ARGS"
else
cmd="pytest $PYTEST_ARGS"
[ "$COVERAGE_LEG" != true ] || cmd="$cmd --cov=${COV_SOURCE//-/_} --cov-report=xml:$COV_REPORT_FILE"
fi
echo "$RUN $cmd"
eval "$RUN $cmd"
- if: env.COVERAGE_LEG == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage${{ inputs.artifact-suffix }}
path: ${{ inputs.working-directory }}/${{ inputs.coverage-file }}
if-no-files-found: error
coverage:
needs: test
if: inputs.coverage
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: coverage${{ inputs.artifact-suffix }}
path: ${{ runner.temp }}/coverage
- id: report
env:
COV_REPORT_FILE: ${{ inputs.coverage-file }}
run: echo "path=$RUNNER_TEMP/coverage/$(basename "$COV_REPORT_FILE")" >> "$GITHUB_OUTPUT"
- uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
files: ${{ steps.report.outputs.path }}
use_oidc: true