-
Notifications
You must be signed in to change notification settings - Fork 1
294 lines (265 loc) · 9.71 KB
/
release.yml
File metadata and controls
294 lines (265 loc) · 9.71 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
name: release
# Manually-triggered stable release. Pick a bump (patch/minor/major) —
# the next vX.Y.Z tag is computed from the latest stable tag. The `notes`
# input is used verbatim as the release body and is also attached to the
# release as `CHANGELOG.md`. An ephemeral release commit (with the built
# ui/dist/ force-added past .gitignore) is created on a detached HEAD and
# the new tag points to *that* commit, so `go install ...@vX.Y.Z` resolves
# a tree containing the embedded UI assets. Main itself is never modified
# — only the tag is pushed to origin.
on:
workflow_dispatch:
inputs:
bump:
description: "Semver bump (patch/minor/major)"
required: true
type: choice
default: patch
options:
- patch
- minor
- major
notes:
description: "Release notes in Markdown. Becomes the release body and the attached CHANGELOG.md asset. Use \\n for newlines if passing via CLI."
required: true
type: string
permissions: read-all
concurrency:
group: release-manual
cancel-in-progress: false
jobs:
tag:
name: compute next tag
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
tag: ${{ steps.ver.outputs.tag }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Compute next stable tag
id: ver
env:
BUMP: ${{ inputs.bump }}
run: |
set -eu
latest=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V \
| tail -1)
if [ -z "$latest" ]; then
latest="v0.0.0"
fi
ver="${latest#v}"
major="${ver%%.*}"
rest="${ver#*.}"
minor="${rest%%.*}"
patch="${rest##*.}"
case "$BUMP" in
major) major=$((major+1)); minor=0; patch=0 ;;
minor) minor=$((minor+1)); patch=0 ;;
patch) patch=$((patch+1)) ;;
*) echo "unknown bump: $BUMP" >&2; exit 1 ;;
esac
next="v${major}.${minor}.${patch}"
echo "tag=$next" >> "$GITHUB_OUTPUT"
echo "Next tag: $next (from $latest, bump=$BUMP)"
ui:
name: build ui
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: ui/package-lock.json
- run: npm --prefix ui ci
- run: npm --prefix ui run build
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ui-dist
path: ui/dist
retention-days: 1
if-no-files-found: error
build:
name: build ${{ matrix.goos }}-${{ matrix.goarch }}
needs: [tag, ui]
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
goos: linux
goarch: amd64
- runner: macos-latest
goos: darwin
goarch: arm64
runs-on: ${{ matrix.runner }}
permissions:
contents: read
env:
CGO_ENABLED: "1"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: go.mod
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: ui-dist
path: ui/dist
- name: Build binary
run: |
set -eu
tag="${{ needs.tag.outputs.tag }}"
sha="${{ github.sha }}"
date="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
pkg="github.com/RandomCodeSpace/docsiq/cmd"
ldflags="-s -w -X ${pkg}.Version=${tag} -X ${pkg}.Commit=${sha} -X ${pkg}.Date=${date}"
go build -tags sqlite_fts5 -trimpath -ldflags="${ldflags}" -o docsiq ./
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
path: docsiq
retention-days: 1
if-no-files-found: error
release:
name: publish release
needs: [tag, build]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # cosign keyless
attestations: write # SLSA provenance
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- uses: sigstore/cosign-installer@cad07c2e89fa2edd6e2d7bab4c1aa38e53f76003 # v4.1.1
with:
# v2.x — v3 broke our sign-blob flag compatibility.
cosign-release: 'v2.6.3'
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
pattern: binary-*
path: downloaded/
- name: Prepare release notes
id: notes
env:
TAG: ${{ needs.tag.outputs.tag }}
NOTES: ${{ inputs.notes }}
run: |
set -eu
if ! printf '%s' "$NOTES" | grep -Eq '[^[:space:]]'; then
echo "::error::The 'notes' workflow input is empty. Fire release.yml again with curated Markdown notes."
exit 1
fi
mkdir -p dist
# CHANGELOG.md attached to the release as-is (same bytes as the body).
printf '# %s\n\n%s\n' "$TAG" "$NOTES" > dist/CHANGELOG.md
# Emit the body to GITHUB_OUTPUT for the next step. The Verify
# footer is appended in the create-release step.
{
echo 'body<<__RN_EOF__'
printf '%s' "$NOTES"
echo
echo '__RN_EOF__'
} >> "$GITHUB_OUTPUT"
- name: Assemble versioned binaries + SHA256SUMS
env:
TAG: ${{ needs.tag.outputs.tag }}
run: |
set -eu
mkdir -p dist
for dir in downloaded/binary-*; do
rest=$(basename "$dir" | sed 's/^binary-//')
goos="${rest%-*}"
goarch="${rest##*-}"
out="dist/docsiq-${TAG}-${goos}-${goarch}"
cp "$dir/docsiq" "$out"
chmod +x "$out"
done
(cd dist && sha256sum docsiq-* > SHA256SUMS)
ls -la dist/
- name: Sign artifacts with cosign (keyless)
run: |
set -eu
cd dist
for f in docsiq-* SHA256SUMS; do
cosign sign-blob --yes \
--output-signature="${f}.sig" \
--output-certificate="${f}.pem" \
"$f"
done
ls -la
- name: Download ui-dist for release commit
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: ui-dist
path: ui/dist
- name: Bake ui/dist into release commit and tag it
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.tag.outputs.tag }}
run: |
set -eu
# ui/dist/ is gitignored on main, so a `go install ...@TAG`
# against the main tree would embed only a placeholder
# index.html and 404 on every /assets/* request. Create an
# ephemeral commit on a detached HEAD that force-includes the
# built ui/dist/, tag that commit as $TAG, and push the tag
# only — main itself is never modified.
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git checkout --detach
git add -f ui/dist
git commit -m "release: bake ui/dist for ${TAG}"
git tag "$TAG"
git push origin "$TAG"
- name: Create GitHub release and upload assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.tag.outputs.tag }}
NOTES_BODY: ${{ steps.notes.outputs.body }}
run: |
set -eu
{
printf '%s\n\n' "$NOTES_BODY"
printf '### Verify\n\n'
printf 'All artifacts are signed with [cosign](https://github.com/sigstore/cosign) keyless via Sigstore.\n\n'
printf '```sh\n'
printf 'cosign verify-blob \\\n'
printf " --certificate-identity-regexp 'https://github.com/RandomCodeSpace/docsiq/\\\\.github/workflows/release\\\\.yml.*' \\\\\n"
printf " --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \\\\\n"
printf ' --certificate docsiq-%s-linux-amd64.pem \\\n' "$TAG"
printf ' --signature docsiq-%s-linux-amd64.sig \\\n' "$TAG"
printf ' docsiq-%s-linux-amd64\n' "$TAG"
printf '```\n'
} > release-notes.md
gh release create "$TAG" \
--title "$TAG" \
--notes-file release-notes.md \
dist/docsiq-* dist/SHA256SUMS dist/SHA256SUMS.sig dist/SHA256SUMS.pem dist/CHANGELOG.md
- name: Generate SLSA build provenance
id: attest
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
with:
subject-path: |
dist/docsiq-*-linux-amd64
dist/docsiq-*-darwin-arm64
dist/SHA256SUMS
- name: Upload provenance to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.tag.outputs.tag }}
run: |
set -eu
cp "${{ steps.attest.outputs.bundle-path }}" "docsiq-${TAG}.intoto.jsonl"
gh release upload "$TAG" "docsiq-${TAG}.intoto.jsonl"