Repository navigation
162 lines (162 loc) · 6 KB
/
Copy pathvalidate-python-release.yaml
File metadata and controls
162 lines (162 loc) · 6 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
name: Validate Python release
on:
workflow_call:
outputs:
distributions-artifact-id:
description: Upload ID for the validated wheel and sdist artifact
value: ${{ jobs.build.outputs.artifact-id }}
inputs:
source:
description: Package source directory
default: .
type: string
artifact-prefix:
description: Prefix for distribution artifacts in a multi-package release
default: ""
type: string
permissions:
contents: read
jobs:
source-check:
runs-on: ubuntu-26.04
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ github.sha }}
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version: latest-known
python-version: "3.15"
enable-cache: false
- uses: $/install-locked-tools
with:
groups: release-check
venv: ${{ runner.temp }}/release-tools
- name: Run tagged source checks
env:
UV_EXCLUDE_NEWER: 7 days
run: >-
"$RUNNER_TEMP/release-tools/bin/prek" run --all-files
constraints:
runs-on: ubuntu-26.04
outputs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ github.sha }}
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version: latest-known
python-version: "3.15"
enable-cache: false
- id: constraints
uses: $/install-locked-tools
- name: Stage build constraints
env:
SOURCE: ${{ steps.constraints.outputs.build-constraints }}
run: cp "$SOURCE" "$RUNNER_TEMP/build-constraints.txt"
- id: upload
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ inputs.artifact-prefix }}build-constraints
path: ${{ runner.temp }}/build-constraints.txt
if-no-files-found: error
build:
needs: constraints
runs-on: ubuntu-26.04
outputs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.sha }}
- name: Verify the exact release tag
env:
TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
test "$GITHUB_REF" = "refs/tags/$TAG"
git check-ref-format "refs/tags/$TAG"
test "$(git rev-parse "refs/tags/$TAG^{commit}")" = "$(git rev-parse HEAD)"
git merge-base --is-ancestor HEAD origin/main
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version: latest-known
python-version: "3.15"
enable-cache: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ needs.constraints.outputs.artifact-id }}
path: ${{ runner.temp }}
- name: Require empty distribution directory
run: test ! -d dist || test -z "$(find dist -mindepth 1 -maxdepth 1 -print -quit)"
- name: Select build interpreter
run: uv venv --python 3.15 "$RUNNER_TEMP/build-python"
- name: Build wheel and sdist
env:
SOURCE: ${{ inputs.source }}
run: |
set -euo pipefail
build_python=$(uv python find "$RUNNER_TEMP/build-python")
export SOURCE_DATE_EPOCH
SOURCE_DATE_EPOCH=$(git -C "$SOURCE" log -1 --format=%ct)
uv build --python "$build_python" --python-preference only-managed --sdist --wheel \
--build-constraints "$RUNNER_TEMP/build-constraints.txt" --require-build-hashes "$SOURCE" --out-dir dist
- name: Match distribution version to tag
env:
TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
shopt -s nullglob
version=${TAG#v}
wheels=(dist/*-"$version"-*.whl)
sdists=(dist/*-"$version".tar.gz)
files=(dist/*)
if [[ ${#wheels[@]} -ne 1 || ${#sdists[@]} -ne 1 || ${#files[@]} -ne 2 ]]; then
echo "::error::wheel and sdist versions must match $TAG" >&2
exit 1
fi
- id: upload
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ inputs.artifact-prefix }}python-package-distributions
path: dist/*
if-no-files-found: error
validate:
needs: build
runs-on: ubuntu-26.04
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ github.sha }}
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version: latest-known
python-version: "3.15"
enable-cache: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ needs.build.outputs.artifact-id }}
path: dist
- name: Install distribution validators
run: |
uv venv --python 3.15 "$RUNNER_TEMP/package-validators"
uv pip install --python "$RUNNER_TEMP/package-validators" 'twine>=7' 'check-wheel-contents>=0.6.3'
- name: Check distribution metadata
run: uv run --no-project --python "$RUNNER_TEMP/package-validators" twine check dist/*
- name: Check wheel contents
run: uv run --no-project --python "$RUNNER_TEMP/package-validators" check-wheel-contents --no-config dist