-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
action.yml
259 lines (219 loc) · 8.41 KB
/
action.yml
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
---
name: Build and Inspect a Python Package
description: Builds the current package using standard PyPA tooling, keeps it as artifacts, then performs checks on it.
author: Hynek Schlawack
branding:
icon: package
color: purple
inputs:
path:
description: Where to look for the Python package to inspect.
required: false
default: .
skip-wheel:
description: Only build the source distribution.
required: false
default: 'false'
upload-name-suffix:
description: Suffix to append to the artifact names.
required: false
default: ""
attest-build-provenance-github:
description: "Attest provenance using GitHub's own action. Requires 'attestations: write' and 'id-token: write' permissions."
required: false
default: 'false'
outputs:
artifact-name:
description: The name of the uploaded artifact.
value: ${{ steps.artifact.outputs.name }}
dist:
description: The location of the built packages.
value: ${{ steps.dist-location-setter.outputs.dist }}
supported_python_classifiers_json_array:
description: >
A JSON array that contains all classifier-declared supported Python
versions. When loaded using the 'fromJson' function, this can be assigned
to a matrix strategy key (for example, `python-version`).
value: ${{ steps.metadata-setter.outputs.supported_python_classifiers_json_array }}
supported_python_classifiers_json_job_matrix_value:
description: >
Same as 'supported_python_classifiers_json_array', except it's already a
JSON mapping from "python-version" to a list of all classifier-declared
supported Python versions. In other words, you can assign it directly to
the 'strategy.matrix' key.
value: ${{ steps.metadata-setter.outputs.supported_python_classifiers_json_job_matrix_value }}
package_version:
description: The version of the package as declared in the metadata.
value: ${{ steps.metadata-setter.outputs.package_version }}
runs:
using: composite
steps:
- uses: actions/setup-python@v5
id: python-baipp
with:
python-version: "3.x"
update-environment: false
- name: Install uv
run: >
curl
--location
--silent
--show-error
--fail
--proto '=https'
--tlsv1.2
https://astral.sh/uv/install.sh | bash
shell: bash
- name: Set uv cache and hash lock file
run: |
echo "UV_CACHE_DIR=/tmp/baipp-uv_cache_dir" >>$GITHUB_ENV
echo "REQS_HASH=$(sha256sum ${{ github.action_path }}/requirements/tools.txt | cut -d' ' -f1)" >>$GITHUB_ENV
shell: bash
- name: Setup uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: baipp-${{ env.REQS_HASH }}
- name: Create venv for tools
run: |
unset UV_SYSTEM_PYTHON
uv venv \
/tmp/baipp \
--python ${{ steps.python-baipp.outputs.python-path }}
shell: bash
- name: Install our tools
run: |
unset UV_SYSTEM_PYTHON
uv pip sync \
${{ github.action_path }}/requirements/tools.txt
shell: bash
env:
VIRTUAL_ENV: /tmp/baipp
- name: Artifact Name
id: artifact
run: echo "name=Packages${{ inputs.upload-name-suffix }}" >>${GITHUB_OUTPUT}
shell: bash
# Build SDist, then build wheel out of it if the user didn't forbid it.
# Set 'SOURCE_DATE_EPOCH' based on the last commit for build
# reproducibility.
- name: Build package
run: |
unset UV_SYSTEM_PYTHON
echo Setting SOURCE_DATE_EPOCH to $(git log -1 --pretty=%ct).
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
if [[ "${{ inputs.skip-wheel }}" == "true" ]]; then
uv build --sdist --out-dir /tmp/baipp/dist
else
uv build --out-dir /tmp/baipp/dist
fi
# We don't need .gitignores and it litters the provenance output.
rm -f /tmp/baipp/dist/.gitignore
shell: bash
working-directory: ${{ inputs.path }}
- name: Optimize uv cache for CI
run: uv cache prune --ci
shell: bash
- name: Attest GitHub build provenance
if: ${{ inputs.attest-build-provenance-github == 'true' }}
uses: actions/attest-build-provenance@v1
with:
subject-path: "/tmp/baipp/dist/*"
- name: Add contents header
shell: bash
run: echo -e '\n### Package Contents' >> $GITHUB_STEP_SUMMARY
- name: Set output
id: dist-location-setter
shell: bash
run: echo "dist=/tmp/baipp/dist" >>$GITHUB_OUTPUT
# Give user overview over what we've built.
- run: ls -l /tmp/baipp/dist
shell: bash
working-directory: ${{ inputs.path }}
- name: Upload built artifacts.
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact.outputs.name }}
path: /tmp/baipp/dist/*
- name: Check wheel contents if one was built
run: |
if [[ "${{ inputs.skip-wheel }}" != 'true' ]]; then
/tmp/baipp/bin/check-wheel-contents /tmp/baipp/dist/*.whl
fi
shell: bash
working-directory: ${{ inputs.path }}
- name: Check PyPI README
shell: bash
working-directory: ${{ inputs.path }}
run: >
/tmp/baipp/bin/python
-m twine check
--strict
/tmp/baipp/dist/*
- name: Show package contents hierarchically, including metadata.
shell: bash
working-directory: ${{ inputs.path }}
run: |
cd /tmp/baipp/dist
mkdir -p out/sdist
tar xf *.tar.gz -C out/sdist
if ! command -v tree &> /dev/null; then
sudo apt-get install tree
fi
echo -e '\n<details><summary>SDist contents</summary>\n' >> $GITHUB_STEP_SUMMARY
(cd /tmp/baipp/dist/out/sdist && tree -Da --timefmt="%Y-%m-%dT%H:%M:%SZ" * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
if [[ "${{ inputs.skip-wheel }}" != 'true' ]]; then
mkdir -p out/wheels
/tmp/baipp/bin/python -m wheel unpack --dest out/wheels *.whl
echo -e '\n<details><summary>Wheel contents</summary>\n' >> $GITHUB_STEP_SUMMARY
(cd /tmp/baipp/dist/out/wheels && tree -a * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
fi
echo ----- Metadata Follows -----
echo -e '\n<details><summary>Metadata</summary>\n' >> $GITHUB_STEP_SUMMARY
cat out/sdist/*/PKG-INFO | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
echo ----- End of Metadata -----
- name: Upload metadata
uses: actions/upload-artifact@v4
with:
name: Package Metadata${{ inputs.upload-name-suffix }}
path: /tmp/baipp/dist/out/sdist/*/PKG-INFO
- name: Extract PyPI README
shell: bash
working-directory: /tmp/baipp/dist/out/sdist/
run: |
cat */PKG-INFO | python -c '
import email.parser
import sys
em = email.parser.Parser().parsestr(sys.stdin.read())
suffix = {
"text/markdown": "md",
"text/x-rst": "rst",
}[em["Description-Content-Type"]]
with open(f"PyPI-README.{suffix}", "w") as f:
f.write(em.get_payload())
'
- name: Upload PyPI README
uses: actions/upload-artifact@v4
with:
name: PyPI README${{ inputs.upload-name-suffix }}
path: /tmp/baipp/dist/out/sdist/PyPI-README.*
- name: Generate JSON objects of supported Python versions
id: metadata-setter
shell: bash
working-directory: /tmp/baipp/dist/out/sdist/
run: |
cat */PKG-INFO | python -c '
import email.parser
import json, re, sys
pkg_info = email.parser.Parser().parsestr(sys.stdin.read())
version_tokens = []
for classifier in pkg_info.get_all("Classifier", []):
if match := re.match(r"Programming Language :: Python :: (\d+\.\d+)$", classifier):
version_tokens.append(match.group(1))
package_version = pkg_info.get("Version", "0.0.0")
print(f"package_version={package_version}")
print(f"supported_python_classifiers_json_array={json.dumps(version_tokens)}")
print(f"""supported_python_classifiers_json_job_matrix_value={json.dumps({"python-version": version_tokens})}""")
' >> $GITHUB_OUTPUT