Skip to content

Commit 94f5fcf

Browse files
committed
Merge branch 'maintenance/ci-shape-reuse-sync'
PR #87
2 parents c810a23 + 270d2f7 commit 94f5fcf

File tree

7 files changed

+572
-689
lines changed

7 files changed

+572
-689
lines changed

.github/actions/cache-keys/action.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
3+
outputs:
4+
cache-key-for-dep-files:
5+
description: >-
6+
A cache key string derived from the dependency declaration files.
7+
value: ${{ steps.calc-cache-key-files.outputs.files-hash-key }}
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: >-
13+
Calculate dependency files' combined hash value
14+
for use in the cache key
15+
id: calc-cache-key-files
16+
run: |
17+
from os import environ
18+
from pathlib import Path
19+
20+
FILE_APPEND_MODE = 'a'
21+
22+
files_derived_hash = '${{
23+
hashFiles(
24+
'tox.ini',
25+
'pyproject.toml',
26+
'.pre-commit-config.yaml',
27+
'pytest.ini',
28+
'dependencies/**/*'
29+
)
30+
}}'
31+
32+
print(f'Computed file-derived hash is {files_derived_hash}.')
33+
34+
with Path(environ['GITHUB_OUTPUT']).open(
35+
mode=FILE_APPEND_MODE,
36+
) as outputs_file:
37+
print(
38+
f'files-hash-key={files_derived_hash}',
39+
file=outputs_file,
40+
)
41+
shell: python
42+
43+
...
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
3+
inputs:
4+
calling-job-context:
5+
description: A JSON with the calling job inputs
6+
type: string
7+
job-dependencies-context:
8+
default: >-
9+
{}
10+
description: >-
11+
The `$ {{ needs }}` context passed from the calling workflow
12+
encoded as a JSON string. The caller is expected to form this
13+
input as follows:
14+
`job-dependencies-context: $ {{ toJSON(needs) }}`.
15+
required: false
16+
type: string
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Log setting up pre-commit cache
22+
if: fromJSON(inputs.calling-job-context).toxenv == 'pre-commit'
23+
run: >-
24+
>&2 echo Caching ~/.cache/pre-commit based on
25+
the contents of '.pre-commit-config.yaml'...
26+
shell: bash
27+
- name: Cache pre-commit.com virtualenvs
28+
if: fromJSON(inputs.calling-job-context).toxenv == 'pre-commit'
29+
uses: actions/cache@v4
30+
with:
31+
path: ~/.cache/pre-commit
32+
key: >-
33+
${{
34+
runner.os
35+
}}-pre-commit-${{
36+
hashFiles('.pre-commit-config.yaml')
37+
}}
38+
39+
...
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
3+
inputs:
4+
calling-job-context:
5+
description: A JSON with the calling job inputs
6+
type: string
7+
job-dependencies-context:
8+
default: >-
9+
{}
10+
description: >-
11+
The `$ {{ needs }}` context passed from the calling workflow
12+
encoded as a JSON string. The caller is expected to form this
13+
input as follows:
14+
`job-dependencies-context: $ {{ toJSON(needs) }}`.
15+
required: false
16+
type: string
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Verify that the artifacts with expected names got created
22+
if: fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
23+
run: >
24+
# Verify that the artifacts with expected names got created
25+
26+
27+
ls -1
28+
'dist/${{
29+
fromJSON(
30+
inputs.job-dependencies-context
31+
).pre-setup.outputs.sdist-artifact-name
32+
}}'
33+
'dist/${{
34+
fromJSON(
35+
inputs.job-dependencies-context
36+
).pre-setup.outputs.wheel-artifact-name
37+
}}'
38+
shell: bash
39+
- name: Store the distribution packages
40+
if: fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: >-
44+
${{
45+
fromJSON(
46+
inputs.job-dependencies-context
47+
).pre-setup.outputs.dists-artifact-name
48+
}}
49+
# NOTE: Exact expected file names are specified here
50+
# NOTE: as a safety measure — if anything weird ends
51+
# NOTE: up being in this dir or not all dists will be
52+
# NOTE: produced, this will fail the workflow.
53+
path: |
54+
dist/${{
55+
fromJSON(
56+
inputs.job-dependencies-context
57+
).pre-setup.outputs.sdist-artifact-name
58+
}}
59+
dist/${{
60+
fromJSON(
61+
inputs.job-dependencies-context
62+
).pre-setup.outputs.wheel-artifact-name
63+
}}
64+
retention-days: >-
65+
${{
66+
fromJSON(
67+
fromJSON(
68+
inputs.job-dependencies-context
69+
).pre-setup.outputs.release-requested
70+
)
71+
&& 90
72+
|| 30
73+
}}
74+
75+
...
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
3+
inputs:
4+
calling-job-context:
5+
description: A JSON with the calling job inputs
6+
type: string
7+
job-dependencies-context:
8+
default: >-
9+
{}
10+
description: >-
11+
The `$ {{ needs }}` context passed from the calling workflow
12+
encoded as a JSON string. The caller is expected to form this
13+
input as follows:
14+
`job-dependencies-context: $ {{ toJSON(needs) }}`.
15+
required: false
16+
type: string
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Drop Git tags from HEAD for non-tag-create events
22+
if: >-
23+
fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
24+
&& !fromJSON(
25+
fromJSON(
26+
inputs.job-dependencies-context
27+
).pre-setup.outputs.release-requested
28+
)
29+
run: >-
30+
git tag --points-at HEAD
31+
|
32+
xargs git tag --delete
33+
shell: bash
34+
35+
- name: Setup git user as [bot]
36+
if: >-
37+
fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
38+
&& (
39+
fromJSON(
40+
fromJSON(
41+
inputs.job-dependencies-context
42+
).pre-setup.outputs.release-requested
43+
)
44+
|| fromJSON(
45+
fromJSON(
46+
inputs.job-dependencies-context
47+
).pre-setup.outputs.is-untagged-devel
48+
)
49+
)
50+
uses: fregante/setup-git-user@v2
51+
- name: >-
52+
Tag the release in the local Git repo
53+
as ${{
54+
fromJSON(
55+
inputs.job-dependencies-context
56+
).pre-setup.outputs.git-tag
57+
}}
58+
for setuptools-scm to set the desired version
59+
if: >-
60+
fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
61+
&& fromJSON(
62+
fromJSON(
63+
inputs.job-dependencies-context
64+
).pre-setup.outputs.release-requested
65+
)
66+
run: >-
67+
git tag
68+
-m '${{
69+
fromJSON(
70+
inputs.job-dependencies-context
71+
).pre-setup.outputs.git-tag
72+
}}'
73+
'${{
74+
fromJSON(
75+
inputs.job-dependencies-context
76+
).pre-setup.outputs.git-tag
77+
}}'
78+
--
79+
${{ fromJSON(inputs.calling-job-context).checkout-src-git-committish }}
80+
shell: bash
81+
82+
- name: Install tomlkit Python distribution package
83+
if: >-
84+
fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
85+
&& fromJSON(
86+
fromJSON(
87+
inputs.job-dependencies-context
88+
).pre-setup.outputs.is-untagged-devel
89+
)
90+
run: >-
91+
python -m pip install --user tomlkit
92+
shell: bash
93+
- name: Instruct setuptools-scm not to add a local version part
94+
if: >-
95+
fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
96+
&& fromJSON(
97+
fromJSON(
98+
inputs.job-dependencies-context
99+
).pre-setup.outputs.is-untagged-devel
100+
)
101+
run: |
102+
from pathlib import Path
103+
104+
import tomlkit
105+
106+
pyproject_toml_path = Path.cwd() / 'pyproject.toml'
107+
pyproject_toml_txt = pyproject_toml_path.read_text()
108+
pyproject_toml = tomlkit.loads(pyproject_toml_txt)
109+
setuptools_scm_section = pyproject_toml['tool']['setuptools_scm']
110+
setuptools_scm_section['local_scheme'] = 'no-local-version'
111+
patched_pyproject_toml_txt = tomlkit.dumps(pyproject_toml)
112+
pyproject_toml_path.write_text(patched_pyproject_toml_txt)
113+
shell: python
114+
- name: Pretend that pyproject.toml is unchanged
115+
if: >-
116+
fromJSON(inputs.calling-job-context).toxenv == 'build-dists'
117+
&& fromJSON(
118+
fromJSON(
119+
inputs.job-dependencies-context
120+
).pre-setup.outputs.is-untagged-devel
121+
)
122+
run: |
123+
git diff --color=always
124+
git update-index --assume-unchanged pyproject.toml
125+
shell: bash
126+
127+
...

0 commit comments

Comments
 (0)