Repository navigation
299 lines (284 loc) · 14.6 KB
/
Copy pathrelease.yml
File metadata and controls
299 lines (284 loc) · 14.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
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
name: Create release PR
# Cutting a release is one deliberate act by a person, and everything after it is automatic. This
# workflow only proposes: it writes the version and the notes and opens a pull request. Merging that
# pull request is what publishes, so the release itself goes through review like anything else.
on:
workflow_dispatch:
inputs:
bump:
description: Version bump
required: true
type: choice
options: [patch, minor, major]
# A stable release goes straight from main. A candidate or beta is cut onto `release/X.Y`
# first, and a final turns the last candidate on that branch into the release itself.
kind:
description: What to release
required: false
default: stable
type: choice
options: [stable, rc, beta, final]
from:
description: The commit on main to cut the first candidate or beta from, as a full commit SHA or a branch name (default the tip). A short SHA does not work.
required: false
default: ""
type: string
dry_run:
description: Show the version and notes without opening a PR
required: false
default: false
type: boolean
permissions:
contents: read
concurrency:
group: openbot-release-pr
cancel-in-progress: false
jobs:
create:
name: create
# Main and the release branches. `release/publish/*` is where the release PRs themselves live,
# and nothing is cut from those. A stable release from a release branch gets this far so that
# "Check the inputs" can refuse it with a reason, instead of the run skipping and looking green.
if: >-
github.ref == 'refs/heads/main' ||
(startsWith(github.ref, 'refs/heads/release/') &&
!startsWith(github.ref, 'refs/heads/release/publish/'))
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
pull-requests: write
steps:
# Two open release PRs would each carry a version computed before the other existed, and
# whichever merged second would publish notes that skip a release.
- name: Refuse a second open release PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { owner, repo } = context.repo;
const { data: pulls } = await github.rest.pulls.list({ owner, repo, state: "open" });
const open = pulls.filter((pull) => pull.head.ref.startsWith("release/publish/"));
if (open.length > 0) {
core.setFailed(`A release PR is already open: ${open.map((p) => p.html_url).join(", ")}`);
}
# `from` picks where a new release branch starts. Anywhere else it would be ignored, and an
# input that is silently ignored is one somebody believes was used.
- name: Check the inputs
env:
KIND: ${{ inputs.kind }}
FROM: ${{ inputs.from }}
run: |
set -euo pipefail
if [ -n "$FROM" ] && { [ "$GITHUB_REF" != refs/heads/main ] || { [ "$KIND" != rc ] && [ "$KIND" != beta ]; }; }; then
echo "::error::'from' only applies to the first candidate or beta, run from main."
exit 1
fi
# A stable release comes from main. A release branch carries one line of candidates, and
# what leaves it as a stable version is the final that finishes them.
if [ "$KIND" = stable ] && [ "$GITHUB_REF" != refs/heads/main ]; then
echo "::error::A stable release is cut from main. From $GITHUB_REF_NAME, cut a candidate, a beta or the final."
exit 1
fi
# A final finishes a candidate, and candidates live on their release branch, never on main.
if [ "$KIND" = final ] && [ "$GITHUB_REF" = refs/heads/main ]; then
echo "::error::A final finishes the candidates on their release/X.Y branch. Run it from that branch."
exit 1
fi
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Empty unless a candidate or beta names its own starting commit, which means the commit
# this run was started on.
ref: ${{ inputs.from }}
# The whole history, because the previous tag is what says where these notes start. It
# brings every tag and every branch too, which the checks below read.
fetch-depth: 0
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.3
- id: prepare
name: Write the version and promote the notes
env:
BUMP: ${{ inputs.bump }}
KIND: ${{ inputs.kind }}
run: |
set -euo pipefail
current=$(bun -e 'console.log(require("./package.json").version)')
# The version in package.json must be one that was actually released, or the bump is
# computed from a number nobody published. The exception is the first release, where there
# is no tag to find yet.
if [ -n "$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --merged HEAD)" ]; then
git rev-parse --verify "refs/tags/v$current" >/dev/null 2>&1 || {
echo "::error::package.json says $current but v$current was never tagged."
exit 1
}
fi
# The version this run is heading for and the branch it belongs to, worked out the same
# way the prepare script below works them out, so they can be checked before anything is
# written.
next=$(CURRENT="$current" bun -e '
const { nextVersion, releaseBranch } = require("./scripts/release-version.ts");
try {
const next = nextVersion(process.env.CURRENT, process.env.BUMP, process.env.KIND);
console.log(next + " " + releaseBranch(next));
} catch (error) {
console.error("::error::" + error.message);
process.exit(1);
}
')
version=${next% *}
branch=${next#* }
# A final ships what a candidate was tested as, so it is cut from the commit a candidate
# was published from and nothing newer. The tags came with the full-history checkout.
if [ "$KIND" = final ] && [ -z "$(git tag --points-at HEAD "v$version-*")" ]; then
echo "::error::$GITHUB_REF_NAME has moved on since its last candidate for $version. Cut a new candidate first."
exit 1
fi
new_branch=""
if [ "$KIND" = rc ] || [ "$KIND" = beta ]; then
if [ "$GITHUB_REF" = refs/heads/main ]; then
# The first candidate or beta starts the release branch. It starts from a commit on
# main, so the branch holds nothing main never had.
git merge-base --is-ancestor HEAD origin/main || {
echo "::error::$(git rev-parse HEAD) is not on main."
exit 1
}
# A branch that already exists has candidates on it, and the next one belongs there.
if git rev-parse --verify --quiet "refs/remotes/origin/$branch" >/dev/null; then
echo "::error::$branch already exists. To cut the next candidate or beta, run from it."
exit 1
fi
new_branch=$branch
fi
fi
# Off main, a run releases the branch it was started on and no other.
if [ "$GITHUB_REF" != refs/heads/main ] && [ "$GITHUB_REF_NAME" != "$branch" ]; then
echo "::error::$version belongs to $branch, not $GITHUB_REF_NAME."
exit 1
fi
# A version is published once. A tag that already carries it means this release happened.
if git rev-parse --verify --quiet "refs/tags/v$version" >/dev/null; then
echo "::error::v$version is already tagged."
exit 1
fi
# A stable release from main must not take a version that a release branch is still
# heading for. It would publish as Latest first, and the final that finishes those
# candidates would then find its version already tagged. A release branch that has been
# finished stays behind, so it is the candidate tags for this exact version that count,
# and a patch after the final still goes ahead.
if [ "$KIND" = stable ] &&
git rev-parse --verify --quiet "refs/remotes/origin/$branch" >/dev/null &&
[ -n "$(git tag --list "v$version-*")" ]; then
echo "::error::$branch already has candidates for $version. Finish them with a final from that branch, or choose a bump past it."
exit 1
fi
{
echo "new_branch=$new_branch"
echo "sha=$(git rev-parse HEAD)"
} >> "$GITHUB_OUTPUT"
# Writes the version, the OpenBot image tag, the Cargo files and the changelog, and
# refuses a changelog with nothing under Unreleased. It appends version, base and the path
# of a file holding the notes to $GITHUB_OUTPUT for the steps below.
bun scripts/release-prepare.ts "$BUMP" "$KIND"
# The notes can be longer than the 65,536 characters GitHub allows in a PR body. The action
# below cuts a longer body to that length and warns (src/main.ts in its v8.1.1). The checklist
# comes first, so the cut only drops the end of the notes. The whole section is still in the
# CHANGELOG.md diff of the PR, and the published release reads it from there, not from here.
# The notes come through a file: an environment variable over 128 KB makes the shell fail with
# "Argument list too long", and the Unreleased section can grow past that. The notes have no
# trailing newline, so the bare echo after cat ends their last line.
- name: Write the PR body
env:
KIND: ${{ inputs.kind }}
VERSION: ${{ steps.prepare.outputs.version }}
NOTES_FILE: ${{ steps.prepare.outputs.notes_file }}
run: |
set -euo pipefail
# A candidate or beta is for the people who asked to try it. It is published where they
# can find it and nowhere that would hand it to everybody else, and it does not wait for
# the smoke journey, because trying it is what it is for.
if [ "$KIND" = rc ] || [ "$KIND" = beta ]; then
{
echo "## Prerelease v$VERSION"
echo
echo "Merging this publishes a GitHub prerelease, never the Latest release. The images"
echo "are tagged v$VERSION and not \`latest\`, and the installers attached to it are"
echo "pinned to this version."
echo
echo "Before merging:"
echo "- [ ] The notes below describe what this $KIND changes"
echo "- [ ] The OpenBot server images are published at v$VERSION, the tag"
echo " backend-images.env now names"
echo
echo "Merging checks this commit before it builds: the full suite, or, when this PR"
echo "changes only the release files, main's passing CI on the commit it merges onto."
echo "There is nothing to check about CI here."
echo
# A prerelease does not promote the changelog, so these are what is under Unreleased.
echo '```'
echo
cat "$NOTES_FILE"
echo
echo
echo '```'
} > /tmp/pr-body.md
exit 0
fi
{
echo "## Release v$VERSION"
echo
echo "Merging this publishes the image, tags the commit and creates the GitHub Release."
echo
echo "Before merging:"
echo "- [ ] The notes below describe what a deployment does differently"
echo "- [ ] The OpenBot server images are published at v$VERSION, the tag"
echo " backend-images.env now names"
echo "- [ ] The smoke journey passed against a licensed deployment, and the result is"
echo " pasted in a comment: \`bash scripts/start.sh && bun run test:smoke\`,"
echo " with OPENBOT_SMOKE_COOKIE set to a signed-in session (docs/releasing.md)"
echo
echo "Merging checks this commit before it builds: the full suite, or, when this PR"
echo "changes only the release files, main's passing CI on the commit it merges onto."
echo "There is nothing to check about CI here. The journey is the part CI cannot do: it"
echo "needs a licence, and a licence belongs to the machine it was issued for."
echo
# The notes come trimmed, so the blank lines the section had around it go back in.
echo '```'
echo
cat "$NOTES_FILE"
echo
echo
echo '```'
} > /tmp/pr-body.md
- name: Preview
if: inputs.dry_run
run: |
git --no-pager diff -- package.json CHANGELOG.md backend-images.env desktop/src-tauri/Cargo.toml desktop/src-tauri/Cargo.lock desktop/intelligence-cli.json
cat /tmp/pr-body.md
# The first candidate or beta needs its branch before a PR can target it. It is made through
# the API with this run's token, so the checkout never holds a credential.
- name: Cut the release branch
if: steps.prepare.outputs.new_branch != '' && !inputs.dry_run
env:
GH_TOKEN: ${{ github.token }}
BRANCH: ${{ steps.prepare.outputs.new_branch }}
SHA: ${{ steps.prepare.outputs.sha }}
run: |
set -euo pipefail
gh api "repos/$GITHUB_REPOSITORY/git/refs" -f "ref=refs/heads/$BRANCH" -f "sha=$SHA"
# A pull request opened by a workflow does not trigger the pull_request workflows, so the
# release PR arrives without its own checks. That is deliberate rather than tolerated: the
# publish path runs the full suite against the release commit before it builds anything, which
# gates the release itself instead of the proposal for one.
- name: Open the release PR
if: '!inputs.dry_run'
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: release/publish/v${{ steps.prepare.outputs.version }}
delete-branch: true
labels: release
commit-message: "Release v${{ steps.prepare.outputs.version }}"
title: "Release v${{ steps.prepare.outputs.version }}"
base: ${{ steps.prepare.outputs.base }}
body-path: /tmp/pr-body.md