66# * checks for a Git Tag that looks like a release
77# * builds artifacts with cargo-dist (archives, installers, hashes)
88# * 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
1010#
11- # Note that the Github Release™ will be created with a generated
11+ # Note that the Github Release will be created with a generated
1212# title/body based on your changelogs.
13+
1314name : Release
1415
1516permissions :
@@ -21,20 +22,20 @@ permissions:
2122# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
2223# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
2324#
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
2526# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
2627#
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
2829# (cargo-dist-able) packages in the workspace with that version (this mode is
2930# intended for workspaces with only one dist-able package, or with all dist-able
3031# packages versioned/released in lockstep).
3132#
3233# 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
3435# will hard limit this to 3 tags per commit, as it will assume more tags is a
3536# mistake.
3637#
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)
3839# will be marked as a prerelease.
3940on :
4041 push :
4344 pull_request :
4445
4546jobs :
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
4748 plan :
4849 runs-on : ubuntu-latest
4950 outputs :
@@ -58,11 +59,19 @@ jobs:
5859 with :
5960 submodules : recursive
6061 - name : Install cargo-dist
61- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.3/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.7.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.)
6271 - id : plan
6372 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"
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"
6675 cat dist-manifest.json
6776 echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
6877 - name : " Upload dist-manifest.json"
@@ -72,10 +81,12 @@ jobs:
7281 path : dist-manifest.json
7382
7483 # Build and packages all the platform-specific things
75- upload-local-artifacts :
84+ build-local-artifacts :
85+ name : build-local-artifacts (${{ join(matrix.targets, ', ') }})
7686 # 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') }}
7990 strategy :
8091 fail-fast : false
8192 # Target platforms/runners are computed by cargo-dist in create-release.
@@ -100,6 +111,12 @@ jobs:
100111 - uses : swatinem/rust-cache@v2
101112 - name : Install cargo-dist
102113 run : ${{ matrix.install_dist }}
114+ # Get the dist-manifest
115+ - name : Fetch local artifacts
116+ uses : actions/download-artifact@v3
117+ with :
118+ name : artifacts
119+ path : target/distrib/
103120 - name : Install dependencies
104121 run : |
105122 ${{ matrix.packages_install }}
@@ -115,7 +132,7 @@ jobs:
115132 # inconsistent syntax between shell and powershell.
116133 shell : bash
117134 run : |
118- # Parse out what we just built and upload it to the Github Release™
135+ # Parse out what we just built and upload it to scratch storage
119136 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
120137 jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
121138 echo "EOF" >> "$GITHUB_OUTPUT"
@@ -130,17 +147,20 @@ jobs:
130147 ${{ env.BUILD_MANIFEST_NAME }}
131148
132149 # Build and package all the platform-agnostic(ish) things
133- upload-global-artifacts :
134- needs : [plan, upload-local-artifacts]
150+ build-global-artifacts :
151+ needs :
152+ - plan
153+ - build-local-artifacts
135154 runs-on : " ubuntu-20.04"
136155 env :
137156 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
157+ BUILD_MANIFEST_NAME : target/distrib/global-dist-manifest.json
138158 steps :
139159 - uses : actions/checkout@v4
140160 with :
141161 submodules : recursive
142162 - name : Install cargo-dist
143- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.3 /cargo-dist-installer.sh | sh"
163+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.7.1 /cargo-dist-installer.sh | sh"
144164 # Get all the local artifacts for the global tasks to use (for e.g. checksums)
145165 - name : Fetch local artifacts
146166 uses : actions/download-artifact@v3
@@ -153,51 +173,88 @@ jobs:
153173 cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
154174 echo "cargo dist ran successfully"
155175
156- # Parse out what we just built and upload it to the Github Release™
176+ # Parse out what we just built and upload it to scratch storage
157177 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
158178 jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
159179 echo "EOF" >> "$GITHUB_OUTPUT"
180+
181+ cp dist-manifest.json "$BUILD_MANIFEST_NAME"
160182 - name : " Upload artifacts"
161183 uses : actions/upload-artifact@v3
162184 with :
163185 name : artifacts
164- path : ${{ steps.cargo-dist.outputs.paths }}
165-
166- should-publish :
186+ path : |
187+ ${{ steps.cargo-dist.outputs.paths }}
188+ ${{ env.BUILD_MANIFEST_NAME }}
189+ # Determines if we should publish/announce
190+ host :
167191 needs :
168192 - plan
169- - upload-local-artifacts
170- - upload-global-artifacts
171- if : ${{ needs.plan.outputs.publishing == 'true' }}
172- runs-on : ubuntu-latest
193+ - build-local-artifacts
194+ - build-global-artifacts
195+ # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
196+ 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') }}
197+ env :
198+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
199+ runs-on : " ubuntu-20.04"
200+ outputs :
201+ val : ${{ steps.host.outputs.manifest }}
173202 steps :
174- - name : print tag
175- run : echo "ok we're publishing!"
203+ - uses : actions/checkout@v4
204+ with :
205+ submodules : recursive
206+ - name : Install cargo-dist
207+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.7.1/cargo-dist-installer.sh | sh"
208+ # Fetch artifacts from scratch-storage
209+ - name : Fetch artifacts
210+ uses : actions/download-artifact@v3
211+ with :
212+ name : artifacts
213+ path : target/distrib/
214+ # This is a harmless no-op for Github Releases, hosting for that happens in "announce"
215+ - id : host
216+ shell : bash
217+ run : |
218+ cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
219+ echo "artifacts uploaded and released successfully"
220+ cat dist-manifest.json
221+ echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
222+ - name : " Upload dist-manifest.json"
223+ uses : actions/upload-artifact@v3
224+ with :
225+ name : artifacts
226+ path : dist-manifest.json
176227
177- # Create a Github Release with all the results once everything is done
178- publish-release :
179- needs : [plan, should-publish]
180- runs-on : ubuntu-latest
228+ # Create a Github Release while uploading all files to it
229+ announce :
230+ needs :
231+ - plan
232+ - host
233+ # use "always() && ..." to allow us to wait for all publish jobs while
234+ # still allowing individual publish jobs to skip themselves (for prereleases).
235+ # "host" however must run to completion, no skipping allowed!
236+ if : ${{ always() && needs.host.result == 'success' }}
237+ runs-on : " ubuntu-20.04"
181238 env :
182239 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
183240 steps :
184241 - uses : actions/checkout@v4
185242 with :
186243 submodules : recursive
187- - name : " Download artifacts "
244+ - name : " Download Github Artifacts "
188245 uses : actions/download-artifact@v3
189246 with :
190247 name : artifacts
191248 path : artifacts
192249 - name : Cleanup
193250 run : |
194251 # Remove the granular manifests
195- rm artifacts/*-dist-manifest.json
196- - name : Create Release
252+ rm -f artifacts/*-dist-manifest.json
253+ - name : Create Github Release
197254 uses : ncipollo/release-action@v1
198255 with :
199256 tag : ${{ needs.plan.outputs.tag }}
200- name : ${{ fromJson(needs.plan .outputs.val).announcement_title }}
201- body : ${{ fromJson(needs.plan .outputs.val).announcement_github_body }}
202- prerelease : ${{ fromJson(needs.plan .outputs.val).announcement_is_prerelease }}
257+ name : ${{ fromJson(needs.host .outputs.val).announcement_title }}
258+ body : ${{ fromJson(needs.host .outputs.val).announcement_github_body }}
259+ prerelease : ${{ fromJson(needs.host .outputs.val).announcement_is_prerelease }}
203260 artifacts : " artifacts/*"
0 commit comments