Repository navigation
365 lines (317 loc) · 11.9 KB
/
Copy pathrelease-cli.yml
File metadata and controls
365 lines (317 loc) · 11.9 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
name: Release CLI
on:
push:
branches:
- main
workflow_dispatch:
inputs:
cli_version:
description: Current CLI version on main to release or republish
required: true
type: string
force_republish:
description: Allow replacing assets on an existing GitHub release
required: false
default: false
type: boolean
permissions:
contents: write
pull-requests: write
concurrency:
group: release-cli-${{ github.ref }}
cancel-in-progress: false
jobs:
plan-release:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
outputs:
should_release: ${{ steps.plan.outputs.should_release }}
cli_version: ${{ steps.plan.outputs.cli_version }}
cli_tag: ${{ steps.plan.outputs.cli_tag }}
force_republish: ${{ steps.plan.outputs.force_republish }}
release_ref: ${{ steps.plan.outputs.release_ref }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.10
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Sync CLI release PR
id: changesets
if: github.event_name == 'push'
uses: changesets/action@v1
with:
version: bun run release:cli:version
commit: "release: cli"
title: "release: cli"
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Detect CLI release plan
id: plan
shell: bash
run: |
event_name="${GITHUB_EVENT_NAME}"
has_changesets="${{ steps.changesets.outputs.hasChangesets }}"
requested_version="${{ inputs.cli_version }}"
force_republish="${{ inputs.force_republish && 'true' || 'false' }}"
cli_version=$(bun -e "console.log(JSON.parse(await Bun.file('./apps/cli/package.json').text()).version)")
cli_tag="cli-v${cli_version}"
should_release=false
release_ref="${GITHUB_SHA}"
tag_exists=false
if git ls-remote --exit-code --tags origin "refs/tags/${cli_tag}" >/dev/null 2>&1; then
tag_exists=true
fi
if [[ "${event_name}" == "push" ]]; then
if [[ "${has_changesets}" == "false" ]]; then
package_changed=false
if git rev-parse HEAD^ >/dev/null 2>&1; then
if ! git diff --quiet HEAD^ HEAD -- apps/cli/package.json; then
package_changed=true
fi
fi
if [[ "$package_changed" == "true" && "$tag_exists" == "false" ]]; then
should_release=true
fi
fi
elif [[ "${event_name}" == "workflow_dispatch" ]]; then
if [[ "${GITHUB_REF}" != "refs/heads/main" ]]; then
echo "Manual releases only support rerunning the current CLI version from the main branch." >&2
exit 1
fi
if [[ -z "${requested_version}" ]]; then
echo "cli_version input is required." >&2
exit 1
fi
if [[ "${requested_version}" != "${cli_version}" ]]; then
echo "Requested version ${requested_version} does not match the current CLI version on main (${cli_version})." >&2
exit 1
fi
should_release=true
if [[ "${tag_exists}" == "true" ]]; then
release_ref="${cli_tag}"
fi
else
echo "Unsupported event ${event_name}." >&2
exit 1
fi
echo "cli_version=${cli_version}" >> "$GITHUB_OUTPUT"
echo "cli_tag=${cli_tag}" >> "$GITHUB_OUTPUT"
echo "should_release=${should_release}" >> "$GITHUB_OUTPUT"
echo "force_republish=${force_republish}" >> "$GITHUB_OUTPUT"
echo "release_ref=${release_ref}" >> "$GITHUB_OUTPUT"
verify:
needs: plan-release
if: needs.plan-release.outputs.should_release == 'true'
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.plan-release.outputs.release_ref }}
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.10
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Test
run: bun run test
- name: Verify version in tag output
run: |
package_version=$(bun -e "console.log(JSON.parse(await Bun.file('./apps/cli/package.json').text()).version)")
if [[ "${package_version}" != "${{ needs.plan-release.outputs.cli_version }}" ]]; then
echo "CLI version mismatch between planning job and workspace." >&2
exit 1
fi
build:
needs:
- plan-release
- verify
if: needs.plan-release.outputs.should_release == 'true'
strategy:
fail-fast: false
matrix:
include:
- runner: macos-15
target: darwin-arm64
artifact_dir: darwin-arm64
- runner: macos-15-intel
target: darwin-x64
artifact_dir: darwin-x64
- runner: ubuntu-latest
target: linux-x64
artifact_dir: linux-x64
- runner: windows-latest
target: windows-x64
artifact_dir: windows-x64
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.plan-release.outputs.release_ref }}
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.10
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build CLI release binary
env:
SYNCDOWN_TARGET_PLATFORM: ${{ matrix.target }}
run: bun run release:cli:binary:local
- name: Smoke test CLI release binary
run: bun run release:cli:binary:smoke
- name: Upload CLI release asset
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_dir }}
path: |
artifacts/release/${{ matrix.artifact_dir }}/*.tar.gz
artifacts/release/${{ matrix.artifact_dir }}/*.zip
if-no-files-found: error
publish-release:
needs:
- plan-release
- build
if: needs.plan-release.outputs.should_release == 'true'
runs-on: ubuntu-latest
env:
CLI_TAG: ${{ needs.plan-release.outputs.cli_tag }}
CLI_VERSION: ${{ needs.plan-release.outputs.cli_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.plan-release.outputs.release_ref }}
fetch-depth: 0
- name: Create CLI tag
run: |
if git ls-remote --exit-code --tags origin "refs/tags/${CLI_TAG}" >/dev/null 2>&1; then
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "${CLI_TAG}" "${GITHUB_SHA}"
git push origin "refs/tags/${CLI_TAG}"
- name: Inspect existing GitHub release
id: inspect_release
uses: actions/github-script@v7
with:
script: |
try {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: process.env.CLI_TAG,
});
core.setOutput("exists", "true");
core.setOutput("id", String(release.data.id));
core.setOutput("asset_count", String(release.data.assets.length));
} catch (error) {
if (error.status === 404) {
core.setOutput("exists", "false");
core.setOutput("id", "");
core.setOutput("asset_count", "0");
return;
}
throw error;
}
- name: Guard against accidental republish
if: steps.inspect_release.outputs.exists == 'true' && needs.plan-release.outputs.force_republish != 'true'
shell: bash
run: |
echo "GitHub release ${CLI_TAG} already exists. Re-run workflow_dispatch with force_republish=true to replace assets." >&2
exit 1
- name: Delete existing release assets
if: steps.inspect_release.outputs.exists == 'true' && needs.plan-release.outputs.force_republish == 'true'
uses: actions/github-script@v7
with:
script: |
const releaseId = Number("${{ steps.inspect_release.outputs.id }}");
const { data: assets } = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
per_page: 100,
});
for (const asset of assets) {
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: asset.id,
});
}
- name: Download CLI release assets
uses: actions/download-artifact@v4
with:
path: artifacts/release-assets
- name: Build CLI checksum manifest
run: |
mkdir -p artifacts/release-assets/final
find artifacts/release-assets -type f \( -name '*.tar.gz' -o -name '*.zip' \) -print0 \
| sort -z \
| xargs -0 sha256sum \
| sed 's#artifacts/release-assets/[^/]*/##' \
> "artifacts/release-assets/final/syncdown-${CLI_TAG}-SHA256SUMS.txt"
- name: Read CLI changelog entry
id: changelog
env:
CHANGELOG_PATH: apps/cli/CHANGELOG.md
run: |
node <<'EOF'
const fs = require("node:fs");
const changelogPath = process.env.CHANGELOG_PATH;
const cliVersion = process.env.CLI_VERSION;
const githubOutput = process.env.GITHUB_OUTPUT;
if (!changelogPath || !cliVersion || !githubOutput) {
throw new Error("Missing required environment for changelog extraction.");
}
if (!fs.existsSync(changelogPath)) {
throw new Error(`Expected changelog at ${changelogPath}, but it does not exist.`);
}
const changelog = fs.readFileSync(changelogPath, "utf8");
const escapedVersion = cliVersion.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const sectionPattern = new RegExp(
`^##\\s+\\[?${escapedVersion}\\]?[^\\r\\n]*\\r?\\n([\\s\\S]*?)(?=^##\\s+|(?![\\s\\S]))`,
"m",
);
const match = changelog.match(sectionPattern);
if (!match) {
throw new Error(
`Could not find changelog section for version ${cliVersion} in ${changelogPath}.`,
);
}
const releaseNotes = match[1].trim();
if (!releaseNotes) {
throw new Error(
`Changelog section for version ${cliVersion} in ${changelogPath} is empty.`,
);
}
fs.appendFileSync(githubOutput, `release_notes<<__CHANGELOG__\n${releaseNotes}\n__CHANGELOG__\n`);
EOF
- name: Publish CLI GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.CLI_TAG }}
name: CLI v${{ env.CLI_VERSION }}
body: ${{ steps.changelog.outputs.release_notes }}
overwrite_files: true
files: |
artifacts/release-assets/**/*.tar.gz
artifacts/release-assets/**/*.zip
artifacts/release-assets/final/syncdown-${{ env.CLI_TAG }}-SHA256SUMS.txt