Repository navigation
234 lines (218 loc) · 9.17 KB
/
Copy pathrelease.yml
File metadata and controls
234 lines (218 loc) · 9.17 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
name: release
# Publishes the Draft Release the releasing agent created for a version tag.
# The agent owns the tag and the notes; this workflow owns going public: the full
# gate from ci.yml must pass first, then the viva command is built for every
# platform and attached to the draft with its checksums and the Homebrew and
# Scoop manifests, the draft's title, body and exact asset list are checked, and
# the draft is flipped to published. The process this implements is
# docs/releases.md; re-running a single tag is
# gh workflow run release.yml -f tag=v<version>
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
tag:
description: Annotated tag whose draft Release should be published
required: true
type: string
permissions:
contents: read
concurrency:
group: release-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
# The same gate main runs: the tag commit is tested before anything goes public.
gate:
uses: ./.github/workflows/ci.yml
# The viva command, one archive per platform. A macOS program reaches Cocoa
# through cgo, so the darwin archives are built on macOS; the rest need no cgo.
build-darwin:
needs: gate
runs-on: macos-latest
env:
TAG: ${{ inputs.tag || github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref_name }}
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: tools/release/build.sh "$TAG" dist darwin/arm64 darwin/amd64
- uses: actions/upload-artifact@v4
with:
name: archives-darwin
path: dist/
if-no-files-found: error
build-other:
needs: gate
runs-on: ubuntu-latest
env:
TAG: ${{ inputs.tag || github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref_name }}
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: tools/release/build.sh "$TAG" dist linux/amd64 linux/arm64 windows/amd64 windows/arm64
- uses: actions/upload-artifact@v4
with:
name: archives-other
path: dist/
if-no-files-found: error
publish:
# Both build jobs already need the gate, so it has run before this starts.
needs: [build-darwin, build-other]
runs-on: ubuntu-latest
permissions:
contents: write
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ inputs.tag || github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref_name }}
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: the tag is annotated and points into main
run: |
case "$TAG" in
v[0-9]*) ;;
*) echo "not a version tag: $TAG" >&2; exit 1 ;;
esac
test "$(git cat-file -t "refs/tags/$TAG")" = tag || {
echo "$TAG is not an annotated tag" >&2; exit 1; }
git fetch --no-tags origin main
git merge-base --is-ancestor HEAD FETCH_HEAD || {
echo "$TAG does not point into main" >&2; exit 1; }
- name: wait for the agent's draft Release
id: draft
run: |
release=""
for _ in $(seq 1 40); do
if release=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" \
--json isDraft,name,assets,body,databaseId); then
break
fi
release=""
sleep 15
done
test -n "$release" || {
echo "no Release for $TAG after 10 minutes; the agent creates the draft first:" >&2
echo " gh release create $TAG --draft --title \"Viva $TAG\" --notes-file <notes>" >&2
exit 1; }
if ! jq -e '.isDraft' <<<"$release" >/dev/null; then
echo "$TAG is already published; nothing to do" >&2
echo "draft=false" >> "$GITHUB_OUTPUT"
exit 0
fi
test "$(jq -r '.name' <<<"$release")" = "Viva $TAG" || {
echo "release name must be 'Viva $TAG'" >&2; exit 1; }
# A rerun finds the archives a failed run already attached; anything
# else on the draft is not ours to publish.
unexpected=$(jq -r '.assets[].name' <<<"$release" | grep -Ev '^(viva_v[^/]+_(darwin|linux|windows)_(amd64|arm64)\.(tar\.gz|zip)|SHA256SUMS|viva\.rb|viva\.json)$' || true)
test -z "$unexpected" || {
echo "release has assets Viva does not publish: $unexpected" >&2; exit 1; }
test -n "$(jq -r '.body' <<<"$release")" || {
echo "release body is empty" >&2; exit 1; }
echo "draft=true" >> "$GITHUB_OUTPUT"
echo "id=$(jq -r '.databaseId' <<<"$release")" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
if: steps.draft.outputs.draft == 'true'
with:
pattern: archives-*
path: dist
merge-multiple: true
- name: checksums and package manifests
if: steps.draft.outputs.draft == 'true'
run: |
tools/release/sums.sh dist
# Homebrew and Scoop only carry final releases.
case "$TAG" in
*-*) ;;
*) go run ./tools/releasepkg -version "$TAG" -sums dist/SHA256SUMS -out packages
cp packages/Formula/viva.rb packages/bucket/viva.json dist/ ;;
esac
- name: the built program reports the tag
if: steps.draft.outputs.draft == 'true'
run: |
tar -xzf "dist/viva_${TAG}_linux_amd64.tar.gz" -C "$RUNNER_TEMP"
test "$("$RUNNER_TEMP/viva" version | cut -d' ' -f2)" = "$TAG" || {
echo "viva version does not say $TAG" >&2; exit 1; }
- name: attach the assets
if: steps.draft.outputs.draft == 'true'
run: |
gh release upload "$TAG" --repo "$GITHUB_REPOSITORY" --clobber dist/*
want=$(cd dist && ls | LC_ALL=C sort)
got=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name' | LC_ALL=C sort)
test "$want" = "$got" || {
echo "release assets differ from what was built" >&2
diff <(echo "$want") <(echo "$got") >&2 || true
exit 1; }
- name: publish
if: steps.draft.outputs.draft == 'true'
run: |
prerelease=false
case "$TAG" in *-*) prerelease=true ;; esac
# PATCH by release id: the tag lookup endpoint does not return drafts.
printf '{"draft":false,"prerelease":%s}\n' "$prerelease" |
gh api --method PATCH "repos/$GITHUB_REPOSITORY/releases/${{ steps.draft.outputs.id }}" --input -
gh release view "$TAG" --repo "$GITHUB_REPOSITORY" \
--json name,tagName,isDraft,isPrerelease,assets,url \
--jq '"published \(.url) name=\(.name) draft=\(.isDraft) prerelease=\(.isPrerelease)"' \
| tee -a "$GITHUB_STEP_SUMMARY"
- name: keep the package manifests for the tap
if: steps.draft.outputs.draft == 'true' && !contains(env.TAG, '-')
uses: actions/upload-artifact@v4
with:
name: package-manifests
path: packages/
if-no-files-found: error
# Updates the Homebrew and Scoop manifests in vivaui/homebrew-tap, one
# repository serving both: `brew install vivaui/tap/viva` and
# `scoop bucket add vivaui https://github.com/vivaui/homebrew-tap`. It runs
# only for a final release, after the release is public (the manifests name
# its URLs), and only when the repository has a TAP_TOKEN secret: a token with
# contents:write on that repository. Without it the release is complete and
# this job reports that it had nothing to do.
tap:
needs: publish
if: ${{ !contains(inputs.tag || github.ref_name, '-') }}
runs-on: ubuntu-latest
env:
TAP_TOKEN: ${{ secrets.TAP_TOKEN }}
TAG: ${{ inputs.tag || github.ref_name }}
steps:
- name: manifests
id: manifests
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: package-manifests
path: packages
- name: push to the tap
run: |
if [ -z "$TAP_TOKEN" ]; then
echo "no TAP_TOKEN secret; the tap was not updated" | tee -a "$GITHUB_STEP_SUMMARY"; exit 0
fi
if [ "${{ steps.manifests.outcome }}" != success ]; then
echo "no manifests for $TAG (it was published by an earlier run); rerun is not needed" | tee -a "$GITHUB_STEP_SUMMARY"; exit 0
fi
git clone --depth 1 "https://x-access-token:${TAP_TOKEN}@github.com/vivaui/homebrew-tap.git" tap
mkdir -p tap/Formula tap/bucket
cp packages/Formula/viva.rb tap/Formula/viva.rb
cp packages/bucket/viva.json tap/bucket/viva.json
cd tap
git add Formula/viva.rb bucket/viva.json
if git diff --cached --quiet; then
echo "the tap already has $TAG" | tee -a "$GITHUB_STEP_SUMMARY"; exit 0
fi
git -c user.name="viva release" -c user.email="release@vivaui.dev" commit -m "viva $TAG"
git push origin HEAD
echo "tap updated to $TAG" | tee -a "$GITHUB_STEP_SUMMARY"