-
Notifications
You must be signed in to change notification settings - Fork 322
177 lines (165 loc) · 6.67 KB
/
Copy pathcli-release.yml
File metadata and controls
177 lines (165 loc) · 6.67 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
name: CLI Release
run-name: CLI release for v${{ inputs.version }}
# Builds the standalone `thunderbolt` CLI binaries and attaches them, plus a
# SHA256SUMS manifest, to the shared `v{version}` GitHub Release. The desktop
# app derives download URLs from its own version:
#
# https://github.com/thunderbird/thunderbolt/releases/download/v{APP_VERSION}/thunderbolt-cli-{target}
# https://github.com/thunderbird/thunderbolt/releases/download/v{APP_VERSION}/SHA256SUMS
#
# where {target} is one of: darwin-arm64 | linux-x64 | linux-arm64.
#
# Native-runner matrix (no cross-compile): the CLI depends on @number0/iroh, a
# NAPI addon that ships a per-platform prebuilt `.node`. `bun build --compile`
# embeds only the `.node` that is installed on the build machine, so each target
# MUST build on a runner of its own architecture — `bun install` there pulls the
# matching optional iroh dependency automatically.
#
# darwin-x64 is intentionally absent: iroh 1.0.0 publishes no x86_64-apple-darwin
# addon (`@number0/iroh-darwin-x64` does not exist on npm), so an Intel-macOS CLI
# binary cannot load iroh and is not shipped. Intel-Mac desktop users therefore
# have no one-click CLI install until iroh gains that target upstream.
#
# Publishing (flipping the draft release to public) is owned by the desktop
# release workflow, which shares the `v{version}` tag. This workflow only uploads
# assets via `gh release upload`, which never mutates the release's draft state —
# so it cannot race the desktop publish flip back into draft.
on:
workflow_call:
inputs:
version:
description: 'Version to release (e.g., 1.2.3 without v prefix)'
required: true
type: string
nightly:
description: 'Is this a nightly build?'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.2.3 without v prefix)'
required: true
type: string
nightly:
description: 'Is this a nightly build?'
required: false
default: false
type: boolean
concurrency:
group: cli-release-${{ inputs.version }}
cancel-in-progress: true
permissions:
contents: write
jobs:
ensure-release:
name: Ensure Draft Release
runs-on: ubuntu-24.04
steps:
# For a regular release the draft already exists (version-bump created it).
# For a nightly it is created by the desktop workflow's draft job, which
# runs in parallel — create it here if we win the race, confirm it if we
# lose. Either way the build matrix can upload afterwards.
- name: Ensure the shared draft release exists
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
VERSION: ${{ inputs.version }}
NIGHTLY: ${{ inputs.nightly }}
run: |
if gh release view "v${VERSION}" --repo "$REPO" >/dev/null 2>&1; then
exit 0
fi
FLAGS="--draft"
[ "$NIGHTLY" = "true" ] && FLAGS="$FLAGS --prerelease"
gh release create "v${VERSION}" --repo "$REPO" $FLAGS \
--title "Release v${VERSION}" \
--notes "Release assets are uploaded by CI." \
|| gh release view "v${VERSION}" --repo "$REPO"
build:
name: Build ${{ matrix.target }}
needs: ensure-release
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
target: darwin-arm64
- os: ubuntu-24.04
target: linux-x64
- os: ubuntu-24.04-arm
target: linux-arm64
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: v${{ inputs.version }}
- name: Install Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: 1.3.14
- name: Cache Bun dependencies (cli)
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.bun/install/cache
cli/node_modules
key: cli-bun-${{ matrix.os }}-${{ hashFiles('cli/bun.lock') }}
restore-keys: |
cli-bun-${{ matrix.os }}-
- name: Build CLI binary
env:
THUNDERBOLT_BUILD_CLOUD_URL: ${{ vars.VITE_THUNDERBOLT_CLOUD_URL }}
THUNDERBOLT_BUILD_APP_URL: ${{ vars.THUNDERBOLT_APP_URL }}
run: |
if [ -z "$THUNDERBOLT_BUILD_CLOUD_URL" ]; then
echo "::error::Repository variable VITE_THUNDERBOLT_CLOUD_URL is required"
exit 1
fi
if [ -z "$THUNDERBOLT_BUILD_APP_URL" ]; then
echo "::error::Repository variable THUNDERBOLT_APP_URL is required"
exit 1
fi
cd cli
bun install --frozen-lockfile
bun build --compile --minify \
--target="bun-${{ matrix.target }}" \
--define "process.env.THUNDERBOLT_BUILD_CLOUD_URL=\"$THUNDERBOLT_BUILD_CLOUD_URL\"" \
--define "process.env.THUNDERBOLT_BUILD_APP_URL=\"$THUNDERBOLT_BUILD_APP_URL\"" \
src/index.ts \
--outfile "dist/thunderbolt-cli-${{ matrix.target }}"
# Upload as a workflow artifact rather than straight to the Release, so a
# failed leg can never leave a partial set of binaries on the release with
# no SHA256SUMS. The publish job below attaches everything atomically once
# ALL legs have succeeded.
- name: Upload CLI binary artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: thunderbolt-cli-${{ matrix.target }}
path: cli/dist/thunderbolt-cli-${{ matrix.target }}
if-no-files-found: error
retention-days: 1
publish:
name: Publish CLI assets
# `needs: build` (default success()) gates this on EVERY leg succeeding, so
# publishing is atomic: either all binaries + SHA256SUMS land, or nothing does.
needs: build
runs-on: ubuntu-24.04
steps:
- name: Download all CLI binaries
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: dist
pattern: thunderbolt-cli-*
merge-multiple: true
- name: Generate SHA256SUMS and upload all assets to the release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
VERSION: ${{ inputs.version }}
run: |
cd dist
sha256sum thunderbolt-cli-* > SHA256SUMS
gh release upload "v${VERSION}" thunderbolt-cli-* SHA256SUMS --clobber --repo "$REPO"