Repository navigation
213 lines (213 loc) · 8.84 KB
/
Copy pathrelease.yml
File metadata and controls
213 lines (213 loc) · 8.84 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
name: Release
on:
workflow_run:
workflows: [Model-free CI]
types: [completed]
branches: [main]
schedule:
- cron: '23 */6 * * *'
workflow_dispatch:
inputs:
bump:
description: Version bump from the newest vMAJOR.MINOR.PATCH tag
required: true
default: minor
type: choice
options: [patch, minor, major]
prerelease:
description: Publish as a prerelease (required while bundled license text is unresolved)
required: true
default: true
type: boolean
dry_run:
description: Verify only; do not create tags or a release
required: true
default: true
type: boolean
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
# Keep every pending run (such as a manual release) instead of replacing it.
queue: max
jobs:
verify:
name: Verify release candidate
# Unattended runs follow successful main pushes or reconcile on schedule; AUTO_RELEASE is the off switch.
if: >-
github.event_name == 'workflow_dispatch' ||
(vars.AUTO_RELEASE == 'true' && (github.event_name == 'schedule' ||
(github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success')))
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
actions: read
contents: read
outputs:
release: ${{ steps.ci.outputs.release }}
sha: ${{ steps.head.outputs.sha }}
tag: ${{ steps.plan.outputs.tag }}
alias: ${{ steps.plan.outputs.alias }}
move-alias: ${{ steps.plan.outputs.move-alias }}
prerelease: ${{ steps.plan.outputs.prerelease }}
latest: ${{ steps.plan.outputs.latest }}
steps:
- name: Require dispatch from main
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
run: |
echo "::error::Releases are cut only from main."
exit 1
- uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
persist-credentials: false
- name: Resolve main head
id: head
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .node-version
- name: Plan release
id: plan
env:
EVENT: ${{ github.event_name }}
BUMP: ${{ inputs.bump }}
PRERELEASE: ${{ inputs.prerelease }}
AUTO_PRERELEASE: ${{ vars.AUTO_RELEASE_PRERELEASE }}
run: |
if [ "$EVENT" = workflow_dispatch ]; then
node tooling/release.mjs plan "$BUMP" "$PRERELEASE" false
else
node tooling/release.mjs plan patch "${AUTO_PRERELEASE:-true}" true
fi
- name: Require Model-free CI success on this exact commit
id: ci
if: steps.plan.outputs.release == 'true'
env:
GH_TOKEN: ${{ github.token }}
EVENT: ${{ github.event_name }}
REPOSITORY: ${{ github.repository }}
SHA: ${{ steps.head.outputs.sha }}
run: |
count="$(gh api "repos/$REPOSITORY/actions/workflows/ci.yml/runs?head_sha=$SHA&event=push&branch=main&status=success&per_page=1" --jq '.total_count')"
if [ "$count" -lt 1 ]; then
if [ "$EVENT" = workflow_dispatch ]; then
echo "::error::Model-free CI has not succeeded for push $SHA on main."
exit 1
fi
echo "::notice::Model-free CI has not succeeded for $SHA yet; its completion triggers the next release check."
echo "release=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "release=true" >> "$GITHUB_OUTPUT"
- run: corepack enable
if: steps.ci.outputs.release == 'true'
- run: corepack pnpm install --frozen-lockfile --ignore-scripts
if: steps.ci.outputs.release == 'true'
- run: corepack pnpm check
if: steps.ci.outputs.release == 'true'
- name: Require a clean checkout
if: steps.ci.outputs.release == 'true'
run: |
if [ -n "$(git status --porcelain --untracked-files=normal)" ]; then
git status --short
echo "::error::pnpm check left the checkout dirty."
exit 1
fi
publish:
name: Publish ${{ needs.verify.outputs.tag }}
needs: verify
if: needs.verify.outputs.release == 'true' && inputs.dry_run != true
runs-on: ubuntu-latest
timeout-minutes: 5
environment: release
permissions:
actions: read
contents: write
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
SHA: ${{ needs.verify.outputs.sha }}
TAG: ${{ needs.verify.outputs.tag }}
ALIAS: ${{ needs.verify.outputs.alias }}
steps:
- name: Require a release environment restricted to main
run: |
policy="$(gh api "repos/$REPOSITORY/environments/release" --jq '"\(.deployment_branch_policy.protected_branches // false) \(.deployment_branch_policy.custom_branch_policies // false)"')"
if [ "$policy" != "false true" ]; then
echo "::error::The release environment must restrict deployments to exactly branch main before unattended publication."
exit 1
fi
branches="$(gh api --paginate "repos/$REPOSITORY/environments/release/deployment-branch-policies" --jq '.branch_policies[] | "\(.type):\(.name)"')"
if [ "$branches" != "branch:main" ]; then
echo "::error::The release environment must restrict deployments to exactly branch main before unattended publication."
exit 1
fi
- uses: actions/checkout@v7
with:
ref: ${{ needs.verify.outputs.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .node-version
- name: Recheck release plan against current tags
env:
PRERELEASE: ${{ needs.verify.outputs.prerelease }}
MOVE_ALIAS: ${{ needs.verify.outputs.move-alias }}
LATEST: ${{ needs.verify.outputs.latest }}
run: |
RELEASE_TAGS="$(gh api --paginate "repos/$REPOSITORY/git/matching-refs/tags/v" --jq '.[].ref | ltrimstr("refs/tags/")')"
export RELEASE_TAGS
node tooling/release.mjs recheck "$TAG" "$PRERELEASE" "$MOVE_ALIAS" "$LATEST"
- name: Create annotated version tag
run: |
if gh api "repos/$REPOSITORY/git/ref/tags/$TAG" > /dev/null 2>&1; then
actual="$(gh api "repos/$REPOSITORY/commits/refs/tags/$TAG" --jq '.sha')"
if [ "$actual" != "$SHA" ]; then
echo "::error::$TAG already exists at $actual, expected $SHA."
exit 1
fi
echo "$TAG already points to $SHA; resuming."
else
object="$(gh api "repos/$REPOSITORY/git/tags" -f tag="$TAG" -f message="$TAG" -f object="$SHA" -f type=commit --jq '.sha')"
gh api "repos/$REPOSITORY/git/refs" -f ref="refs/tags/$TAG" -f sha="$object" > /dev/null
fi
- name: Publish GitHub Release
env:
PRERELEASE: ${{ needs.verify.outputs.prerelease }}
LATEST: ${{ needs.verify.outputs.latest }}
run: |
if state="$(gh release view "$TAG" --repo "$REPOSITORY" --json isDraft,isPrerelease --jq '"\(.isDraft) \(.isPrerelease)"' 2>/dev/null)"; then
if [ "$state" != "false $PRERELEASE" ]; then
echo "::error::Release $TAG exists but is not a published release with prerelease=$PRERELEASE (draft/prerelease: $state)."
exit 1
fi
echo "Release $TAG is already published; resuming."
exit 0
fi
flags=(--verify-tag --generate-notes --title "$TAG" "--latest=$LATEST")
if [ "$PRERELEASE" = true ]; then flags+=(--prerelease); fi
gh release create "$TAG" --repo "$REPOSITORY" "${flags[@]}"
- name: Advance major alias
if: needs.verify.outputs.move-alias == 'true'
run: |
if gh api "repos/$REPOSITORY/git/ref/tags/$ALIAS" > /dev/null 2>&1; then
gh api -X PATCH "repos/$REPOSITORY/git/refs/tags/$ALIAS" -f sha="$SHA" -F force=true > /dev/null
else
gh api "repos/$REPOSITORY/git/refs" -f ref="refs/tags/$ALIAS" -f sha="$SHA" > /dev/null
fi
- name: Verify published refs
env:
MOVE_ALIAS: ${{ needs.verify.outputs.move-alias }}
run: |
refs=("$TAG")
if [ "$MOVE_ALIAS" = true ]; then refs+=("$ALIAS"); fi
for ref in "${refs[@]}"; do
actual="$(gh api "repos/$REPOSITORY/commits/refs/tags/$ref" --jq '.sha')"
if [ "$actual" != "$SHA" ]; then
echo "::error::$ref resolves to $actual, expected $SHA."
exit 1
fi
done