-
Notifications
You must be signed in to change notification settings - Fork 1
329 lines (279 loc) · 10.1 KB
/
release-auto.yml
File metadata and controls
329 lines (279 loc) · 10.1 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Autonomous Release
on:
push:
branches: [main]
paths:
- Cargo.toml
- pyproject.toml
workflow_dispatch:
permissions:
contents: write
attestations: write
id-token: write
concurrency:
group: release-auto-${{ github.ref_name }}
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
jobs:
prepare:
name: Prepare release
runs-on: ubuntu-24.04
outputs:
should_build: ${{ steps.prepare.outputs.should_build }}
should_publish_github: ${{ steps.prepare.outputs.should_publish_github }}
should_publish_pypi: ${{ steps.prepare.outputs.should_publish_pypi }}
version: ${{ steps.prepare.outputs.version }}
project_version: ${{ steps.prepare.outputs.project_version }}
commit_sha: ${{ steps.prepare.outputs.commit_sha }}
release_ref: ${{ steps.prepare.outputs.release_ref }}
steps:
- uses: actions/checkout@v6
- name: Check release eligibility
id: prepare
shell: bash
run: |
set -euo pipefail
cargo_version="$(
python - <<'PY'
import tomllib
with open("Cargo.toml", "rb") as f:
print(tomllib.load(f)["workspace"]["package"]["version"])
PY
)"
pyproject_version="$(
python - <<'PY'
import tomllib
with open("pyproject.toml", "rb") as f:
print(tomllib.load(f)["project"]["version"])
PY
)"
if [ "$cargo_version" != "$pyproject_version" ]; then
echo "Cargo.toml version ($cargo_version) does not match pyproject.toml version ($pyproject_version)" >&2
exit 1
fi
version="v${cargo_version}"
commit_sha="$(git rev-parse HEAD)"
release_ref="${commit_sha}"
tag_exists="false"
tag_sha=""
if tag_sha="$(git ls-remote --exit-code --tags origin "refs/tags/${version}" | awk '{print $1}' | tail -n1)"; then
tag_exists="true"
release_ref="${version}"
fi
pypi_json="$(mktemp)"
if curl -fsSL https://pypi.org/pypi/fbuild/json -o "$pypi_json"; then
latest="$(python -c 'import json,sys; print(json.load(open(sys.argv[1]))["info"]["version"])' "$pypi_json")"
pypi_file_count="$(python -c 'import json,sys; data=json.load(open(sys.argv[1])); print(len(data.get("releases", {}).get(sys.argv[2], [])))' "$pypi_json" "$cargo_version")"
else
latest="0.0.0"
pypi_file_count="0"
fi
should_build="false"
should_publish_github="false"
should_publish_pypi="false"
newest="$(printf '%s\n%s\n' "$latest" "$cargo_version" | sort -V | tail -n1)"
if [ "$tag_exists" != "true" ] && [ "$newest" = "$cargo_version" ] && [ "$pypi_file_count" -lt 4 ]; then
should_build="true"
should_publish_github="true"
should_publish_pypi="true"
elif [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ] && [ "$tag_exists" = "true" ] && [ "$pypi_file_count" -lt 4 ]; then
should_build="true"
should_publish_pypi="true"
fi
{
echo "version=${version}"
echo "project_version=${cargo_version}"
echo "commit_sha=${commit_sha}"
echo "release_ref=${release_ref}"
echo "should_build=${should_build}"
echo "should_publish_github=${should_publish_github}"
echo "should_publish_pypi=${should_publish_pypi}"
} >> "$GITHUB_OUTPUT"
echo "Candidate version: ${version}"
echo "Latest PyPI version: ${latest}"
echo "PyPI files for ${cargo_version}: ${pypi_file_count}"
echo "Tag exists: ${tag_exists}"
echo "Tag SHA: ${tag_sha:-<none>}"
echo "Release ref: ${release_ref}"
echo "Should build: ${should_build}"
echo "Should publish GitHub release: ${should_publish_github}"
echo "Should publish PyPI: ${should_publish_pypi}"
build:
name: Native build (${{ matrix.target }})
needs: prepare
if: needs.prepare.outputs.should_build == 'true'
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
runner: ubuntu-latest
binary_ext: ""
linux_cross: false
macos_cross: false
- target: aarch64-unknown-linux-musl
runner: ubuntu-latest
binary_ext: ""
linux_cross: true
macos_cross: false
- target: aarch64-apple-darwin
runner: macos-latest
binary_ext: ""
linux_cross: false
macos_cross: false
- target: x86_64-pc-windows-msvc
runner: windows-latest
binary_ext: ".exe"
linux_cross: false
macos_cross: false
uses: ./.github/workflows/template_native_build.yml
with:
target: ${{ matrix.target }}
runner: ${{ matrix.runner }}
binary_ext: ${{ matrix.binary_ext }}
linux_cross: ${{ matrix.linux_cross }}
macos_cross: ${{ matrix.macos_cross }}
ref: ${{ needs.prepare.outputs.release_ref }}
publish:
name: Publish GitHub release
needs: [prepare, build]
if: needs.prepare.outputs.should_publish_github == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.prepare.outputs.release_ref }}
- name: Download native artifacts
uses: actions/download-artifact@v8
with:
pattern: binaries-*
path: artifacts
- name: Package release archives
shell: bash
run: |
set -euo pipefail
version="${{ needs.prepare.outputs.version }}"
mkdir -p dist pkg
for artifact_dir in artifacts/binaries-*; do
[ -d "$artifact_dir" ] || continue
target="${artifact_dir#artifacts/binaries-}"
package_name="fbuild-${version}-${target}"
package_dir="pkg/${package_name}"
rm -rf "$package_dir"
mkdir -p "$package_dir"
cp -a "$artifact_dir"/. "$package_dir"/
if [[ "$target" == *windows* ]]; then
(cd pkg && zip -r "../dist/${package_name}.zip" "$package_name")
else
tar -C pkg -czf "dist/${package_name}.tar.gz" "$package_name"
fi
done
cd dist
sha256sum fbuild-* > "fbuild-${version}-SHA256SUMS.txt"
- name: Attest release artifacts
uses: actions/attest-build-provenance@v4
with:
subject-checksums: dist/fbuild-${{ needs.prepare.outputs.version }}-SHA256SUMS.txt
- name: Create draft release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
version="${{ needs.prepare.outputs.version }}"
gh release create "$version" dist/* \
--draft \
--generate-notes \
--target "${{ needs.prepare.outputs.release_ref }}" \
--title "$version"
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: gh release edit "${{ needs.prepare.outputs.version }}" --draft=false
build-pypi:
name: Build PyPI wheels
needs: [prepare, build]
if: needs.prepare.outputs.should_publish_pypi == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.prepare.outputs.release_ref }}
- name: Download native artifacts
uses: actions/download-artifact@v8
with:
pattern: binaries-*
path: dist/_tmp
- name: Build wheels
shell: bash
run: |
set -euo pipefail
python - <<'PY'
import shutil
import ci.publish as publish
tmp = publish.DIST_DIR / "_tmp"
missing = []
for artifact_name, subdir in publish.ARTIFACT_MAP.items():
src = tmp / artifact_name
if not src.exists():
missing.append(artifact_name)
continue
dest = publish.DIST_DIR / subdir
if dest.exists():
shutil.rmtree(dest)
dest.mkdir(parents=True)
for path in src.iterdir():
if path.is_file():
target = dest / path.name
shutil.copy2(path, target)
if not path.name.endswith(".exe"):
target.chmod(0o755)
if missing:
raise SystemExit(f"Missing native artifacts: {', '.join(missing)}")
meta = publish.read_project_meta()
wheels = publish.build_all_wheels(*meta)
print(f"Built {len(wheels)} wheel(s)")
PY
- name: Smoke test Linux x86_64 wheel
shell: bash
run: |
set -euo pipefail
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install dist/wheels/*manylinux_2_17_x86_64*.whl
fbuild --version
python -c "import fbuild; print(fbuild.__version__)"
- name: Upload PyPI distributions
uses: actions/upload-artifact@v7
with:
name: pypi-fbuild
path: dist/wheels/*.whl
if-no-files-found: error
publish-pypi:
name: Publish PyPI
needs: [prepare, build-pypi]
if: needs.prepare.outputs.should_publish_pypi == 'true'
runs-on: ubuntu-24.04
environment: pypi
permissions:
contents: read
id-token: write
steps:
- name: Download PyPI distributions
uses: actions/download-artifact@v8
with:
name: pypi-fbuild
path: dist
- name: List distributions
shell: bash
run: ls -lh dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1
with:
packages-dir: dist
attestations: true
skip-existing: true