Repository navigation
270 lines (261 loc) · 10 KB
/
Copy pathrelease.yml
File metadata and controls
270 lines (261 loc) · 10 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
name: Release
on:
pull_request:
branches: [main]
types: [closed]
workflow_dispatch:
inputs:
source_commit:
description: Exact main commit to release when retrying the current unpublished version
required: false
type: string
concurrency:
group: magnitude-production-release
cancel-in-progress: false
permissions:
contents: write
pull-requests: read
env:
BUN_VERSION: "1.3.14"
RUST_VERSION: "1.91.1"
NPM_VERSION: "11.6.2"
jobs:
preflight:
if: >-
github.event_name == 'workflow_dispatch' ||
(
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'changeset-release/main' &&
github.event.pull_request.head.repo.full_name == github.repository
)
runs-on: ubuntu-latest
outputs:
action: ${{ steps.preflight.outputs.action }}
version: ${{ steps.preflight.outputs.version }}
source_commit: ${{ steps.source.outputs.commit }}
release_commit: ${{ steps.source.outputs.release_commit }}
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Resolve the Changesets release commit
id: source
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT_COMMIT: ${{ github.event_name == 'pull_request' && github.sha || '' }}
SOURCE_COMMIT_OVERRIDE: ${{ github.event_name == 'workflow_dispatch' && inputs.source_commit || '' }}
run: |
release_commit="$EVENT_COMMIT"
if [ -z "$release_commit" ]; then
test "$GITHUB_REF" = "refs/heads/main"
owner="${GITHUB_REPOSITORY%%/*}"
release_commit="$(
gh pr list \
--repo "$GITHUB_REPOSITORY" \
--state merged \
--base main \
--head changeset-release/main \
--limit 100 \
--json headRepositoryOwner,mergeCommit,mergedAt |
jq -r \
--arg owner "$owner" \
'map(select(.headRepositoryOwner.login == $owner)) |
sort_by(.mergedAt) | last | .mergeCommit.oid // empty'
)"
test -n "$release_commit"
current_version="$(jq -r '.version // empty' packages/launcher/package.json)"
release_version="$(
git show "${release_commit}:packages/launcher/package.json" |
jq -r '.version // empty'
)"
test -n "$current_version"
test "$release_version" = "$current_version"
fi
commit="${SOURCE_COMMIT_OVERRIDE:-$release_commit}"
[[ "$release_commit" =~ ^[a-f0-9]{40}$ ]]
[[ "$commit" =~ ^[a-f0-9]{40}$ ]]
git merge-base --is-ancestor "$release_commit" "$commit"
git merge-base --is-ancestor "$commit" origin/main
source_version="$(
git show "${commit}:packages/launcher/package.json" |
jq -r '.version // empty'
)"
test -n "$source_version"
test "$source_version" = "$(
git show "${release_commit}:packages/launcher/package.json" |
jq -r '.version // empty'
)"
echo "commit=$commit" >> "$GITHUB_OUTPUT"
echo "release_commit=$release_commit" >> "$GITHUB_OUTPUT"
- name: Validate the release commit
shell: bash
env:
RELEASE_COMMIT: ${{ steps.source.outputs.commit }}
run: |
test "${{ github.ref }}" = "refs/heads/main"
[[ "$RELEASE_COMMIT" =~ ^[a-f0-9]{40}$ ]]
git fetch origin main
git merge-base --is-ancestor "$RELEASE_COMMIT" origin/main
- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: bun install --frozen-lockfile
- id: preflight
run: bun run packages/release/scripts/preflight.ts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAGNITUDE_RELEASE_COMMIT: ${{ steps.source.outputs.release_commit }}
MAGNITUDE_SOURCE_COMMIT: ${{ steps.source.outputs.commit }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Validate the preflight action
shell: bash
env:
ACTION: ${{ steps.preflight.outputs.action }}
run: |
case "$ACTION" in
release|publish-npm|complete) ;;
*) echo "::error::Invalid preflight action: '${ACTION}'"; exit 1 ;;
esac
build:
needs: preflight
if: needs.preflight.outputs.action == 'release'
uses: ./.github/workflows/release-build.yml
with:
source_commit: ${{ needs.preflight.outputs.source_commit }}
validate_candidate: false
publish:
needs: [preflight, build]
if: needs.preflight.outputs.action == 'release'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.preflight.outputs.source_commit }}
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: bun install --frozen-lockfile
- run: sudo apt-get update && sudo apt-get install -y binutils
- uses: actions/download-artifact@v4
with:
pattern: host-*
path: release-artifacts
- uses: actions/download-artifact@v4
with:
pattern: backend-*
path: release-artifacts
- run: npm install --global "npm@${NPM_VERSION}"
- run: bun scripts/prepare-integrations.ts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: npm-candidate
run: bun run packages/release/scripts/prepare-npm.ts release/npm-candidate
- run: bun run packages/release/scripts/assemble.ts release-artifacts release-candidate
env:
MAGNITUDE_RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
MAGNITUDE_SOURCE_COMMIT: ${{ needs.preflight.outputs.source_commit }}
- run: bun run scripts/accept-release-candidate.ts release-candidate "${{ steps.npm-candidate.outputs.tarball }}" release/integration-candidate
- name: Commit-point recheck
run: bun run packages/release/scripts/preflight.ts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAGNITUDE_RELEASE_COMMIT: ${{ needs.preflight.outputs.release_commit }}
MAGNITUDE_RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
MAGNITUDE_SOURCE_COMMIT: ${{ needs.preflight.outputs.source_commit }}
MAGNITUDE_REQUIRE_RELEASE: "true"
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: bun scripts/accept-integrations.ts
- uses: actions/upload-artifact@v4
with:
name: accepted-integrations
path: release/integration-candidate
if-no-files-found: ignore
overwrite: true
- run: bun scripts/publish-integrations.ts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: bun run packages/release/scripts/publish.ts release-candidate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAGNITUDE_SOURCE_COMMIT: ${{ needs.preflight.outputs.source_commit }}
- name: Verify public CLI acquisition
run: bun run packages/release/scripts/accept-public-cli.ts "${{ steps.npm-candidate.outputs.tarball }}"
env:
MAGNITUDE_RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
- name: Publish accepted CLI tarball
run: bun run publish "${{ steps.npm-candidate.outputs.tarball }}"
env:
MAGNITUDE_RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
MAGNITUDE_EXPECTED_NPM_INTEGRITY: ${{ steps.npm-candidate.outputs.integrity }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
public-smoke:
needs: [preflight, publish]
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- shell: bash
run: |
npm install --global "@magnitudedev/cli@${{ needs.preflight.outputs.version }}"
magnitude --version
# The CLI is already public: this Version PR changed only plugins, or is a retry after
# a complete CLI release. Plugins publish on their own; unchanged ones verify as no-ops.
publish-integrations:
needs: preflight
if: needs.preflight.outputs.action == 'complete'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.preflight.outputs.source_commit }}
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: bun install --frozen-lockfile
- run: npm install --global "npm@${NPM_VERSION}"
- run: bun run --cwd integrations/pi typecheck
- run: bun run --cwd integrations/pi test
- run: bun scripts/prepare-integrations.ts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: bun scripts/accept-integrations.ts
- uses: actions/upload-artifact@v4
with:
name: accepted-integrations
path: release/integration-candidate
if-no-files-found: ignore
overwrite: true
- run: bun scripts/publish-integrations.ts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm:
needs: preflight
if: needs.preflight.outputs.action == 'publish-npm'
uses: ./.github/workflows/publish-npm.yml
with:
version: ${{ needs.preflight.outputs.version }}
within_release: true
secrets: inherit