1
- # Copyright 2022-2023 , axodotdev
1
+ # Copyright 2022-2024 , axodotdev
2
2
# SPDX-License-Identifier: MIT or Apache-2.0
3
3
#
4
4
# CI that:
5
5
#
6
6
# * checks for a Git Tag that looks like a release
7
7
# * builds artifacts with cargo-dist (archives, installers, hashes)
8
8
# * uploads those artifacts to temporary workflow zip
9
- # * on success, uploads the artifacts to a Github Release™
9
+ # * on success, uploads the artifacts to a GitHub Release
10
10
#
11
- # Note that the Github Release™ will be created with a generated
11
+ # Note that the GitHub Release will be created with a generated
12
12
# title/body based on your changelogs.
13
+
13
14
name : Release
14
15
15
16
permissions :
@@ -21,20 +22,20 @@ permissions:
21
22
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
22
23
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
23
24
#
24
- # If PACKAGE_NAME is specified, then the release will be for that
25
+ # If PACKAGE_NAME is specified, then the announcement will be for that
25
26
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
26
27
#
27
- # If PACKAGE_NAME isn't specified, then the release will be for all
28
+ # If PACKAGE_NAME isn't specified, then the announcement will be for all
28
29
# (cargo-dist-able) packages in the workspace with that version (this mode is
29
30
# intended for workspaces with only one dist-able package, or with all dist-able
30
31
# packages versioned/released in lockstep).
31
32
#
32
33
# If you push multiple tags at once, separate instances of this workflow will
33
- # spin up, creating an independent Github Release™ for each one. However Github
34
+ # spin up, creating an independent announcement for each one. However, GitHub
34
35
# will hard limit this to 3 tags per commit, as it will assume more tags is a
35
36
# mistake.
36
37
#
37
- # If there's a prerelease-style suffix to the version, then the Github Release™
38
+ # If there's a prerelease-style suffix to the version, then the release(s)
38
39
# will be marked as a prerelease.
39
40
on :
40
41
push :
43
44
pull_request :
44
45
45
46
jobs :
46
- # Run 'cargo dist plan' to determine what tasks we need to do
47
+ # Run 'cargo dist plan' (or host) to determine what tasks we need to do
47
48
plan :
48
49
runs-on : ubuntu-latest
49
50
outputs :
@@ -58,24 +59,34 @@ jobs:
58
59
with :
59
60
submodules : recursive
60
61
- name : Install cargo-dist
61
- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.2/cargo-dist-installer.sh | sh"
62
+ # we specify bash to get pipefail; it guards against the `curl` command
63
+ # failing. otherwise `sh` won't catch that `curl` returned non-0
64
+ shell : bash
65
+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.1/cargo-dist-installer.sh | sh"
66
+ # sure would be cool if github gave us proper conditionals...
67
+ # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
68
+ # functionality based on whether this is a pull_request, and whether it's from a fork.
69
+ # (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
70
+ # but also really annoying to build CI around when it needs secrets to work right.)
62
71
- id : plan
63
72
run : |
64
- cargo dist plan ${{ !github.event.pull_request && format('-- tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json
65
- echo "cargo dist plan ran successfully"
66
- cat dist-manifest.json
67
- echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
73
+ cargo dist ${{ ( !github.event.pull_request && format('host --steps=create -- tag={0}', github.ref_name)) || 'plan ' }} --output-format=json > plan- dist-manifest.json
74
+ echo "cargo dist ran successfully"
75
+ cat plan- dist-manifest.json
76
+ echo "manifest=$(jq -c "." plan- dist-manifest.json)" >> "$GITHUB_OUTPUT"
68
77
- name : " Upload dist-manifest.json"
69
- uses : actions/upload-artifact@v3
78
+ uses : actions/upload-artifact@v4
70
79
with :
71
- name : artifacts
72
- path : dist-manifest.json
80
+ name : artifacts-plan-dist-manifest
81
+ path : plan- dist-manifest.json
73
82
74
83
# Build and packages all the platform-specific things
75
- upload-local-artifacts :
84
+ build-local-artifacts :
85
+ name : build-local-artifacts (${{ join(matrix.targets, ', ') }})
76
86
# Let the initial task tell us to not run (currently very blunt)
77
- needs : plan
78
- if : ${{ fromJson(needs.plan.outputs.val).releases != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
87
+ needs :
88
+ - plan
89
+ 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') }}
79
90
strategy :
80
91
fail-fast : false
81
92
# Target platforms/runners are computed by cargo-dist in create-release.
@@ -98,8 +109,17 @@ jobs:
98
109
with :
99
110
submodules : recursive
100
111
- uses : swatinem/rust-cache@v2
112
+ with :
113
+ key : ${{ join(matrix.targets, '-') }}
101
114
- name : Install cargo-dist
102
115
run : ${{ matrix.install_dist }}
116
+ # Get the dist-manifest
117
+ - name : Fetch local artifacts
118
+ uses : actions/download-artifact@v4
119
+ with :
120
+ pattern : artifacts-*
121
+ path : target/distrib/
122
+ merge-multiple : true
103
123
- name : Install dependencies
104
124
run : |
105
125
${{ matrix.packages_install }}
@@ -115,54 +135,134 @@ jobs:
115
135
# inconsistent syntax between shell and powershell.
116
136
shell : bash
117
137
run : |
118
- # Parse out what we just built and upload it to the Github Release™
138
+ # Parse out what we just built and upload it to scratch storage
119
139
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
120
- jq --raw-output ".artifacts[]?.path | select( . != null ) " dist-manifest.json >> "$GITHUB_OUTPUT"
140
+ jq --raw-output ".upload_files[] " dist-manifest.json >> "$GITHUB_OUTPUT"
121
141
echo "EOF" >> "$GITHUB_OUTPUT"
122
142
123
143
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
124
144
- name : " Upload artifacts"
125
- uses : actions/upload-artifact@v3
145
+ uses : actions/upload-artifact@v4
126
146
with :
127
- name : artifacts
147
+ name : artifacts-build-local-${{ join(matrix.targets, '_') }}
128
148
path : |
129
149
${{ steps.cargo-dist.outputs.paths }}
130
150
${{ env.BUILD_MANIFEST_NAME }}
131
151
132
- should-publish :
152
+ # Build and package all the platform-agnostic(ish) things
153
+ build-global-artifacts :
133
154
needs :
134
155
- plan
135
- - upload-local-artifacts
136
- if : ${{ needs.plan.outputs.publishing == 'true' }}
137
- runs-on : ubuntu-latest
156
+ - build-local-artifacts
157
+ runs-on : " ubuntu-20.04"
158
+ env :
159
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
160
+ BUILD_MANIFEST_NAME : target/distrib/global-dist-manifest.json
138
161
steps :
139
- - name : print tag
140
- run : echo "ok we're publishing!"
162
+ - uses : actions/checkout@v4
163
+ with :
164
+ submodules : recursive
165
+ - name : Install cargo-dist
166
+ shell : bash
167
+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.1/cargo-dist-installer.sh | sh"
168
+ # Get all the local artifacts for the global tasks to use (for e.g. checksums)
169
+ - name : Fetch local artifacts
170
+ uses : actions/download-artifact@v4
171
+ with :
172
+ pattern : artifacts-*
173
+ path : target/distrib/
174
+ merge-multiple : true
175
+ - id : cargo-dist
176
+ shell : bash
177
+ run : |
178
+ cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
179
+ echo "cargo dist ran successfully"
141
180
142
- # Create a Github Release with all the results once everything is done
143
- publish-release :
144
- needs : [plan, should-publish]
145
- runs-on : ubuntu-latest
181
+ # Parse out what we just built and upload it to scratch storage
182
+ echo "paths<<EOF" >> "$GITHUB_OUTPUT"
183
+ jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
184
+ echo "EOF" >> "$GITHUB_OUTPUT"
185
+
186
+ cp dist-manifest.json "$BUILD_MANIFEST_NAME"
187
+ - name : " Upload artifacts"
188
+ uses : actions/upload-artifact@v4
189
+ with :
190
+ name : artifacts-build-global
191
+ path : |
192
+ ${{ steps.cargo-dist.outputs.paths }}
193
+ ${{ env.BUILD_MANIFEST_NAME }}
194
+ # Determines if we should publish/announce
195
+ host :
196
+ needs :
197
+ - plan
198
+ - build-local-artifacts
199
+ - build-global-artifacts
200
+ # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
201
+ 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') }}
202
+ env :
203
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
204
+ runs-on : " ubuntu-20.04"
205
+ outputs :
206
+ val : ${{ steps.host.outputs.manifest }}
207
+ steps :
208
+ - uses : actions/checkout@v4
209
+ with :
210
+ submodules : recursive
211
+ - name : Install cargo-dist
212
+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.1/cargo-dist-installer.sh | sh"
213
+ # Fetch artifacts from scratch-storage
214
+ - name : Fetch artifacts
215
+ uses : actions/download-artifact@v4
216
+ with :
217
+ pattern : artifacts-*
218
+ path : target/distrib/
219
+ merge-multiple : true
220
+ # This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
221
+ - id : host
222
+ shell : bash
223
+ run : |
224
+ cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
225
+ echo "artifacts uploaded and released successfully"
226
+ cat dist-manifest.json
227
+ echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
228
+ - name : " Upload dist-manifest.json"
229
+ uses : actions/upload-artifact@v4
230
+ with :
231
+ # Overwrite the previous copy
232
+ name : artifacts-dist-manifest
233
+ path : dist-manifest.json
234
+
235
+ # Create a GitHub Release while uploading all files to it
236
+ announce :
237
+ needs :
238
+ - plan
239
+ - host
240
+ # use "always() && ..." to allow us to wait for all publish jobs while
241
+ # still allowing individual publish jobs to skip themselves (for prereleases).
242
+ # "host" however must run to completion, no skipping allowed!
243
+ if : ${{ always() && needs.host.result == 'success' }}
244
+ runs-on : " ubuntu-20.04"
146
245
env :
147
246
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
148
247
steps :
149
248
- uses : actions/checkout@v4
150
249
with :
151
250
submodules : recursive
152
- - name : " Download artifacts "
153
- uses : actions/download-artifact@v3
251
+ - name : " Download GitHub Artifacts "
252
+ uses : actions/download-artifact@v4
154
253
with :
155
- name : artifacts
254
+ pattern : artifacts-*
156
255
path : artifacts
256
+ merge-multiple : true
157
257
- name : Cleanup
158
258
run : |
159
259
# Remove the granular manifests
160
- rm artifacts/*-dist-manifest.json
161
- - name : Create Release
260
+ rm -f artifacts/*-dist-manifest.json
261
+ - name : Create GitHub Release
162
262
uses : ncipollo/release-action@v1
163
263
with :
164
264
tag : ${{ needs.plan.outputs.tag }}
165
- name : ${{ fromJson(needs.plan .outputs.val).announcement_title }}
166
- body : ${{ fromJson(needs.plan .outputs.val).announcement_github_body }}
167
- prerelease : ${{ fromJson(needs.plan .outputs.val).announcement_is_prerelease }}
265
+ name : ${{ fromJson(needs.host .outputs.val).announcement_title }}
266
+ body : ${{ fromJson(needs.host .outputs.val).announcement_github_body }}
267
+ prerelease : ${{ fromJson(needs.host .outputs.val).announcement_is_prerelease }}
168
268
artifacts : " artifacts/*"
0 commit comments