Repository navigation
284 lines (270 loc) · 14.1 KB
/
Copy pathpromote.yml
File metadata and controls
284 lines (270 loc) · 14.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
name: Promote RC to stable release
on:
workflow_dispatch:
inputs:
rc_tag:
description: "RC tag to promote (e.g. v1.5.0-rc.2)"
required: true
type: string
release_notes_extra:
description: "Optional message to prepend to auto-generated release notes"
required: false
type: string
default: ""
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: promote-${{ github.ref }}
cancel-in-progress: false
jobs:
promote:
name: Promote RC to stable
runs-on: ubuntu-latest
environment: release
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
# The persisted GITHUB_TOKEN header overrides the PAT in a push URL, so every
# push would run as github-actions[bot], which the release rulesets reject.
persist-credentials: false
- name: Setup Node.js
uses: ./.github/actions/setup
- name: Validate RC tag and compute stable version
id: version
env:
RC_TAG: ${{ inputs.rc_tag }}
run: |
set -euo pipefail
TAG="${RC_TAG}"
if [[ ! "$TAG" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)-(rc|beta|alpha)\.[0-9]+$ ]]; then
echo "::error::Tag must look like v1.5.0-rc.1; got '${TAG}'"
exit 1
fi
STABLE_VERSION="${BASH_REMATCH[1]}"
STABLE_TAG="v${STABLE_VERSION}"
echo "rc_tag=$TAG" >> "$GITHUB_OUTPUT"
echo "stable_version=$STABLE_VERSION" >> "$GITHUB_OUTPUT"
echo "stable_tag=$STABLE_TAG" >> "$GITHUB_OUTPUT"
echo "Promoting ${TAG} -> ${STABLE_TAG}"
- name: Close versioned milestone
env:
TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
STABLE_VERSION: ${{ steps.version.outputs.stable_version }}
run: node .github/scripts/release-milestone-close.mjs
- name: Install Nix
uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
- name: Bump the version to stable on the release branch
env:
TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
STABLE_VERSION: ${{ steps.version.outputs.stable_version }}
run: |
set -euo pipefail
# Taken from the dispatched ref before the release branch is checked out: a frozen
# branch cut before this script existed would not have it.
cp .github/scripts/refresh-nix-npm-hash.sh "$RUNNER_TEMP/"
# Promote checks out the FROZEN release branch (created by prerelease.yml) and
# rewrites the version there. This guarantees the stable tag points at the
# same code that was tested as the RC plus any cherry-picked bugfixes.
BRANCH="release/v${STABLE_VERSION}"
git fetch origin "$BRANCH"
git checkout "$BRANCH"
git reset --hard "origin/${BRANCH}"
# Writes package-lock.json too. A sed over package.json alone left the
# lockfile behind on every release up to 1.9.0; see the script header.
node .github/scripts/set-release-version.mjs "${STABLE_VERSION}"
# The lockfile's version is part of Nix's npm hash: refresh it in this same commit.
bash "$RUNNER_TEMP/refresh-nix-npm-hash.sh"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json nix/package.nix
git commit --allow-empty -m "chore(release): bump to ${STABLE_VERSION} [skip ci]" || true
git push "https://x-access-token:${TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$BRANCH"
- name: Push stable tag on the release branch tip
env:
# Push with the PAT: the checkout keeps no credentials, and the release-tags
# ruleset only lets its owner delete a tag. The tip commit says [skip ci], so
# the push does not fire build.yml; it is dispatched explicitly right after.
TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
STABLE_TAG: ${{ steps.version.outputs.stable_tag }}
STABLE_VERSION: ${{ steps.version.outputs.stable_version }}
run: |
set -euo pipefail
BRANCH="release/v${STABLE_VERSION}"
git fetch origin "$BRANCH"
git checkout "$BRANCH"
git reset --hard "origin/${BRANCH}"
# Delete remote tag first (idempotent on rerun) and any local tag.
REMOTE="https://x-access-token:${TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push "$REMOTE" ":${STABLE_TAG}" 2>/dev/null || true
git tag -d "$STABLE_TAG" 2>/dev/null || true
git tag "$STABLE_TAG"
git push "$REMOTE" "$STABLE_TAG"
# ORDER MATTERS. Everything that actually publishes the release runs before the
# main-sync below. The stable tag is already pushed at this point, so the build
# and the announcement depend on nothing the sync produces — while the sync is a
# PR round-trip against a remote that fails for reasons of its own. It used to
# run first, and every one of its failures silently skipped both steps under it:
# v1.7.0, v1.8.0 and v1.9.0 all shipped without an automated build (dispatched by
# hand minutes later) and without a #releases announcement.
- name: Trigger build workflow
env:
GH_TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
STABLE_TAG: ${{ steps.version.outputs.stable_tag }}
run: |
set -euo pipefail
# GITHUB_TOKEN tag pushes don't fire build.yml in this setup, dispatch it.
#
# --ref pins the build to the stable tag (the frozen release-branch tip), which
# is also what makes running this before the main-sync correct: the tag already
# points at the released snapshot, so checkout gets the matching package.json +
# code whatever main looks like, and signing/notarization is enabled (tag has
# no '-').
gh workflow run build.yml \
--ref "${STABLE_TAG}" \
-f release_tag="${STABLE_TAG}" \
-f arch=both \
--repo "$GITHUB_REPOSITORY"
# No announcement step here any more. It moved to announce-release.yml, which
# runs on `release: published` — the one event every release path shares,
# including a tag pushed straight to build.yml with no promotion at all. This
# step could only ever announce what THIS workflow did, and it announced it
# from here, before build.yml had produced a single asset.
#
# `release_notes_extra` consequently no longer reaches Discord from this
# workflow. Pass it to the announce dispatch instead when there is something
# to prepend; the automatic run posts the standard message.
# Bookkeeping, not publishing: the release is already out by now. Allowed to fail
# so a stuck PR never masks a successful release — the summary reports it and it
# is trivially redone by hand.
- name: Sync the released version into main
id: sync_main
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
STABLE_VERSION: ${{ steps.version.outputs.stable_version }}
run: |
set -euo pipefail
# Main gets the release's version, not its history. Every fix on the release
# branch is a cherry-pick of a commit already on main, so the version bumps are
# all main lacks. This step used to rebase-merge the whole release branch,
# replaying those cherry-picks too, and once main had moved on they no longer
# applied: v2.1.0's sync PR (#1312) failed five times and main stayed at 2.0.0
# until #1313 did by hand what this step does now. The PR is rebase-merged via
# the PAT, a ruleset bypass actor, so no approval is needed.
BRANCH="release/v${STABLE_VERSION}"
git fetch origin main "$BRANCH"
main_version() {
# An argument, not stdin: readFileSync(0) can throw EAGAIN on a CI pipe.
node -p 'JSON.parse(process.argv[1]).version' "$(git show origin/main:package.json)"
}
# At or past the release, not just equal: promoting an older version after a
# newer one must not set main back.
main_is_current() {
node .github/scripts/version-at-least.mjs "$(main_version)" "$STABLE_VERSION"
}
# From here on, main's own scripts: a release branch cut before one of them
# existed would not have it.
git checkout -B "${BRANCH}-sync" origin/main
# A fix committed to the release branch alone would be left out of a
# version-only sync. Name it, sync the version anyway, and fail the step so
# the summary says main is incomplete.
UNSYNCED=$(git cherry -v origin/main "origin/${BRANCH}" | node .github/scripts/release-unsynced-fixes.mjs)
finish() {
if [[ -n "$UNSYNCED" ]]; then
echo "::error::origin/${BRANCH} has commits main lacks, and the version sync leaves them out. Cherry-pick them onto main, or check that main has them in another form:"
echo "$UNSYNCED"
exit 1
fi
exit 0
}
if main_is_current; then
echo "main is at $(main_version), not behind ${STABLE_VERSION}: nothing to sync."
finish
fi
node .github/scripts/set-release-version.mjs "${STABLE_VERSION}"
# The lockfile's version is part of Nix's npm hash, and the hash must match
# main's lockfile, not the release's.
bash .github/scripts/refresh-nix-npm-hash.sh
git add package.json package-lock.json nix/package.nix
git commit -m "chore(release): release v${STABLE_VERSION} into main"
# --force: a rerun commits again on top of a newer main.
git push --force "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "${BRANCH}-sync"
gh pr create \
--base main \
--head "${BRANCH}-sync" \
--title "chore(release): release v${STABLE_VERSION} into main" \
--body "Sets main to ${STABLE_VERSION}, the version just released. Rebase-merged via PAT; bypass applies because EtienneLescot is a ruleset bypass actor." \
--repo "$GITHUB_REPOSITORY" || echo "(PR already exists — skipping)"
PR_NUMBER=$(gh pr list --head "${BRANCH}-sync" --state open --json number -q '.[0].number' --repo "$GITHUB_REPOSITORY")
if [[ -z "$PR_NUMBER" ]]; then
# L'échec de `gh pr create` ci-dessus est converti en echo, donc on
# arrive ici aussi bien quand la PR existait déjà que quand sa création
# a échoué pour une autre raison. Sortir en 0 dans le second cas
# reportait sync_main en succès alors que le test de version du haut
# avait justement établi que main n'est pas à jour, et l'avertissement
# de fin sautait. On re-teste plutôt que de supposer : quelqu'un a pu
# merger la synchro à la main entre-temps.
git fetch origin main
if main_is_current; then
echo "main is at $(main_version), not behind ${STABLE_VERSION}: nothing to sync."
finish
fi
echo "::error::No open sync PR exists and main is behind ${STABLE_VERSION}."
exit 1
fi
# GitHub computes mergeability asynchronously. Merging ~3s after creating the
# PR raced that computation every time: v1.9.0 got "This branch can't be
# rebased" 2.9s after create, v1.8.0 "has merge conflicts" after 1.7s — and
# both merged by hand, unchanged, minutes later. Wait for a real verdict.
for _ in $(seq 1 30); do
STATE=$(gh pr view "$PR_NUMBER" --json mergeStateStatus -q .mergeStateStatus \
--repo "$GITHUB_REPOSITORY" 2>/dev/null || echo UNKNOWN)
echo "mergeStateStatus=${STATE}"
if [[ "$STATE" != "UNKNOWN" ]]; then break; fi
sleep 5
done
# Retry anyway: leaving UNKNOWN is necessary, not sufficient. MERGED must be
# set by a successful merge — a bare `&& break` loop exits 0 after five
# failures and reports a merge that never happened.
MERGED=0
for _ in $(seq 1 5); do
if gh pr merge "$PR_NUMBER" --rebase --delete-branch --admin \
--repo "$GITHUB_REPOSITORY"; then
MERGED=1
break
fi
sleep 15
done
if [[ "$MERGED" -ne 1 ]]; then
echo "::error::Could not rebase-merge sync PR #${PR_NUMBER} into main after 5 attempts. The release itself is published; merge it by hand."
exit 1
fi
# The release branch itself was already used to publish and contains frozen
# history — leave it in place for forensics. A v1.6.0 release branch should
# never be deleted until the next major cuts over.
finish
- name: Workflow summary
run: |
{
echo "## Release promoted"
echo ""
echo "- Stable tag: \`${{ steps.version.outputs.stable_tag }}\`"
echo "- Promoted from: \`${{ steps.version.outputs.rc_tag }}\`"
echo "- Tier 3 (homebrew/winget/nix/aur) will fire on the published release via OPENSCREEN_RELEASE_TOKEN."
if [[ "${{ steps.sync_main.outcome }}" != "success" ]]; then
echo ""
echo "> [!WARNING]"
echo "> **main sync is incomplete.** The release is published and the build was"
echo "> dispatched. The \`Sync the released version into main\` step's error says what is"
echo "> left: the \`release/v${{ steps.version.outputs.stable_version }}-sync\` → main PR to merge by hand,"
echo "> or release-branch commits that main lacks."
fi
} >> "$GITHUB_STEP_SUMMARY"