-
Notifications
You must be signed in to change notification settings - Fork 0
367 lines (315 loc) · 11.9 KB
/
distribute.yml
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
366
367
name: 🚚 » Build and Distribute Release
permissions:
"contents": "write"
on:
push:
tags:
- '**[0-9]+.[0-9]+.[0-9]+*'
jobs:
build-ui:
name: 📲 » Build UI
runs-on: ubuntu-latest
steps:
- name: 🛎️ » Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: 🫓 » Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.18
- name: 📦 » Install dependencies with bun
working-directory: ./ui
run: |
bun install --frozen-lockfile
- name: 🛠️ » Build
working-directory: ./ui
run: bun vite build
# upload ui/dist to artifacts so that we can download it in the next steps
- name: 📤» Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ui-dist-${{ github.sha }}
path: ./ui/dist
plan:
name: 📋 » Create distribution plan
runs-on: "ubuntu-20.04"
needs:
- build-ui
outputs:
val: ${{ steps.plan.outputs.manifest }}
tag: ${{ github.ref_name || '' }}
tag-flag: ${{ format('--tag={0}', github.ref_name) || '' }}
publishing: 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: 🛎️ » Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive
- name: 🚚 » Install cargo-dist
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.19.1/cargo-dist-installer.sh | sh"
- name: 💾 » Cache cargo-dist
uses: actions/upload-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/cargo-dist
- name: 📋 » Create distribution plan
id: plan
working-directory: ./server
run: |
cargo dist plan --output-format=json > plan-dist-manifest.json
echo "cargo dist ran successfully"
cat plan-dist-manifest.json
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
- name: 📤 » Upload plan-dist-manifest.json artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-plan-dist-manifest
path: ./server/plan-dist-manifest.json
build-local-artifacts:
# Builds and packages all the platform-specific things
name: 🔨 » Build Local Artifcats (${{ join(matrix.targets, ', ') }})
needs:
- plan
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
strategy:
fail-fast: false
# Target platforms/runners are computed by cargo-dist in create-release.
# Each member of the matrix has the following arguments:
#
# - runner: the github runner
# - dist-args: cli flags to pass to cargo dist
# - install-dist: expression to run to install cargo-dist on the runner
#
# Typically there will be:
# - 1 "global" task that builds universal installers
# - N "local" tasks that build each platform's binaries and platform-specific installers
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
runs-on: ${{ matrix.runner }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
steps:
- name: 🔧 » Enable windows longpaths
run: |
git config --global core.longpaths true
- name: 🛎️ » Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive
# download the ui/dist artifacts so that we don't have to rebuild the UI for each platform
- name: 📥 » Download UI artifacts
uses: actions/download-artifact@v4
with:
name: ui-dist-${{ github.sha }}
path: ./ui/dist
- name: 🚚 » Install cargo-dist
run: ${{ matrix.install_dist }}
- name: 📥 » Fetch local artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: ./server/target/distrib/
merge-multiple: true
- name: 📦 » Install dependencies
working-directory: ./server
run: |
${{ matrix.packages_install }}
- name: 🏗️ » Build artifacts
working-directory: ./server
run: |
# Actually do builds and make zips and whatnot
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "cargo dist ran successfully"
- id: cargo-dist
name: ⏩ » Post-build
working-directory: ./server
shell: bash
run: |
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
- name: 🧾 » Log paths
run: |
echo "paths: ${{ steps.cargo-dist.outputs.paths }}"
echo "manifest: ${{ env.BUILD_MANIFEST_NAME }}"
- name: 📤 » Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
path: |
${{ steps.cargo-dist.outputs.paths }}
${{ env.BUILD_MANIFEST_NAME }}
# Build and package all the platform-agnostic(ish) things
build-global-artifacts:
name: 🏗️ » Build Global Artifacts
needs:
- plan
- build-local-artifacts
runs-on: "ubuntu-20.04"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_MANIFEST_NAME: ./target/distrib/global-dist-manifest.json
steps:
- name: 🛎️ » Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive
- name: 🚚 » Install cached cargo-dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- name: 🛠️ » Make cargo-dist executable
run: chmod +x ~/.cargo/bin/cargo-dist
- name: 📥 » Download local artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: ./server/target/distrib/
merge-multiple: true
- name: 🏗️ » Build artifacts
id: cargo-dist
working-directory: ./server
shell: bash
run: |
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
echo "cargo dist ran successfully"
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "copying dist-manifest.json to:"
echo $BUILD_MANIFEST_NAME
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
- name: 📤 » Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-build-global
path: |
${{ steps.cargo-dist.outputs.paths }}
${{ env.BUILD_MANIFEST_NAME }}
# Determines if we should publish/announce
host:
name: 🏠 » Host distribution
needs:
- plan
- build-local-artifacts
- build-global-artifacts
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: "ubuntu-20.04"
outputs:
val: ${{ steps.host.outputs.manifest }}
steps:
- name: 🛎️ » Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive
- name: 🚚 » Install cached cargo-dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/cargo-dist
# Fetch artifacts from scratch-storage
- name: 📥 » Download artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: ./server/target/distrib/
merge-multiple: true
- id: host
name: 🏠 » Cargo dist host
working-directory: ./server
shell: bash
run: |
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
echo "artifacts uploaded and released successfully"
cat dist-manifest.json
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
- name: 📤 » Upload dist-manifest.json
uses: actions/upload-artifact@v4
with:
# Overwrite the previous copy
name: artifacts-dist-manifest
path: ./server/dist-manifest.json
publish-npm:
name: 📦 » Publish NPM packages
needs:
- plan
- host
runs-on: "ubuntu-20.04"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PLAN: ${{ needs.plan.outputs.val }}
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
steps:
- name: 📥 » Download artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: npm/
merge-multiple: true
- name: 🌳 » Log File Tree
run: |
tree -a -L 10
- name: 🟢 » Setup node js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: 📦 » Publish NPM packages
run: |
for release in $(echo "$PLAN" | jq --compact-output '.releases[] | select([.artifacts[] | endswith("-npm-package.tar.gz")] | any)'); do
pkg=$(echo "$release" | jq '.artifacts[] | select(endswith("-npm-package.tar.gz"))' --raw-output)
echo "Publishing $pkg"
npm publish --access public "./npm/server/target/distrib/${pkg}"
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
announce:
name: 📢 » Announce release
needs:
- plan
- host
- publish-npm
# use "always() && ..." to allow us to wait for all publish jobs while
# still allowing individual publish jobs to skip themselves (for prereleases).
# "host" however must run to completion, no skipping allowed!
if: ${{ always() && needs.host.result == 'success' }}
runs-on: "ubuntu-20.04"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: "Download GitHub Artifacts"
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: artifacts
merge-multiple: true
- name: Cleanup
run: |
# Remove the granular manifests
rm -f artifacts/*-dist-manifest.json
- name: 🌳 » Log File Tree
run: |
tree -a -L 10
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.plan.outputs.tag }}
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
artifacts: "artifacts/server/target/distrib/*"