1- # Copyright 2022-2023, axodotdev
1+ # This file was autogenerated by dist: https://axodotdev.github.io/cargo-dist
2+ #
3+ # Copyright 2022-2024, axodotdev
24# SPDX-License-Identifier: MIT or Apache-2.0
35#
46# CI that:
57#
68# * checks for a Git Tag that looks like a release
7- # * builds artifacts with cargo- dist (archives, installers, hashes)
9+ # * builds artifacts with dist (archives, installers, hashes)
810# * uploads those artifacts to temporary workflow zip
9- # * on success, uploads the artifacts to a Github Release
11+ # * on success, uploads the artifacts to a GitHub Release
1012#
11- # Note that the Github Release will be created with a generated
13+ # Note that the GitHub Release will be created with a generated
1214# title/body based on your changelogs.
1315
1416name : Release
15-
1617permissions :
17- contents : write
18+ " contents " : " write"
1819
1920# This task will run whenever you push a git tag that looks like a version
2021# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
@@ -23,30 +24,30 @@ permissions:
2324# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
2425#
2526# If PACKAGE_NAME is specified, then the announcement will be for that
26- # package (erroring out if it doesn't have the given version or isn't cargo- dist-able).
27+ # package (erroring out if it doesn't have the given version or isn't dist-able).
2728#
2829# If PACKAGE_NAME isn't specified, then the announcement will be for all
29- # (cargo- dist-able) packages in the workspace with that version (this mode is
30+ # (dist-able) packages in the workspace with that version (this mode is
3031# intended for workspaces with only one dist-able package, or with all dist-able
3132# packages versioned/released in lockstep).
3233#
3334# If you push multiple tags at once, separate instances of this workflow will
34- # spin up, creating an independent announcement for each one. However Github
35+ # spin up, creating an independent announcement for each one. However, GitHub
3536# will hard limit this to 3 tags per commit, as it will assume more tags is a
3637# mistake.
3738#
3839# If there's a prerelease-style suffix to the version, then the release(s)
3940# will be marked as a prerelease.
4041on :
42+ pull_request :
4143 push :
4244 tags :
4345 - ' **[0-9]+.[0-9]+.[0-9]+*'
44- pull_request :
4546
4647jobs :
47- # Run 'cargo dist plan' (or host) to determine what tasks we need to do
48+ # Run 'dist plan' (or host) to determine what tasks we need to do
4849 plan :
49- runs-on : ubuntu-latest
50+ runs-on : " ubuntu-22.04 "
5051 outputs :
5152 val : ${{ steps.plan.outputs.manifest }}
5253 tag : ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -57,21 +58,27 @@ jobs:
5758 steps :
5859 - uses : actions/checkout@v4
5960 with :
61+ persist-credentials : false
6062 submodules : recursive
61- - name : Install cargo- dist
63+ - name : Install dist
6264 # we specify bash to get pipefail; it guards against the `curl` command
6365 # failing. otherwise `sh` won't catch that `curl` returned non-0
6466 shell : bash
65- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
67+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.30.3/cargo-dist-installer.sh | sh"
68+ - name : Cache dist
69+ uses : actions/upload-artifact@v4
70+ with :
71+ name : cargo-dist-cache
72+ path : ~/.cargo/bin/dist
6673 # sure would be cool if github gave us proper conditionals...
6774 # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
6875 # functionality based on whether this is a pull_request, and whether it's from a fork.
6976 # (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
7077 # but also really annoying to build CI around when it needs secrets to work right.)
7178 - id : plan
7279 run : |
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"
80+ dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
81+ echo "dist ran successfully"
7582 cat plan-dist-manifest.json
7683 echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
7784 - name : " Upload dist-manifest.json"
@@ -89,28 +96,39 @@ jobs:
8996 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') }}
9097 strategy :
9198 fail-fast : false
92- # Target platforms/runners are computed by cargo- dist in create-release.
99+ # Target platforms/runners are computed by dist in create-release.
93100 # Each member of the matrix has the following arguments:
94101 #
95102 # - runner: the github runner
96- # - dist-args: cli flags to pass to cargo dist
97- # - install-dist: expression to run to install cargo- dist on the runner
103+ # - dist-args: cli flags to pass to dist
104+ # - install-dist: expression to run to install dist on the runner
98105 #
99106 # Typically there will be:
100107 # - 1 "global" task that builds universal installers
101108 # - N "local" tasks that build each platform's binaries and platform-specific installers
102109 matrix : ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
103110 runs-on : ${{ matrix.runner }}
111+ container : ${{ matrix.container && matrix.container.image || null }}
104112 env :
105113 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
106114 BUILD_MANIFEST_NAME : target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
107115 steps :
116+ - name : enable windows longpaths
117+ run : |
118+ git config --global core.longpaths true
108119 - uses : actions/checkout@v4
109120 with :
121+ persist-credentials : false
110122 submodules : recursive
111- - uses : swatinem/rust-cache@v2
112- - name : Install cargo-dist
113- run : ${{ matrix.install_dist }}
123+ - name : Install Rust non-interactively if not already installed
124+ if : ${{ matrix.container }}
125+ run : |
126+ if ! command -v cargo > /dev/null 2>&1; then
127+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
128+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
129+ fi
130+ - name : Install dist
131+ run : ${{ matrix.install_dist.run }}
114132 # Get the dist-manifest
115133 - name : Fetch local artifacts
116134 uses : actions/download-artifact@v4
@@ -124,8 +142,8 @@ jobs:
124142 - name : Build artifacts
125143 run : |
126144 # Actually do builds and make zips and whatnot
127- cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
128- echo "cargo dist ran successfully"
145+ dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
146+ echo "dist ran successfully"
129147 - id : cargo-dist
130148 name : Post-build
131149 # We force bash here just because github makes it really hard to get values up
@@ -135,7 +153,7 @@ jobs:
135153 run : |
136154 # Parse out what we just built and upload it to scratch storage
137155 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
138- jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
156+ dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
139157 echo "EOF" >> "$GITHUB_OUTPUT"
140158
141159 cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -152,17 +170,21 @@ jobs:
152170 needs :
153171 - plan
154172 - build-local-artifacts
155- runs-on : " ubuntu-20 .04"
173+ runs-on : " ubuntu-22 .04"
156174 env :
157175 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
158176 BUILD_MANIFEST_NAME : target/distrib/global-dist-manifest.json
159177 steps :
160178 - uses : actions/checkout@v4
161179 with :
180+ persist-credentials : false
162181 submodules : recursive
163- - name : Install cargo-dist
164- shell : bash
165- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
182+ - name : Install cached dist
183+ uses : actions/download-artifact@v4
184+ with :
185+ name : cargo-dist-cache
186+ path : ~/.cargo/bin/
187+ - run : chmod +x ~/.cargo/bin/dist
166188 # Get all the local artifacts for the global tasks to use (for e.g. checksums)
167189 - name : Fetch local artifacts
168190 uses : actions/download-artifact@v4
@@ -173,12 +195,12 @@ jobs:
173195 - id : cargo-dist
174196 shell : bash
175197 run : |
176- cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
177- echo "cargo dist ran successfully"
198+ dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
199+ echo "dist ran successfully"
178200
179201 # Parse out what we just built and upload it to scratch storage
180202 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
181- jq --raw-output ".artifacts[]?.path | select( . != null ) " dist-manifest.json >> "$GITHUB_OUTPUT"
203+ jq --raw-output ".upload_files[] " dist-manifest.json >> "$GITHUB_OUTPUT"
182204 echo "EOF" >> "$GITHUB_OUTPUT"
183205
184206 cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -195,31 +217,35 @@ jobs:
195217 - plan
196218 - build-local-artifacts
197219 - build-global-artifacts
198- # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
199- 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') }}
220+ # Only run if we're "publishing", and only if plan, local and global didn't fail (skipped is fine)
221+ if : ${{ always() && needs.plan.result == 'success' && 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') }}
200222 env :
201223 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
202- runs-on : " ubuntu-20 .04"
224+ runs-on : " ubuntu-22 .04"
203225 outputs :
204226 val : ${{ steps.host.outputs.manifest }}
205227 steps :
206228 - uses : actions/checkout@v4
207229 with :
230+ persist-credentials : false
208231 submodules : recursive
209- - name : Install cargo-dist
210- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
232+ - name : Install cached dist
233+ uses : actions/download-artifact@v4
234+ with :
235+ name : cargo-dist-cache
236+ path : ~/.cargo/bin/
237+ - run : chmod +x ~/.cargo/bin/dist
211238 # Fetch artifacts from scratch-storage
212239 - name : Fetch artifacts
213240 uses : actions/download-artifact@v4
214241 with :
215242 pattern : artifacts-*
216243 path : target/distrib/
217244 merge-multiple : true
218- # This is a harmless no-op for Github Releases, hosting for that happens in "announce"
219245 - id : host
220246 shell : bash
221247 run : |
222- cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
248+ dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
223249 echo "artifacts uploaded and released successfully"
224250 cat dist-manifest.json
225251 echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
@@ -229,8 +255,29 @@ jobs:
229255 # Overwrite the previous copy
230256 name : artifacts-dist-manifest
231257 path : dist-manifest.json
258+ # Create a GitHub Release while uploading all files to it
259+ - name : " Download GitHub Artifacts"
260+ uses : actions/download-artifact@v4
261+ with :
262+ pattern : artifacts-*
263+ path : artifacts
264+ merge-multiple : true
265+ - name : Cleanup
266+ run : |
267+ # Remove the granular manifests
268+ rm -f artifacts/*-dist-manifest.json
269+ - name : Create GitHub Release
270+ env :
271+ PRERELEASE_FLAG : " ${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
272+ ANNOUNCEMENT_TITLE : " ${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
273+ ANNOUNCEMENT_BODY : " ${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
274+ RELEASE_COMMIT : " ${{ github.sha }}"
275+ run : |
276+ # Write and read notes from a file to avoid quoting breaking things
277+ echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
278+
279+ gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
232280
233- # Create a Github Release while uploading all files to it
234281 announce :
235282 needs :
236283 - plan
@@ -239,28 +286,11 @@ jobs:
239286 # still allowing individual publish jobs to skip themselves (for prereleases).
240287 # "host" however must run to completion, no skipping allowed!
241288 if : ${{ always() && needs.host.result == 'success' }}
242- runs-on : " ubuntu-20 .04"
289+ runs-on : " ubuntu-22 .04"
243290 env :
244291 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
245292 steps :
246293 - uses : actions/checkout@v4
247294 with :
295+ persist-credentials : false
248296 submodules : recursive
249- - name : " Download Github Artifacts"
250- uses : actions/download-artifact@v4
251- with :
252- pattern : artifacts-*
253- path : artifacts
254- merge-multiple : true
255- - name : Cleanup
256- run : |
257- # Remove the granular manifests
258- rm -f artifacts/*-dist-manifest.json
259- - name : Create Github Release
260- uses : ncipollo/release-action@v1
261- with :
262- tag : ${{ needs.plan.outputs.tag }}
263- name : ${{ fromJson(needs.host.outputs.val).announcement_title }}
264- body : ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
265- prerelease : ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
266- artifacts : " artifacts/*"
0 commit comments