Repository navigation
254 lines (223 loc) · 9.5 KB
/
Copy pathpublish.yml
File metadata and controls
254 lines (223 loc) · 9.5 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
# THREAT[TM-INF-027]: build the immutable validated release SHA, including recovery from main.
# Verify packages without registry credentials; upload skips compilation.
name: Publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Existing stable release tag to recover from current main (optional on a tag ref)'
required: false
default: ''
type: string
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
validate-tag:
name: Validate release tag
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.validate.outputs.tag }}
sha: ${{ steps.source.outputs.sha }}
steps:
- name: Validate workflow input
id: validate
env:
EVENT_NAME: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
INPUT_TAG: ${{ inputs.tag }}
run: |
if [ "$EVENT_NAME" = "release" ]; then
TAG="$RELEASE_TAG"
elif [ -n "$INPUT_TAG" ]; then
TAG="$INPUT_TAG"
else
TAG="${GITHUB_REF#refs/tags/}"
fi
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: tag must match vMAJOR.MINOR.PATCH." >&2
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.validate.outputs.tag }}
fetch-depth: 0
persist-credentials: false
- name: Verify tag source
id: source
env:
RELEASE_TAG: ${{ steps.validate.outputs.tag }}
run: |
git fetch --force origin main:refs/remotes/origin/main \
"refs/tags/$RELEASE_TAG:refs/tags/$RELEASE_TAG"
TAG_SHA=$(git rev-list -n 1 "$RELEASE_TAG")
# Validate and build the same immutable tree even during workflow recovery.
git checkout --detach "$TAG_SHA"
VERSION="${RELEASE_TAG#v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$VERSION" != "$CARGO_VERSION" ]; then
echo "Error: tag $RELEASE_TAG does not match Cargo.toml $CARGO_VERSION" >&2
exit 1
fi
MAIN_SHA=$(git rev-parse origin/main)
if { [ "$GITHUB_REF" != "refs/tags/$RELEASE_TAG" ] || [ "$GITHUB_SHA" != "$TAG_SHA" ]; } &&
{ [ "$GITHUB_REF" != "refs/heads/main" ] || [ "$GITHUB_SHA" != "$MAIN_SHA" ]; }; then
echo "Error: workflow ref must be $RELEASE_TAG or current main" >&2
exit 1
fi
if ! git merge-base --is-ancestor "$TAG_SHA" origin/main; then
echo "Error: $RELEASE_TAG is not reachable from origin/main" >&2
exit 1
fi
echo "sha=$TAG_SHA" >> "$GITHUB_OUTPUT"
# Publish bashkit-cpython-wasm (optional dependency of bashkit's `cpython`
# feature; must exist on crates.io before bashkit can be verified)
publish-bashkit-cpython-wasm:
name: Publish bashkit-cpython-wasm
needs: validate-tag
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.validate-tag.outputs.sha }}
persist-credentials: false
- name: Verify publish source is on main
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
SOURCE_SHA=$(git rev-parse HEAD)
if ! git merge-base --is-ancestor "$SOURCE_SHA" origin/main; then
echo "Error: publish source $SOURCE_SHA is not reachable from origin/main"
exit 1
fi
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
- name: Verify bashkit-cpython-wasm package without credentials
run: |
cargo publish --dry-run -p bashkit-cpython-wasm
# Cargo 1.95 publish dry-runs retain a temporary archive. Finalize
# the verified package at Cargo's package output before measuring it.
cargo package -p bashkit-cpython-wasm
# crates.io rejects crates over 10 MiB; the embedded snapshot and
# stdlib keep this one close to that limit.
crate_version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
archive="${CARGO_TARGET_DIR:-target}/package/bashkit-cpython-wasm-${crate_version}.crate"
size=$(wc -c < "$archive")
echo "crate size: $size bytes"
if [ "$size" -ge 10485760 ]; then
echo "Error: bashkit-cpython-wasm crate exceeds the crates.io 10 MiB limit"
exit 1
fi
- name: Publish bashkit-cpython-wasm to crates.io
run: cargo publish --no-verify -p bashkit-cpython-wasm
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Publish bashkit (core library) to crates.io
publish-bashkit:
name: Publish bashkit
runs-on: ubuntu-latest
needs: [validate-tag, publish-bashkit-cpython-wasm]
environment: release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.validate-tag.outputs.sha }}
persist-credentials: false
- name: Verify publish source is on main
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
SOURCE_SHA=$(git rev-parse HEAD)
if ! git merge-base --is-ancestor "$SOURCE_SHA" origin/main; then
echo "Error: publish source $SOURCE_SHA is not reachable from origin/main"
exit 1
fi
echo "Publish source verified on origin/main: $SOURCE_SHA"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
- name: Verify version matches tag
env:
RELEASE_TAG: ${{ needs.validate-tag.outputs.tag }}
run: |
TAG_VERSION="${RELEASE_TAG#v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
echo "Version verified: $TAG_VERSION"
- name: Wait for crates.io index update
run: sleep 30
- name: Verify bashkit package without credentials
run: cargo publish --dry-run -p bashkit
- name: Publish bashkit to crates.io
run: cargo publish --no-verify -p bashkit
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Publish bashkit-cli (depends on bashkit)
publish-bashkit-cli:
name: Publish bashkit-cli
runs-on: ubuntu-latest
needs: [validate-tag, publish-bashkit]
environment: release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.validate-tag.outputs.sha }}
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
- name: Wait for crates.io index update
run: sleep 30
- name: Verify bashkit-cli package without credentials
run: cargo publish --dry-run -p bashkit-cli
- name: Publish bashkit-cli to crates.io
run: cargo publish --no-verify -p bashkit-cli
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Publish bashkit-scripted-tool (depends on bashkit)
publish-bashkit-scripted-tool:
name: Publish bashkit-scripted-tool
runs-on: ubuntu-latest
needs: [validate-tag, publish-bashkit]
environment: release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.validate-tag.outputs.sha }}
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
- name: Wait for crates.io index update
run: sleep 30
- name: Verify bashkit-scripted-tool package without credentials
run: cargo publish --dry-run -p bashkit-scripted-tool
- name: Publish bashkit-scripted-tool to crates.io
run: cargo publish --no-verify -p bashkit-scripted-tool
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# ============================================================================
# Verify all packages were published successfully
# ============================================================================
verify-publish:
name: Verify published versions
runs-on: ubuntu-latest
needs: [validate-tag, publish-bashkit-cpython-wasm, publish-bashkit, publish-bashkit-cli, publish-bashkit-scripted-tool]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Verification code belongs to the trusted workflow revision.
ref: ${{ github.sha }}
persist-credentials: false
- name: Wait for crates.io propagation
run: sleep 60
- name: Verify crates.io versions
env:
RELEASE_TAG: ${{ needs.validate-tag.outputs.tag }}
run: |
EXPECTED="${RELEASE_TAG#v}"
echo "Expected version: $EXPECTED"
python3 scripts/verify_crates_publish.py --expected "$EXPECTED" bashkit-cpython-wasm bashkit bashkit-cli bashkit-scripted-tool