22
33on :
44 merge_group :
5- pull_request :
65 push :
76 # We need to explicitly include tags because otherwise when adding
87 # `branches-ignore` it will only trigger on branches.
@@ -29,59 +28,27 @@ jobs:
2928 strategy :
3029 fail-fast : false
3130 matrix :
31+ arch :
32+ - amd64
33+ - arm
3234 os :
3335 - ubuntu-24.04
3436 python :
3537 - " 3.11"
38+ - " 3.12"
3639 nox-session :
3740 # To speed things up a bit we use the special ci_checks_max session
3841 # that uses the same venv to run multiple linting sessions
3942 - " ci_checks_max"
4043 - " pytest_min"
41- runs-on : ${{ matrix.os }}
44+ runs-on : ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
4245
4346 steps :
44- - name : Setup Git
45- uses :
frequenz-floss/[email protected] 46-
47- - name : Print environment (debug)
48- run : env
49-
50- - name : Fetch sources
51- uses : actions/checkout@v4
52- with :
53- submodules : true
54-
55- - name : Set up Python
56- uses : actions/setup-python@v5
47+ - name : Run nox
48+ uses :
frequenz-floss/[email protected] 5749 with :
5850 python-version : ${{ matrix.python }}
59- cache : ' pip'
60-
61- - name : Install required Python packages
62- run : |
63- python -m pip install --upgrade pip
64- python -m pip install -e .[dev-noxfile]
65- pip freeze
66-
67- - name : Create nox venv
68- env :
69- NOX_SESSION : ${{ matrix.nox-session }}
70- run : nox --install-only -e "$NOX_SESSION"
71-
72- - name : Print pip freeze for nox venv (debug)
73- env :
74- NOX_SESSION : ${{ matrix.nox-session }}
75- run : |
76- . ".nox/$NOX_SESSION/bin/activate"
77- pip freeze
78- deactivate
79-
80- - name : Run nox
81- env :
82- NOX_SESSION : ${{ matrix.nox-session }}
83- run : nox -R -e "$NOX_SESSION"
84- timeout-minutes : 10
51+ nox-session : ${{ matrix.nox-session }}
8552
8653 # This job runs if all the `nox` matrix jobs ran and succeeded.
8754 # It is only used to have a single job that we can require in branch
@@ -100,150 +67,27 @@ jobs:
10067 - name : Check matrix job result
10168 run : test "$DEPS_RESULT" = "success"
10269
103- nox-cross-arch :
104- name : Cross-arch tests with nox
105- if : github.event_name != 'pull_request'
106- strategy :
107- fail-fast : false
108- # Before adding new items to this matrix, make sure that a dockerfile
109- # exists for the combination of items in the matrix.
110- # Refer to .github/containers/nox-cross-arch/README.md to learn how to
111- # add and name new dockerfiles.
112- matrix :
113- arch :
114- - arm64
115- os :
116- - ubuntu-24.04
117- python :
118- - " 3.11"
119- nox-session :
120- - " pytest_min"
121- - " pytest_max"
122- runs-on : ${{ matrix.os }}
123-
124- steps :
125- - name : Setup Git
126- uses :
frequenz-floss/[email protected] 127-
128- - name : Fetch sources
129- uses : actions/checkout@v4
130- with :
131- submodules : true
132-
133- - name : Set up QEMU
134- uses : docker/setup-qemu-action@v3
135- with :
136- platforms : linux/${{ matrix.arch }}
137-
138- - name : Set up Docker Buildx
139- uses : docker/setup-buildx-action@v3
140-
141- # This is a workaround to prevent the cache from growing indefinitely.
142- # https://docs.docker.com/build/ci/github-actions/cache/#local-cache
143- # https://github.com/docker/build-push-action/issues/252
144- # https://github.com/moby/buildkit/issues/1896
145- - name : Cache container layers
146- uses : actions/cache@v4
147- with :
148- path : /tmp/.buildx-cache
149- key : ${{ runner.os }}-buildx-nox-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python }}
150-
151- - name : Build image
152- uses : docker/build-push-action@v6
153- with :
154- context : .github/containers/nox-cross-arch
155- file : .github/containers/nox-cross-arch/${{ matrix.arch }}-${{ matrix.os }}-python-${{ matrix.python }}.Dockerfile
156- platforms : linux/${{ matrix.arch }}
157- tags : localhost/nox-cross-arch:latest
158- push : false
159- load : true
160- cache-from : type=local,src=/tmp/.buildx-cache
161- cache-to : type=local,dest=/tmp/.buildx-cache-new,mode=max
162-
163- # Refer to the workaround mentioned above
164- - name : Move cache
165- run : |
166- rm -rf /tmp/.buildx-cache
167- mv /tmp/.buildx-cache-new /tmp/.buildx-cache
168-
169- # Cache pip downloads
170- - name : Cache pip downloads
171- uses : actions/cache@v4
172- with :
173- path : /tmp/pip-cache
174- key : nox-${{ matrix.nox-session }}-${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }}
175-
176- # This ensures that the docker container has access to the pip cache.
177- # Changing the user in the docker-run step causes it to fail due to
178- # incorrect permissions. Setting the ownership of the pip cache to root
179- # before running is a workaround to this issue.
180- - name : Set pip cache owners to root for docker
181- run : if [[ -e /tmp/pip-cache ]]; then sudo chown -R root:root /tmp/pip-cache; fi
182-
183- - name : Run nox
184- run : |
185- docker run \
186- --rm \
187- -v $(pwd):/${{ github.workspace }} \
188- -v /tmp/pip-cache:/root/.cache/pip \
189- -w ${{ github.workspace }} \
190- --net=host \
191- --platform linux/${{ matrix.arch }} \
192- localhost/nox-cross-arch:latest \
193- bash -c "pip install -e .[dev-noxfile]; nox --install-only -e ${{ matrix.nox-session }}; pip freeze; nox -e ${{ matrix.nox-session }}"
194- timeout-minutes : 30
195-
196- # This ensures that the runner has access to the pip cache.
197- - name : Reset pip cache ownership
198- if : always()
199- run : sudo chown -R $USER:$USER /tmp/pip-cache
200-
201- # This job runs if all the `nox-cross-arch` matrix jobs ran and succeeded.
202- # As the `nox-all` job, its main purpose is to provide a single point of
203- # reference in branch protection rules, similar to how `nox-all` operates.
204- # However, there's a crucial difference: the `nox-cross-arch` job is omitted
205- # in PRs. Without the `nox-cross-arch-all` job, the inner matrix wouldn't be
206- # expanded in such scenarios. This would lead to the CI indefinitely waiting
207- # for these jobs to complete due to the branch protection rules, essentially
208- # causing it to hang. This behavior is tied to a recognized GitHub matrices
209- # issue when certain jobs are skipped. For a deeper understanding, refer to:
210- # https://github.com/orgs/community/discussions/9141
211- nox-cross-arch-all :
212- # The job name should match the name of the `nox-cross-arch` job.
213- name : Cross-arch tests with nox
214- needs : ["nox-cross-arch"]
215- # We skip this job only if nox-cross-arch was also skipped
216- if : always() && needs.nox-cross-arch.result != 'skipped'
217- runs-on : ubuntu-24.04
218- env :
219- DEPS_RESULT : ${{ needs.nox-cross-arch.result }}
220- steps :
221- - name : Check matrix job result
222- run : test "$DEPS_RESULT" = "success"
223-
22470 build :
22571 name : Build distribution packages
72+ # Since this is a pure Python package, we only need to build it once. If it
73+ # had any architecture specific code, we would need to build it for each
74+ # architecture.
22675 runs-on : ubuntu-24.04
76+
22777 steps :
22878 - name : Setup Git
229- uses : frequenz-floss/gh-action-setup-git@v0.x.x
79+ uses : frequenz-floss/gh-action-setup-git@v1.0.0
23080
23181 - name : Fetch sources
23282 uses : actions/checkout@v4
23383 with :
23484 submodules : true
23585
236- - name : Set up Python
237- uses : actions/ setup-python@v5
86+ - name : Setup Python
87+ uses :
frequenz-floss/gh-action- setup-python[email protected] 23888 with :
23989 python-version : ${{ env.DEFAULT_PYTHON_VERSION }}
240- cache : ' pip'
241-
242- - name : Install required Python packages
243- run : |
244- python -m pip install -U pip
245- python -m pip install -U build
246- pip freeze
90+ dependencies : build
24791
24892 - name : Build the source and binary distribution
24993 run : python -m build
@@ -256,66 +100,92 @@ jobs:
256100 if-no-files-found : error
257101
258102 test-installation :
259- name : Test package installation in different architectures
103+ name : Test package installation
260104 needs : ["build"]
261- runs-on : ubuntu-24.04
105+ strategy :
106+ fail-fast : false
107+ matrix :
108+ arch :
109+ - amd64
110+ - arm
111+ os :
112+ - ubuntu-24.04
113+ python :
114+ - " 3.11"
115+ - " 3.12"
116+ runs-on : ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
117+
262118 steps :
263119 - name : Setup Git
264- uses : frequenz-floss/gh-action-setup-git@v0.x.x
120+ uses : frequenz-floss/gh-action-setup-git@v1.0.0
265121
266- - name : Fetch sources
267- uses : actions/checkout@v4
122+ - name : Print environment (debug)
123+ run : env
268124
269125 - name : Download package
270126 uses : actions/download-artifact@v4
271127 with :
272128 name : dist-packages
273129 path : dist
274130
275- - name : Make Git credentials available to docker
131+ # This is necessary for the `pip` caching in the setup-python action to work
132+ - name : Fetch the pyproject.toml file for this action hash
133+ env :
134+ GH_TOKEN : ${{ github.token }}
135+ REPO : ${{ github.repository }}
136+ REF : ${{ github.sha }}
276137 run : |
277- touch ~/.git-credentials # Ensure the file exists
278- cp ~/.git-credentials git-credentials || true
138+ set -ux
139+ gh api \
140+ -X GET \
141+ -H "Accept: application/vnd.github.raw" \
142+ "/repos/$REPO/contents/pyproject.toml?ref=$REF" \
143+ > pyproject.toml
279144
280- - name : Set up QEMU
281- uses : docker/setup-qemu-action@v3
145+ - name : Setup Python
146+ uses :
frequenz-floss/[email protected] 147+ with :
148+ python-version : ${{ matrix.python }}
149+ dependencies : dist/*.whl
282150
283- - name : Set up docker-buildx
284- uses : docker/setup-buildx-action@v3
151+ - name : Print installed packages (debug)
152+ run : python -m pip freeze
285153
286- - name : Test Installation
287- uses : docker/build-push-action@v6
288- with :
289- context : .
290- file : .github/containers/test-installation/Dockerfile
291- platforms : linux/amd64,linux/arm64
292- tags : localhost/test-installation
293- push : false
154+ # This job runs if all the `test-installation` matrix jobs ran and succeeded.
155+ # It is only used to have a single job that we can require in branch
156+ # protection rules, so we don't have to update the protection rules each time
157+ # we add or remove a job from the matrix.
158+ test-installation-all :
159+ # The job name should match the name of the `test-installation` job.
160+ name : Test package installation
161+ needs : ["test-installation"]
162+ # We skip this job only if test-installation was also skipped
163+ if : always() && needs.test-installation.result != 'skipped'
164+ runs-on : ubuntu-24.04
165+ env :
166+ DEPS_RESULT : ${{ needs.test-installation.result }}
167+ steps :
168+ - name : Check matrix job result
169+ run : test "$DEPS_RESULT" = "success"
294170
295171 test-docs :
296172 name : Test documentation website generation
297173 if : github.event_name != 'push'
298174 runs-on : ubuntu-24.04
299175 steps :
300176 - name : Setup Git
301- uses : frequenz-floss/gh-action-setup-git@v0.x.x
177+ uses : frequenz-floss/gh-action-setup-git@v1.0.0
302178
303179 - name : Fetch sources
304180 uses : actions/checkout@v4
305181 with :
306182 submodules : true
307183
308- - name : Set up Python
309- uses : actions/ setup-python@v5
184+ - name : Setup Python
185+ uses :
frequenz-floss/gh-action- setup-python[email protected] 310186 with :
311187 python-version : ${{ env.DEFAULT_PYTHON_VERSION }}
312- cache : ' pip'
313-
314- - name : Install build dependencies
315- run : |
316- python -m pip install -U pip
317- python -m pip install .[dev-mkdocs]
318- pip freeze
188+ dependencies : .[dev-mkdocs]
319189
320190 - name : Generate the documentation
321191 env :
@@ -333,31 +203,25 @@ jobs:
333203
334204 publish-docs :
335205 name : Publish documentation website to GitHub pages
336- needs : ["nox-all", "nox-cross-arch-all", " test-installation"]
206+ needs : ["nox-all", "test-installation-all "]
337207 if : github.event_name == 'push'
338208 runs-on : ubuntu-24.04
339209 permissions :
340210 contents : write
341211 steps :
342212 - name : Setup Git
343- uses : frequenz-floss/gh-action-setup-git@v0.x.x
213+ uses : frequenz-floss/gh-action-setup-git@v1.0.0
344214
345215 - name : Fetch sources
346216 uses : actions/checkout@v4
347217 with :
348218 submodules : true
349219
350- - name : Set up Python
351- uses : actions/ setup-python@v5
220+ - name : Setup Python
221+ uses :
frequenz-floss/gh-action- setup-python[email protected] 352222 with :
353223 python-version : ${{ env.DEFAULT_PYTHON_VERSION }}
354- cache : ' pip'
355-
356- - name : Install build dependencies
357- run : |
358- python -m pip install -U pip
359- python -m pip install .[dev-mkdocs]
360- pip freeze
224+ dependencies : .[dev-mkdocs]
361225
362226 - name : Calculate and check version
363227 id : mike-version
0 commit comments