-
Notifications
You must be signed in to change notification settings - Fork 8
291 lines (281 loc) · 11.1 KB
/
release.yml
File metadata and controls
291 lines (281 loc) · 11.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
285
286
287
288
289
290
291
name: release
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g. v0.2.0). Must already exist on the ref.'
required: true
permissions:
contents: write
id-token: write
packages: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
NODE_VERSION: '20'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# ---------------------------------------------------------------------
# 🧪 Pre-release gate — don't cut a release if tests are red
# ---------------------------------------------------------------------
gate:
name: 🧪 pre-release gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: Install dependencies
# npm/cli#4828 self-heal (see ci.yml for rationale).
# `shell: bash` so the Windows runner uses Git Bash instead of
# PowerShell — `2>/dev/null`, `||`-grouped fallbacks, and `rm -rf`
# are bash-only and PowerShell mis-parses `/dev/null` as a path.
shell: bash
run: |
npm ci --ignore-scripts || {
echo "::warning::npm ci failed — falling back to npm install (npm/cli#4828)"
rm -rf node_modules package-lock.json
npm install --ignore-scripts --no-audit --no-fund
}
node -e "require('rollup/dist/native.js')" 2>/dev/null || {
echo "::warning::rollup native binding missing — reinstalling (npm/cli#4828)"
rm -rf node_modules package-lock.json
npm install --ignore-scripts --no-audit --no-fund
}
- run: npm rebuild better-sqlite3
- run: npm run build
- run: npx vitest run
# ---------------------------------------------------------------------
# 📦 Platform tarballs — kept as-is, one artefact per target
# ---------------------------------------------------------------------
build-artifacts:
name: 📦 artifacts (${{ matrix.target }})
needs: [gate]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact: forge-linux-x64
target: linux-x64
- os: ubuntu-latest
artifact: forge-linux-arm64
target: linux-arm64
- os: macos-latest
artifact: forge-macos-x64
target: darwin-x64
- os: macos-latest
artifact: forge-macos-arm64
target: darwin-arm64
- os: windows-latest
artifact: forge-windows-x64.exe
target: win32-x64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: Install dependencies
# npm/cli#4828 self-heal (see ci.yml for rationale).
# `shell: bash` so the Windows runner uses Git Bash instead of
# PowerShell — `2>/dev/null`, `||`-grouped fallbacks, and `rm -rf`
# are bash-only and PowerShell mis-parses `/dev/null` as a path.
shell: bash
run: |
npm ci --ignore-scripts || {
echo "::warning::npm ci failed — falling back to npm install (npm/cli#4828)"
rm -rf node_modules package-lock.json
npm install --ignore-scripts --no-audit --no-fund
}
node -e "require('rollup/dist/native.js')" 2>/dev/null || {
echo "::warning::rollup native binding missing — reinstalling (npm/cli#4828)"
rm -rf node_modules package-lock.json
npm install --ignore-scripts --no-audit --no-fund
}
- run: npm rebuild better-sqlite3
- run: npm run build
- run: npm pack
- name: Upload tarball
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: forge-cli-*.tgz
# ---------------------------------------------------------------------
# 🐳 Multi-arch Docker image → GitHub Container Registry
# ---------------------------------------------------------------------
docker:
name: 🐳 docker publish
needs: [gate]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=sha,format=short
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build + push
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
FORGE_VERSION=${{ github.ref_name }}
FORGE_COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.repository.updated_at }}
- name: Image summary
run: |
echo "## 🐳 Image published" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Tags:" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo "${{ steps.meta.outputs.tags }}" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
# ---------------------------------------------------------------------
# 📝 Signed manifest + GitHub Release — aggregates the tarballs
# ---------------------------------------------------------------------
manifest:
name: 📝 manifest + gh-release
needs: [build-artifacts]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { path: artifacts }
- name: Build manifest.json
run: |
set -eu
cat > manifest.json <<EOF
{
"version": "${GITHUB_REF_NAME#v}",
"channel": "stable",
"releasedAt": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"artifacts": [
$(find artifacts -type f | awk 'BEGIN{ORS=""} NR>1{print ","} { name=$0; gsub(".*/","",name); "shasum -a 256 " $0 " | awk {print $1}" | getline sha; "wc -c < " $0 | getline size; printf(" {\"name\":\"%s\",\"sha256\":\"%s\",\"size\":%s}", name, sha, size+0); close("shasum -a 256 " $0) }')
]
}
EOF
cat manifest.json
- name: Sign manifest (ed25519)
env:
ED25519_KEY: ${{ secrets.FORGE_RELEASE_ED25519_PRIV }}
if: env.ED25519_KEY != ''
run: |
printf '%s' "$ED25519_KEY" > /tmp/ed25519.key
openssl pkeyutl -sign -inkey /tmp/ed25519.key -rawin -in manifest.json -out manifest.sig.bin
base64 -w0 manifest.sig.bin > manifest.sig
- uses: softprops/action-gh-release@v2
with:
files: |
artifacts/**/*
manifest.json
manifest.sig
generate_release_notes: true
# ---------------------------------------------------------------------
# 📤 npm publish (with provenance)
# ---------------------------------------------------------------------
publish-npm:
name: 📤 npm publish
needs: [manifest]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: https://registry.npmjs.org
cache: npm
- name: Install dependencies
# npm/cli#4828 self-heal (see ci.yml for rationale).
# `shell: bash` so the Windows runner uses Git Bash instead of
# PowerShell — `2>/dev/null`, `||`-grouped fallbacks, and `rm -rf`
# are bash-only and PowerShell mis-parses `/dev/null` as a path.
shell: bash
run: |
npm ci --ignore-scripts || {
echo "::warning::npm ci failed — falling back to npm install (npm/cli#4828)"
rm -rf node_modules package-lock.json
npm install --ignore-scripts --no-audit --no-fund
}
node -e "require('rollup/dist/native.js')" 2>/dev/null || {
echo "::warning::rollup native binding missing — reinstalling (npm/cli#4828)"
rm -rf node_modules package-lock.json
npm install --ignore-scripts --no-audit --no-fund
}
- run: npm rebuild better-sqlite3
- run: npm run build
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ---------------------------------------------------------------------
# 📊 Release status — final job, always runs, writes summary
# ---------------------------------------------------------------------
release-status:
name: 📊 release status
if: always()
runs-on: ubuntu-latest
needs: [gate, build-artifacts, docker, manifest, publish-npm]
steps:
- name: Write release summary
env:
GATE_R: ${{ needs.gate.result }}
ARTIF_R: ${{ needs.build-artifacts.result }}
DOCKER_R: ${{ needs.docker.result }}
MANIFEST_R: ${{ needs.manifest.result }}
NPM_R: ${{ needs.publish-npm.result }}
run: |
set -eu
icon() {
case "$1" in
success) echo "✅" ;;
failure) echo "❌" ;;
cancelled) echo "⏹️" ;;
skipped) echo "⏭️" ;;
*) echo "❔" ;;
esac
}
{
echo "# 🚀 Forge release — ${GITHUB_REF_NAME}"
echo ""
echo "| Stage | Result |"
echo "|-------|--------|"
printf "| 🧪 pre-release gate | %s \`%s\` |\n" "$(icon "$GATE_R")" "$GATE_R"
printf "| 📦 artifacts | %s \`%s\` |\n" "$(icon "$ARTIF_R")" "$ARTIF_R"
printf "| 🐳 docker publish | %s \`%s\` |\n" "$(icon "$DOCKER_R")" "$DOCKER_R"
printf "| 📝 manifest + GH | %s \`%s\` |\n" "$(icon "$MANIFEST_R")" "$MANIFEST_R"
printf "| 📤 npm publish | %s \`%s\` |\n" "$(icon "$NPM_R")" "$NPM_R"
echo ""
echo "> Tag: \`${GITHUB_REF_NAME}\` · SHA: \`${GITHUB_SHA:0:7}\` · [Run ${GITHUB_RUN_NUMBER}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})"
} >> "$GITHUB_STEP_SUMMARY"