-
Notifications
You must be signed in to change notification settings - Fork 0
473 lines (409 loc) · 17.3 KB
/
Copy pathrelease.yml
File metadata and controls
473 lines (409 loc) · 17.3 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
name: Build release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Package version to publish, for example 0.1.0 or v0.1.0"
required: true
type: string
permissions:
contents: read
pull-requests: read
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
release_ref:
name: Resolve release tag
runs-on: ubuntu-24.04
outputs:
tag: ${{ steps.release.outputs.tag }}
version: ${{ steps.release.outputs.version }}
steps:
- name: Resolve release tag
id: release
env:
RELEASE_INPUT: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}
run: |
release_input="${RELEASE_INPUT}"
if [[ ! "${release_input}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error title=Invalid release version::Use MAJOR.MINOR.PATCH or vMAJOR.MINOR.PATCH, got '${release_input}'."
exit 1
fi
release_version="${release_input#v}"
release_tag="v${release_version}"
echo "tag=${release_tag}" >> "${GITHUB_OUTPUT}"
echo "version=${release_version}" >> "${GITHUB_OUTPUT}"
validate:
name: Validate
needs: release_ref
uses: ./.github/workflows/validate.yml
with:
ref: ${{ needs.release_ref.outputs.tag }}
build-package: false
wheelhouse:
name: ${{ matrix.platform }}-py311 wheelhouse
needs: release_ref
runs-on: ${{ matrix.runs_on }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux-x86_64
runs_on: ubuntu-24.04
asset_basename: src-auth-perms-sync-linux-x64
target_description: Linux x64
expected_machine: x86_64
- platform: macos-arm64
runs_on: macos-26
asset_basename: src-auth-perms-sync-macos-arm64
target_description: macOS arm64
expected_machine: arm64
env:
ASSET_BASENAME: ${{ matrix.asset_basename }}
PACKAGE_NAME: src-auth-perms-sync
PYTHON_VERSION: "3.11"
TARGET_DESCRIPTION: ${{ matrix.target_description }}
UV_VERSION: "0.11.7"
steps:
- name: Check out release ref
uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ needs.release_ref.outputs.tag }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache uv
uses: actions/cache@v5
with:
path: ~/.cache/uv
key: uv-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-
- name: Install build tools
run: python -m pip install "uv==${UV_VERSION}"
- name: Validate release inputs
id: release
env:
RELEASE_TAG: ${{ needs.release_ref.outputs.tag }}
run: |
release_tag="${RELEASE_TAG}"
if [[ ! "${release_tag}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error title=Invalid release tag::Use a vMAJOR.MINOR.PATCH tag, got '${release_tag}'."
exit 1
fi
if ! git rev-parse --verify --quiet "refs/tags/${release_tag}" >/dev/null; then
echo "::error title=Missing tag::Tag '${release_tag}' was not fetched. Create and push it before running this workflow."
exit 1
fi
tag_revision="$(git rev-list -n 1 "${release_tag}")"
git fetch --no-tags origin main
main_revision="$(git rev-parse origin/main)"
if ! git merge-base --is-ancestor "${tag_revision}" "${main_revision}"; then
echo "::error title=Tag is not on main::Tag '${release_tag}' points at ${tag_revision}, which is not reachable from origin/main."
echo "::error::Merge the release PR first, then tag the main commit."
exit 1
fi
echo "tag=${release_tag}" >> "${GITHUB_OUTPUT}"
echo "version=${release_tag#v}" >> "${GITHUB_OUTPUT}"
- name: Validate runner architecture
run: |
actual_machine=$(uv run --frozen python - <<'PY'
import platform
print(platform.machine())
PY
)
if [[ "${actual_machine}" != "${{ matrix.expected_machine }}" ]]; then
echo "::error title=Wrong runner architecture::Expected ${{ matrix.expected_machine }}, got ${actual_machine}."
exit 1
fi
- name: Build wheelhouse tarball
id: build
run: |
release_tag="${{ steps.release.outputs.tag }}"
release_version="${{ steps.release.outputs.version }}"
release_dir="build/release/${ASSET_BASENAME}"
wheelhouse_dir="${release_dir}/wheelhouse"
dist_dir="build/release/dist"
requirements_file="build/release/requirements.txt"
runtime_requirements_file="build/release/runtime-requirements.txt"
asset_path="build/release/${ASSET_BASENAME}.tar.gz"
checksum_path="${asset_path}.sha256"
rm -rf build/release
mkdir -p "${wheelhouse_dir}" "${dist_dir}"
shopt -s nullglob
uv build --wheel --sdist --out-dir "${dist_dir}" --no-create-gitignore
project_wheels=("${dist_dir}"/*.whl)
if [[ "${#project_wheels[@]}" -ne 1 ]]; then
echo "::error title=Unexpected wheel count::Expected one project wheel, found ${#project_wheels[@]}."
exit 1
fi
project_source_distributions=("${dist_dir}"/*.tar.gz)
if [[ "${#project_source_distributions[@]}" -ne 1 ]]; then
echo "::error title=Unexpected source distribution count::Expected one project source distribution, found ${#project_source_distributions[@]}."
exit 1
fi
project_wheel_path="${project_wheels[0]}"
project_wheel_name="$(basename "${project_wheel_path}")"
project_source_distribution_path="${project_source_distributions[0]}"
project_source_distribution_name="$(basename "${project_source_distribution_path}")"
case "${project_wheel_name}" in
src_auth_perms_sync-"${release_version}"-*.whl)
;;
*)
echo "::error title=Wheel version mismatch::Expected wheel version ${release_version}, got '${project_wheel_name}'."
exit 1
;;
esac
case "${project_source_distribution_name}" in
src_auth_perms_sync-"${release_version}".tar.gz)
;;
*)
echo "::error title=Source distribution version mismatch::Expected source distribution version ${release_version}, got '${project_source_distribution_name}'."
exit 1
;;
esac
project_wheel_checksum_path="${project_wheel_path}.sha256"
project_source_distribution_checksum_path="${project_source_distribution_path}.sha256"
if [[ ! -f "${project_wheel_path}" ]]; then
echo "::error title=Missing project wheel::Expected ${project_wheel_path} to exist."
exit 1
fi
dependency_metadata_dir="$(mktemp -d)"
git clone --no-hardlinks . "${dependency_metadata_dir}" >/dev/null
(
cd "${dependency_metadata_dir}"
git checkout --detach "${release_tag}" >/dev/null
mkdir -p "$(dirname "${requirements_file}")"
uv export \
--no-sources \
--no-dev \
--no-emit-project \
--no-hashes \
--no-header \
--no-annotate \
--output-file "${requirements_file}"
)
cp "${dependency_metadata_dir}/${requirements_file}" "${requirements_file}"
cp "${requirements_file}" "${runtime_requirements_file}"
if grep -Eq '(^-e[[:space:]]|^(\.\.?/)|(^|[[:space:]])file:| @ (\.\.?/|file:))' "${runtime_requirements_file}"; then
echo "::error title=Unexpected local dependency::Runtime requirements must resolve from PyPI."
cat "${runtime_requirements_file}"
exit 1
fi
python -m pip wheel \
--only-binary=:all: \
--wheel-dir "${wheelhouse_dir}" \
--requirement "${runtime_requirements_file}"
cp "${project_wheel_path}" "${wheelhouse_dir}/"
src_py_lib_wheels=("${wheelhouse_dir}"/src_py_lib-*.whl)
if [[ "${#src_py_lib_wheels[@]}" -ne 1 ]]; then
echo "::error title=Unexpected src-py-lib wheel count::Expected one src-py-lib wheel, found ${#src_py_lib_wheels[@]}."
exit 1
fi
cat > "${wheelhouse_dir}/INSTALL.txt" <<EOF
# src-auth-perms-sync ${release_tag} offline install
This wheelhouse targets ${TARGET_DESCRIPTION} with Python 3.11.
tar -xzf ${ASSET_BASENAME}.tar.gz
python3.11 -m venv .venv
. .venv/bin/activate
pip install --no-index --find-links ./wheelhouse ${PACKAGE_NAME}
src-auth-perms-sync --help
Connected install from PyPI:
pip install ${PACKAGE_NAME}
GitHub release asset install, using the same project wheel uploaded to PyPI:
pip install "https://github.com/sourcegraph/src-auth-perms-sync/releases/download/${release_tag}/${project_wheel_name}"
EOF
(cd "${wheelhouse_dir}" && shasum -a 256 ./*.whl > WHEELS.sha256)
test -f "${project_wheel_path}"
test -f "${wheelhouse_dir}"/src_auth_perms_sync-*.whl
test -f "${wheelhouse_dir}"/src_py_lib-*.whl
if find "${wheelhouse_dir}" -type f \
! -name '*.whl' \
! -name INSTALL.txt \
! -name WHEELS.sha256 \
| grep .; then
echo "::error title=Unexpected wheelhouse content::Wheelhouse contains non-wheel payloads."
exit 1
fi
(
cd "$(dirname "${project_wheel_path}")"
shasum -a 256 "${project_wheel_name}" > "$(basename "${project_wheel_checksum_path}")"
shasum -a 256 "${project_source_distribution_name}" > "$(basename "${project_source_distribution_checksum_path}")"
)
tar -C "${release_dir}" -czf "${asset_path}" wheelhouse
(
cd "$(dirname "${asset_path}")"
shasum -a 256 "$(basename "${asset_path}")" > "$(basename "${checksum_path}")"
)
{
echo "asset_path=${asset_path}"
echo "checksum_path=${checksum_path}"
echo "project_wheel_path=${project_wheel_path}"
echo "project_wheel_name=${project_wheel_name}"
echo "project_source_distribution_path=${project_source_distribution_path}"
echo "project_source_distribution_name=${project_source_distribution_name}"
echo "project_wheel_checksum_path=${project_wheel_checksum_path}"
echo "project_source_distribution_checksum_path=${project_source_distribution_checksum_path}"
} >> "${GITHUB_OUTPUT}"
- name: Validate offline install from tarball
run: |
validation_dir=$(mktemp -d)
tar -xzf "${{ steps.build.outputs.asset_path }}" -C "${validation_dir}"
python3.11 -m venv "${validation_dir}/.venv"
. "${validation_dir}/.venv/bin/activate"
PIP_CACHE_DIR="${validation_dir}/pip-cache" \
GIT_ALLOW_PROTOCOL=file \
pip install \
--no-cache-dir \
--no-index \
--find-links "${validation_dir}/wheelhouse" \
"${PACKAGE_NAME}"
src-auth-perms-sync --help >/tmp/src-auth-perms-sync-release-help.txt
- name: Write release notes
id: notes
run: |
release_tag="${{ steps.release.outputs.tag }}"
project_wheel_name="${{ steps.build.outputs.project_wheel_name }}"
project_source_distribution_name="${{ steps.build.outputs.project_source_distribution_name }}"
notes_path="build/release/release-notes.md"
cat > "${notes_path}" <<EOF
## Customer install
### Restricted/offline Linux x64 + Python 3.11 install
Download \`src-auth-perms-sync-linux-x64.tar.gz\`, then run:
\`\`\`sh
tar -xzf src-auth-perms-sync-linux-x64.tar.gz
python3.11 -m venv .venv
. .venv/bin/activate
pip install --no-index --find-links ./wheelhouse ${PACKAGE_NAME}
src-auth-perms-sync --help
\`\`\`
### Restricted/offline macOS arm64 + Python 3.11 install
Download \`src-auth-perms-sync-macos-arm64.tar.gz\`, then run:
\`\`\`sh
tar -xzf src-auth-perms-sync-macos-arm64.tar.gz
python3.11 -m venv .venv
. .venv/bin/activate
pip install --no-index --find-links ./wheelhouse ${PACKAGE_NAME}
src-auth-perms-sync --help
\`\`\`
The tarball includes this project, \`src-py-lib\`, and all runtime wheels.
Verify the tarball downloads with the matching \`.sha256\` files.
The GitHub release also includes the same \`${project_wheel_name}\` and
\`${project_source_distribution_name}\` files uploaded to PyPI, plus matching checksums.
### Connected PyPI install
\`\`\`sh
pip install ${PACKAGE_NAME}
\`\`\`
### GitHub release asset install
\`\`\`sh
pip install "https://github.com/sourcegraph/src-auth-perms-sync/releases/download/${release_tag}/${project_wheel_name}"
\`\`\`
EOF
echo "path=${notes_path}" >> "${GITHUB_OUTPUT}"
- name: Upload workflow artifact
uses: actions/upload-artifact@v7
with:
name: ${{ env.ASSET_BASENAME }}
path: |
${{ steps.build.outputs.asset_path }}
${{ steps.build.outputs.checksum_path }}
- name: Upload project distribution release artifact
if: matrix.platform == 'linux-x86_64'
uses: actions/upload-artifact@v7
with:
name: src-auth-perms-sync-project-distributions
path: |
${{ steps.build.outputs.project_wheel_path }}
${{ steps.build.outputs.project_source_distribution_path }}
${{ steps.build.outputs.project_wheel_checksum_path }}
${{ steps.build.outputs.project_source_distribution_checksum_path }}
- name: Upload release notes artifact
if: matrix.platform == 'linux-x86_64'
uses: actions/upload-artifact@v7
with:
name: release-notes
path: ${{ steps.notes.outputs.path }}
- name: Upload PyPI artifact
if: matrix.platform == 'linux-x86_64'
uses: actions/upload-artifact@v7
with:
name: pypi-distributions
path: |
${{ steps.build.outputs.project_wheel_path }}
${{ steps.build.outputs.project_source_distribution_path }}
github-release:
name: Publish GitHub release assets
needs: [release_ref, validate, wheelhouse]
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Download wheelhouse artifacts
uses: actions/download-artifact@v8
with:
pattern: src-auth-perms-sync-*
path: release-assets
merge-multiple: true
- name: Download release notes
uses: actions/download-artifact@v8
with:
name: release-notes
path: release-notes
- name: Publish GitHub release assets
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ needs.release_ref.outputs.tag }}
run: |
release_tag="${RELEASE_TAG}"
notes_path="$(find release-notes -name release-notes.md -print -quit)"
mapfile -t release_assets < <(find release-assets -type f | sort)
if [[ -z "${notes_path}" ]]; then
echo "::error title=Missing release notes::release-notes.md was not found in release artifact."
exit 1
fi
if [[ "${#release_assets[@]}" -eq 0 ]]; then
echo "::error title=Missing release assets::No release assets were downloaded."
exit 1
fi
if gh release view "${release_tag}" >/dev/null 2>&1; then
gh release edit "${release_tag}" --title "${release_tag}" --notes-file "${notes_path}"
gh release upload "${release_tag}" "${release_assets[@]}" --clobber
else
gh release create "${release_tag}" \
"${release_assets[@]}" \
--title "${release_tag}" \
--notes-file "${notes_path}" \
--verify-tag
fi
pypi:
name: Publish PyPI package
needs: [validate, wheelhouse]
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
environment:
name: pypi
url: https://pypi.org/project/src-auth-perms-sync/
steps:
- name: Download built distribution
uses: actions/download-artifact@v8
with:
name: pypi-distributions
path: dist
- name: Publish PyPI package
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
skip-existing: true