WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c2d9e83

Browse files
committed
📦 Build release artifacts in CI
This is a narrowly scoped initial integration of `reusable-tox.yml` into the project's CI/CD infra. It makes use of the following external action and reusable workflow repositories, some are optional: * `codecov/codecov-action` (transitively, via `tox-dev/workflow`) * `irongut/CodeCoverageSummary` (transitively, via `tox-dev/workflow`) * `re-actors/cache-python-deps` « (directly; and also transitively, via `tox-dev/workflow`) * `re-actors/checkout-python-sdist` « (transitively, via `tox-dev/workflow`) * `test-summary/action` (transitively, via `tox-dev/workflow`) * `tox-dev/workflow` « (directly) The marked projects are under my control. This patch plugs the main CI workflow as reusable into the release one. The CI workflow gets two new jobs — pre-setup that computes a number of variables, and build that makes the artifacts and stores them for later consumption by the PyPI upload job. The build job also double-checks that the artifacts are created with expected names. The invocation of `pypa/build` moved to tox so that it's possible to run the same process locally. In follow-up PRs, these dists will also be used in testing.
1 parent c5b5426 commit c2d9e83

File tree

5 files changed

+477
-64
lines changed

5 files changed

+477
-64
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
3+
name: placeholder
4+
description: placeholder
5+
6+
outputs:
7+
cache-key-for-dep-files:
8+
description: >-
9+
A cache key string derived from the dependency declaration files.
10+
value: ${{ steps.calc-cache-key-files.outputs.files-hash-key }}
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: >-
16+
Calculate dependency files' combined hash value
17+
for use in the cache key
18+
id: calc-cache-key-files
19+
run: |
20+
from os import environ
21+
from pathlib import Path
22+
23+
FILE_APPEND_MODE = 'a'
24+
25+
files_derived_hash = '${{
26+
hashFiles(
27+
'tox.ini',
28+
'pyproject.toml',
29+
'.pre-commit-config.yaml',
30+
'pytest.ini',
31+
'dependencies/**',
32+
'dependencies/*/**',
33+
'setup.cfg'
34+
)
35+
}}'
36+
37+
print(f'Computed file-derived hash is {files_derived_hash}.')
38+
39+
with Path(environ['GITHUB_OUTPUT']).open(
40+
mode=FILE_APPEND_MODE,
41+
) as outputs_file:
42+
print(
43+
f'files-hash-key={files_derived_hash}',
44+
file=outputs_file,
45+
)
46+
shell: python
47+
48+
...
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
3+
inputs:
4+
calling-job-context:
5+
description: A JSON with the calling job inputs
6+
type: string
7+
current-job-steps:
8+
description: >-
9+
The `$ {{ steps }}` context passed from the reusable workflow's
10+
tox job encoded as a JSON string. The caller passes it this input
11+
as follows:
12+
`current-job-steps: $ {{ toJSON(steps) }}`.
13+
type: string
14+
job-dependencies-context:
15+
default: >-
16+
{}
17+
description: >-
18+
The `$ {{ needs }}` context passed from the calling workflow
19+
encoded as a JSON string. The caller is expected to form this
20+
input as follows:
21+
`job-dependencies-context: $ {{ toJSON(needs) }}`.
22+
required: false
23+
type: string
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: Verify that the artifacts with expected names got created
29+
if: fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
30+
run: >
31+
# Verify that the artifacts with expected names got created
32+
33+
34+
ls -1
35+
'dist/${{
36+
fromJSON(
37+
inputs.job-dependencies-context
38+
).pre-setup.outputs.sdist-artifact-name
39+
}}'
40+
'dist/${{
41+
fromJSON(
42+
inputs.job-dependencies-context
43+
).pre-setup.outputs.wheel-artifact-name
44+
}}'
45+
shell: bash
46+
- name: Store the distribution packages
47+
if: fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: >-
51+
${{
52+
fromJSON(
53+
inputs.job-dependencies-context
54+
).pre-setup.outputs.dists-artifact-name
55+
}}
56+
# NOTE: Exact expected file names are specified here
57+
# NOTE: as a safety measure — if anything weird ends
58+
# NOTE: up being in this dir or not all dists will be
59+
# NOTE: produced, this will fail the workflow.
60+
path: |
61+
dist/${{
62+
fromJSON(
63+
inputs.job-dependencies-context
64+
).pre-setup.outputs.sdist-artifact-name
65+
}}
66+
dist/${{
67+
fromJSON(
68+
inputs.job-dependencies-context
69+
).pre-setup.outputs.wheel-artifact-name
70+
}}
71+
retention-days: >-
72+
${{
73+
fromJSON(
74+
fromJSON(
75+
inputs.job-dependencies-context
76+
).pre-setup.outputs.release-requested
77+
)
78+
&& 90
79+
|| 30
80+
}}
81+
82+
...

0 commit comments

Comments
 (0)