-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (223 loc) ยท 8.62 KB
/
test.yaml
File metadata and controls
259 lines (223 loc) ยท 8.62 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
# This is the main workflow for testing the code before and after
# packaging it.
# The workflow is divided into three jobs:
# 1. env-prepare:
# - Prepare the environment for testing
# 2. source-test:
# - Test the code base against the latest code in the repository
# - Create the Python package
# - Upload the Python package for the next job
# 3. package-test:
# - Download the Python package (including extra files) from the previous job
# - Install the downloaded Python package
# - Test the code base against the installed package
# 4. dashboard-build-trigger:
# - Trigger the dashboard build workflow to update the code quality
# metrics on the dashboard
name: Code and package tests
on:
# Trigger the workflow on push
push:
# Every branch
branches: ['**']
# But do not run this workflow on creating a new tag starting with
# 'v', e.g. 'v1.0.3' (see publish-pypi.yml)
tags-ignore: ['v*']
# Trigger the workflow on pull request
pull_request:
branches: ['**']
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Need permissions to trigger the dashboard build workflow
permissions:
actions: write
contents: read
# Allow only one concurrent workflow, skipping runs queued between the run
# in-progress and latest queued. And cancel in-progress runs.
concurrency:
group:
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# Set the environment variables to be used in all jobs defined in this workflow
env:
CI_BRANCH: ${{ github.head_ref || github.ref_name }}
jobs:
# Job 1: Prepare environment
env-prepare:
runs-on: [ubuntu-latest]
outputs:
pytest-marks: ${{ steps.set-mark.outputs.pytest_marks }}
steps:
# Determine if integration tests should be run fully or only the fast ones
# (to save time on branches other than master and develop)
- name: Set mark for integration tests
id: set-mark
run: |
if [[ "${{ env.CI_BRANCH }}" == "master" || "${{ env.CI_BRANCH }}" == "develop" ]]; then
echo "pytest_marks=" >> $GITHUB_OUTPUT
else
echo "pytest_marks=-m fast" >> $GITHUB_OUTPUT
fi
# Job 2: Test code
source-test:
needs: env-prepare # depend on previous job
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-14, windows-2022]
runs-on: ${{ matrix.os }}
env:
PIXI_ENVS: 'py311-dev py313-dev'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: '0' # full history with tags to get the version number by versioningit
- name: Set up pixi
uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: ${{ env.PIXI_ENVS }}
run-install: true
frozen: true
cache: false
post-cleanup: false
- name: Install and setup development dependencies
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run --environment $env dev
echo "PYTHONPATH:"
pixi run printenv PYTHONPATH || true
pixi run --environment $env easydiffraction --version
done
- name: Run unit tests
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run --environment $env unit-tests
done
- name:
Run integration tests ${{ needs.env-prepare.outputs.pytest-marks }}
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run --environment $env integration-tests ${{ needs.env-prepare.outputs.pytest-marks }}
done
# Delete all local tags when not on a tagged commit to force versioningit
# to fall back to the configured default-tag, which is '999.0.0' in our case.
# This is needed for testing the package in the next job, as its version
# must be higher than the PyPI version for pip to prefer the local version.
- name: Force using versioningit default tag (non tagged release)
if: startsWith(github.ref , 'refs/tags/v') != true
run: git tag --delete $(git tag)
- name: Create Python package
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run -e $env dist-build
env_prefix="${env%%-*}"
echo "๐ฆ Moving built wheel to dist/$env_prefix/"
pixi run mkdir -p dist/$env_prefix
pixi run mv dist/*.whl dist/$env_prefix/
done
- name: Remove local easydiffraction from pixi.toml
shell: bash
run: pixi remove --pypi easydiffraction
- name: Remove Python cache files before uploading
shell: bash
run: pixi run clean-pycache
# More than one file/dir need to be specified in 'path', to preserve the
# structure of the dist/ directory, not only its contents.
- name: Upload Python package for the next job
uses: actions/upload-artifact@v4
with:
name: edl_${{ matrix.os }}_${{ runner.arch }}
path: |
dist/
tests/
pytest.ini
pixi.toml
pixi.lock
if-no-files-found: 'error'
compression-level: 0
# Job 3: Test the package
package-test:
needs: [env-prepare, source-test] # depend on previous jobs
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-14, windows-2022]
runs-on: ${{ matrix.os }}
env:
PIXI_ENVS: 'py311-dev py313-dev'
steps:
- name:
Download zipped Python package (incl. extra files) from previous job
uses: actions/download-artifact@v4
with: # name or path are taken from the upload step of the previous job
name: edl_${{ matrix.os }}_${{ runner.arch }}
path: . # directory to extract downloaded zipped artifacts
- name: Set up pixi
uses: prefix-dev/setup-pixi@v0.9.3
with:
environments: ${{ env.PIXI_ENVS }}
run-install: true
frozen: true
cache: false
post-cleanup: false
- name: Install and setup development dependencies
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run --environment $env wheel
done
- name: Install easydiffraction package from the built wheel
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
env_prefix="${env%%-*}"
echo "๐ฆ Looking for wheel in dist/$env_prefix/"
whl_path="$(find dist/${env_prefix} -name '*.whl' | head -1)"
echo "๐ฆ Installing easydiffraction from: $whl_path"
pixi run --environment $env python -m uv pip install "${whl_path}[all]" --reinstall-package easydiffraction
pixi run --environment $env easydiffraction --version
done
- name: Run unit tests
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run --environment $env unit-tests
done
- name:
Run integration tests ${{ needs.env-prepare.outputs.pytest-marks }}
shell: bash
run: |
for env in ${{ env.PIXI_ENVS }}; do
echo "๐น๐ธ๐น๐ธ๐น Current env: $env ๐น๐ธ๐น๐ธ๐น"
pixi run --environment $env integration-tests ${{ needs.env-prepare.outputs.pytest-marks }}
done
# Job 4: Trigger dashboard build
dashboard-build-trigger:
needs: [source-test, package-test] # depend on previous jobs
runs-on: ubuntu-latest
steps:
- name: Check-out repository
uses: actions/checkout@v5
- name: Trigger dashboard build
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "dashboard.yaml",
ref: "${{ env.CI_BRANCH }}"
});