Repository navigation
248 lines (228 loc) · 11.5 KB
/
Copy pathrelease-mirror.yml
File metadata and controls
248 lines (228 loc) · 11.5 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
name: Mirror release
# camy is built, signed, and published to the release channel
# (https://dl.camy.sh/stable/) by a private pipeline. This workflow turns each
# published version into a GitHub Release here, with the same assets, after
# verifying them: every tarball against the version-scoped SHA256SUMS, and
# that manifest against its cosign signature with the signing workflow's
# identity pinned (the same check docs/verifying-releases.md shows). It runs
# with this repository's own token and uploads nothing it could not verify.
# Release notes come from CHANGELOG.md; a version whose heading still says
# "unreleased" is skipped until the notes and the date are written.
on:
# Scheduled polling removed 2026-09-17: the every-30-minutes cron was a no-op
# on ~99% of runs (the channel VERSION had not changed). Mirror a release
# on demand with workflow_dispatch, or wire a repository_dispatch from the
# private release pipeline so a real publish triggers exactly one run.
workflow_dispatch:
inputs:
version:
description: "Version to mirror (default: the channel's current VERSION)"
required: false
default: ""
npm_only:
description: "Re-run only the npm job for a version whose GitHub Release already exists"
type: boolean
required: false
default: false
permissions:
contents: write
concurrency:
group: mirror-release
cancel-in-progress: false
env:
CHANNEL: https://dl.camy.sh/stable
# The workflow that signs releases lives in the private source repository.
SIGNER: '^https://github\.com/CamyAI/camy-cli/\.github/workflows/release\.yml@refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$'
# The source repository the SLSA provenance must name, for slsa-verifier.
SOURCE: github.com/CamyAI/camy-cli
# The release minisign public key, as published in docs/verifying-releases.md
# and pinned by scripts/install.sh.
MINISIGN_PUB: RWT7bpmBcMfiVQvo6BbIeVDh7f9B8WbapvOEBzs7TxhSkLsjlySfxXG6
jobs:
mirror:
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
version: ${{ steps.v.outputs.version }}
released: ${{ steps.v.outputs.skip == 'false' }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Resolve the version
id: v
env:
GH_TOKEN: ${{ github.token }}
INPUT: ${{ github.event.inputs.version }}
NPM_ONLY: ${{ github.event.inputs.npm_only }}
run: |
set -euo pipefail
v="${INPUT:-$(curl -fsSL --retry 3 --proto '=https' --tlsv1.2 "$CHANNEL/VERSION" | tr -cd '0-9A-Za-z.-')}"
case "$v" in [0-9]*.[0-9]*.[0-9]*) ;; *) echo "::error::unexpected VERSION '$v'"; exit 1 ;; esac
echo "skip=true" >> "$GITHUB_OUTPUT"
heading=$(grep -E "^## ${v//./\\.}( |$)" CHANGELOG.md || true)
if [ -z "$heading" ]; then
echo "::notice::$v has no CHANGELOG.md section, so it is not a public release; nothing to do"; exit 0
fi
case "$heading" in
*nreleased*) echo "::notice::CHANGELOG.md still marks $v unreleased; write the notes and the date, then re-run"; exit 0 ;;
esac
if gh release view "v$v" >/dev/null 2>&1; then
if [ "$NPM_ONLY" = "true" ]; then
echo "npm_only=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::v$v is already released"; exit 0
fi
fi
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "version=$v" >> "$GITHUB_OUTPUT"
- name: Install cosign
if: steps.v.outputs.skip == 'false'
uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3
# Pinned and checked against the Go module checksum database; verifies
# the minisign signature on the Camy.app zip (1.0.3 on).
- name: Install minisign
run: |
set -euo pipefail
go install aead.dev/minisign/cmd/minisign@v0.3.0
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Install slsa-verifier
if: steps.v.outputs.skip == 'false'
uses: slsa-framework/slsa-verifier/actions/installer@ea584f4502babc6f60d9bc799dbbb13c1caa9ee6 # v2.7.1
- name: Download and verify
if: steps.v.outputs.skip == 'false'
env:
V: ${{ steps.v.outputs.version }}
run: |
set -euo pipefail
mkdir -p assets && cd assets
get() { curl -fsSL --retry 3 --retry-delay 2 --proto '=https' --tlsv1.2 -O "$CHANNEL/$1"; }
get "SHA256SUMS-$V"; get "SHA256SUMS-$V.sig"; get "SHA256SUMS-$V.pem"
get "SHA256SUMS-$V.minisig" || { echo "::error::no minisign signature published for $V"; exit 1; }
cosign verify-blob \
--certificate "SHA256SUMS-$V.pem" --signature "SHA256SUMS-$V.sig" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp "$SIGNER" \
"SHA256SUMS-$V"
# Every file that lands on the GitHub Release is checked against the
# cosign-verified manifest: the tarballs and their SBOMs by hash here.
check() {
want=$(awk -v f="$1" '($2 == f || $2 == "*" f) { print $1; exit }' "SHA256SUMS-$V")
got=$(sha256sum "$1" | cut -d' ' -f1)
if [ -z "$want" ] || [ "$want" != "$got" ]; then echo "::error::$1 does not match SHA256SUMS-$V"; exit 1; fi
}
for p in darwin_arm64 darwin_amd64 linux_arm64 linux_amd64; do
t="camy_${V}_${p}.tar.gz"
get "$t"; check "$t"
get "$t.sbom.cdx.json"; check "$t.sbom.cdx.json"
done
# SLSA build provenance is mandatory from 1.0.1 on; only 1.0.0
# predates it. It must verify for every tarball: the provenance names
# the source repository, the tag, and the builder.
if [ "$V" = "1.0.0" ]; then
echo "::notice::$V predates SLSA provenance"
else
get "camy_$V.intoto.jsonl" || { echo "::error::no SLSA provenance published for $V; refusing to mirror"; exit 1; }
for p in darwin_arm64 darwin_amd64 linux_arm64 linux_amd64; do
slsa-verifier verify-artifact "camy_${V}_${p}.tar.gz" \
--provenance-path "camy_$V.intoto.jsonl" \
--source-uri "$SOURCE" --source-tag "v$V"
done
fi
# The notarized Camy.app bundle, published from 1.0.2 on beside the
# tarballs. 1.0.2 shipped it with a sha256 sidecar and Apple's
# notarization only; from 1.0.3 the zip carries its own cosign and
# minisign signatures and is a subject of the same SLSA provenance
# as the tarballs, and every one of the three must verify.
Z="Camy_${V}_darwin.zip"
if get "$Z.sha256"; then
get "$Z"
want=$(awk '{print $1}' "$Z.sha256"); got=$(sha256sum "$Z" | cut -d' ' -f1)
[ "$want" = "$got" ] || { echo "::error::$Z does not match its sha256 sidecar"; exit 1; }
if [ "$V" = "1.0.2" ]; then
echo "::notice::$V predates the bundle's signatures and provenance"
else
get "$Z.sig"; get "$Z.pem"
get "$Z.minisig" || { echo "::error::no minisign signature published for $Z"; exit 1; }
cosign verify-blob \
--certificate "$Z.pem" --signature "$Z.sig" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp "$SIGNER" \
"$Z"
minisign -Vm "$Z" -x "$Z.minisig" -P "$MINISIGN_PUB"
slsa-verifier verify-artifact "$Z" \
--provenance-path "camy_$V.intoto.jsonl" \
--source-uri "$SOURCE" --source-tag "v$V"
fi
else
echo "::notice::no Camy.app bundle published for $V"
fi
ls -la
# The npm job builds from these exact bytes, not from a second download.
- name: Keep the verified assets for the npm job
if: steps.v.outputs.skip == 'false'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: assets-${{ steps.v.outputs.version }}
path: assets/
retention-days: 1
- name: Release notes from CHANGELOG.md
if: steps.v.outputs.skip == 'false' && steps.v.outputs.npm_only != 'true'
env:
V: ${{ steps.v.outputs.version }}
run: |
set -euo pipefail
awk -v v="$V" '/^## / { if (on) exit; on = ($2 == v); next } on { print }' CHANGELOG.md \
| sed -e '1{/^$/d;}' > notes.md
[ -s notes.md ] || { echo "::error::empty CHANGELOG.md section for $V"; exit 1; }
printf '\n---\n\nEvery asset was downloaded from the release channel and verified before upload: checksums against `SHA256SUMS-%s`, that manifest against its cosign signature, and, where published, each tarball and the Camy.app zip against the SLSA provenance `camy_%s.intoto.jsonl`. See docs/verifying-releases.md.\n' "$V" "$V" >> notes.md
cat notes.md
- name: Create the GitHub Release
if: steps.v.outputs.skip == 'false' && steps.v.outputs.npm_only != 'true'
env:
GH_TOKEN: ${{ github.token }}
V: ${{ steps.v.outputs.version }}
run: |
set -euo pipefail
gh release create "v$V" --target "$GITHUB_SHA" --title "v$V" --notes-file notes.md --latest assets/*
echo "::notice::released v$V with $(ls assets | wc -l) assets"
# The npm packages: an @camy/cli launcher plus one platform package per os/arch
# carrying the binary, assembled from the channel's verified tarballs
# (scripts/build-npm.sh) and published with npm trusted publishing, so the
# credential is this workflow's identity and every publish carries
# provenance. Enabled by the repository variable NPM_PUBLISH=true once the
# packages exist on npmjs.com with this workflow as their trusted publisher.
npm:
needs: mirror
if: needs.mirror.outputs.released == 'true' && vars.NPM_PUBLISH == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "22"
registry-url: https://registry.npmjs.org
# Staged publishing (`npm stage publish`) needs npm 11.19 or later.
# Pinned exactly, with lifecycle scripts off: this step runs while the
# job holds the publish identity.
- name: Update npm
run: npm install -g --ignore-scripts npm@11.19.1
- name: Fetch the assets the mirror job verified
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: assets-${{ needs.mirror.outputs.version }}
path: assets/
- name: Build the packages from the verified assets
env:
V: ${{ needs.mirror.outputs.version }}
run: sh scripts/build-npm.sh "$V" "$GITHUB_WORKSPACE/assets"
# The trusted publisher on npmjs.com may stage but not publish directly:
# the five versions land in staging with provenance, and a maintainer
# approves each on npmjs.com (platform packages first, then @camy/cli).
- name: Stage for approval on npmjs.com
run: sh scripts/publish-npm.sh --provenance --stage