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,30 +22,31 @@ 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 :
41
42
tags :
42
43
- ' **[0-9]+.[0-9]+.[0-9]+*'
44
+ pull_request :
43
45
44
46
jobs :
45
- # 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
46
48
plan :
47
- runs-on : self-hosted
49
+ runs-on : ubuntu-latest
48
50
outputs :
49
51
val : ${{ steps.plan.outputs.manifest }}
50
52
tag : ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -56,16 +58,20 @@ jobs:
56
58
- uses : actions/checkout@v4
57
59
with :
58
60
submodules : recursive
59
- - name : Install toolchain
60
- uses : dtolnay/rust-toolchain@nightly
61
- with :
62
- toolchain : nightly
63
61
- name : Install cargo-dist
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
64
65
run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/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.)
65
71
- id : plan
66
72
run : |
67
- cargo dist plan ${{ !github.event.pull_request && format('-- tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json
68
- echo "cargo dist plan ran successfully"
73
+ cargo dist ${{ !github.event.pull_request && format('host --steps=create -- tag={0}', github.ref_name) || (github.event.pull_request.head.repo.fork && 'plan' || 'host --steps=check') }} --output-format=json > dist-manifest.json
74
+ echo "cargo dist ran successfully"
69
75
cat dist-manifest.json
70
76
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
71
77
- name : " Upload dist-manifest.json"
@@ -75,10 +81,12 @@ jobs:
75
81
path : dist-manifest.json
76
82
77
83
# Build and packages all the platform-specific things
78
- upload-local-artifacts :
84
+ build-local-artifacts :
85
+ name : build-local-artifacts (${{ join(matrix.targets, ', ') }})
79
86
# Let the initial task tell us to not run (currently very blunt)
80
- needs : plan
81
- 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') }}
82
90
strategy :
83
91
fail-fast : false
84
92
# Target platforms/runners are computed by cargo-dist in create-release.
92
100
# - 1 "global" task that builds universal installers
93
101
# - N "local" tasks that build each platform's binaries and platform-specific installers
94
102
matrix : ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
95
- runs-on : ${{ matrix.runner }}
103
+ # runs-on: ${{ matrix.runner }}
104
+ runs-on : self-hosted
96
105
env :
97
106
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
98
107
BUILD_MANIFEST_NAME : target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
@@ -103,24 +112,12 @@ jobs:
103
112
- uses : swatinem/rust-cache@v2
104
113
- name : Install cargo-dist
105
114
run : ${{ matrix.install_dist }}
106
-
107
- - uses : webfactory/ssh-agent@v0.5.4
108
- with :
109
- ssh-private-key : " ${{ secrets.SSH_KEY }}"
110
-
111
- - name : Install Protoc
112
- uses : arduino/setup-protoc@v1
113
- with :
114
- version : ' 3.9.1'
115
-
116
- - name : Install toolchain
117
- uses : dtolnay/rust-toolchain@nightly
115
+ # Get the dist-manifest
116
+ - name : Fetch local artifacts
117
+ uses : actions/download-artifact@v3
118
118
with :
119
- toolchain : nightly
120
-
121
- - name : Add wasm toolchain
122
- run : rustup target add wasm32-unknown-unknown
123
-
119
+ name : artifacts
120
+ path : target/distrib/
124
121
- name : Install dependencies
125
122
run : |
126
123
${{ matrix.packages_install }}
@@ -136,8 +133,7 @@ jobs:
136
133
# inconsistent syntax between shell and powershell.
137
134
shell : bash
138
135
run : |
139
- cat dist-manifest.json
140
- # Parse out what we just built and upload it to the Github Release™
136
+ # Parse out what we just built and upload it to scratch storage
141
137
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
142
138
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
143
139
echo "EOF" >> "$GITHUB_OUTPUT"
@@ -152,11 +148,14 @@ jobs:
152
148
${{ env.BUILD_MANIFEST_NAME }}
153
149
154
150
# Build and package all the platform-agnostic(ish) things
155
- upload-global-artifacts :
156
- needs : [plan, upload-local-artifacts]
151
+ build-global-artifacts :
152
+ needs :
153
+ - plan
154
+ - build-local-artifacts
157
155
runs-on : " ubuntu-20.04"
158
156
env :
159
157
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
158
+ BUILD_MANIFEST_NAME : target/distrib/global-dist-manifest.json
160
159
steps :
161
160
- uses : actions/checkout@v4
162
161
with :
@@ -175,85 +174,88 @@ jobs:
175
174
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
176
175
echo "cargo dist ran successfully"
177
176
178
- # Parse out what we just built and upload it to the Github Release™
177
+ # Parse out what we just built and upload it to scratch storage
179
178
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
180
179
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
181
180
echo "EOF" >> "$GITHUB_OUTPUT"
181
+
182
+ cp dist-manifest.json "$BUILD_MANIFEST_NAME"
182
183
- name : " Upload artifacts"
183
184
uses : actions/upload-artifact@v3
184
185
with :
185
186
name : artifacts
186
- path : ${{ steps.cargo-dist.outputs.paths }}
187
-
188
- should-publish :
187
+ path : |
188
+ ${{ steps.cargo-dist.outputs.paths }}
189
+ ${{ env.BUILD_MANIFEST_NAME }}
190
+ # Determines if we should publish/announce
191
+ host :
189
192
needs :
190
193
- plan
191
- - upload-local-artifacts
192
- - upload-global-artifacts
193
- if : ${{ needs.plan.outputs.publishing == 'true' }}
194
- runs-on : self-hosted
195
- steps :
196
- - name : print tag
197
- run : echo "ok we're publishing!"
198
-
199
- publish-homebrew-formula :
200
- needs : [plan, should-publish]
201
- runs-on : " ubuntu-20.04"
194
+ - build-local-artifacts
195
+ - build-global-artifacts
196
+ # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
197
+ 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
198
env :
203
199
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
204
- PLAN : ${{ needs.plan.outputs.val }}
205
- GITHUB_USER : " axo bot"
206
- GITHUB_EMAIL : " admin+bot@axo.dev"
207
- if : ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
200
+ runs-on : " ubuntu-20.04"
201
+ outputs :
202
+ val : ${{ steps.host.outputs.manifest }}
208
203
steps :
209
204
- uses : actions/checkout@v4
210
205
with :
211
- repository : " polytope-labs/hyperbridge"
212
- token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
213
- # So we have access to the formula
214
- - name : Fetch local artifacts
206
+ submodules : recursive
207
+ - name : Install cargo-dist
208
+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
209
+ # Fetch artifacts from scratch-storage
210
+ - name : Fetch artifacts
215
211
uses : actions/download-artifact@v3
216
212
with :
217
213
name : artifacts
218
- path : Formula/
219
- - name : Commit formula files
214
+ path : target/distrib/
215
+ # This is a harmless no-op for Github Releases, hosting for that happens in "announce"
216
+ - id : host
217
+ shell : bash
220
218
run : |
221
- git config --global user.name "${GITHUB_USER}"
222
- git config --global user.email "${GITHUB_EMAIL}"
223
-
224
- for release in $(echo "$PLAN" | jq --compact-output '.releases[]'); do
225
- name=$(echo "$release" | jq .app_name --raw-output)
226
- version=$(echo "$release" | jq .app_version --raw-output)
227
-
228
- git add Formula/${name}.rb
229
- git commit -m "${name} ${version}"
230
- done
231
- git push
219
+ cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
220
+ echo "artifacts uploaded and released successfully"
221
+ cat dist-manifest.json
222
+ echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
223
+ - name : " Upload dist-manifest.json"
224
+ uses : actions/upload-artifact@v3
225
+ with :
226
+ name : artifacts
227
+ path : dist-manifest.json
232
228
233
- # Create a Github Release with all the results once everything is done
234
- publish-release :
235
- needs : [plan, should-publish]
236
- runs-on : self-hosted
229
+ # Create a Github Release while uploading all files to it
230
+ announce :
231
+ needs :
232
+ - plan
233
+ - host
234
+ # use "always() && ..." to allow us to wait for all publish jobs while
235
+ # still allowing individual publish jobs to skip themselves (for prereleases).
236
+ # "host" however must run to completion, no skipping allowed!
237
+ if : ${{ always() && needs.host.result == 'success' }}
238
+ runs-on : " ubuntu-20.04"
237
239
env :
238
240
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
239
241
steps :
240
242
- uses : actions/checkout@v4
241
243
with :
242
244
submodules : recursive
243
- - name : " Download artifacts "
245
+ - name : " Download Github Artifacts "
244
246
uses : actions/download-artifact@v3
245
247
with :
246
248
name : artifacts
247
249
path : artifacts
248
250
- name : Cleanup
249
251
run : |
250
252
# Remove the granular manifests
251
- rm artifacts/*-dist-manifest.json
252
- - name : Create Release
253
+ rm -f artifacts/*-dist-manifest.json
254
+ - name : Create Github Release
253
255
uses : ncipollo/release-action@v1
254
256
with :
255
257
tag : ${{ needs.plan.outputs.tag }}
256
- name : ${{ fromJson(needs.plan .outputs.val).announcement_title }}
257
- body : ${{ fromJson(needs.plan .outputs.val).announcement_github_body }}
258
- prerelease : ${{ fromJson(needs.plan .outputs.val).announcement_is_prerelease }}
258
+ name : ${{ fromJson(needs.host .outputs.val).announcement_title }}
259
+ body : ${{ fromJson(needs.host .outputs.val).announcement_github_body }}
260
+ prerelease : ${{ fromJson(needs.host .outputs.val).announcement_is_prerelease }}
259
261
artifacts : " artifacts/*"
0 commit comments