1- # Copyright 2022-2023, axodotdev
1+ # This file was autogenerated by dist: https://opensource.axo.dev/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-20.04 "
5051 outputs :
5152 val : ${{ steps.plan.outputs.manifest }}
5253 tag : ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -58,20 +59,25 @@ jobs:
5859 - uses : actions/checkout@v4
5960 with :
6061 submodules : recursive
61- - name : Install cargo- dist
62+ - name : Install dist
6263 # we specify bash to get pipefail; it guards against the `curl` command
6364 # failing. otherwise `sh` won't catch that `curl` returned non-0
6465 shell : bash
65- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/cargo-dist-installer.sh | sh"
66+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.25.1/cargo-dist-installer.sh | sh"
67+ - name : Cache dist
68+ uses : actions/upload-artifact@v4
69+ with :
70+ name : cargo-dist-cache
71+ path : ~/.cargo/bin/dist
6672 # sure would be cool if github gave us proper conditionals...
6773 # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
6874 # functionality based on whether this is a pull_request, and whether it's from a fork.
6975 # (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
7076 # but also really annoying to build CI around when it needs secrets to work right.)
7177 - id : plan
7278 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"
79+ dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
80+ echo "dist ran successfully"
7581 cat plan-dist-manifest.json
7682 echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
7783 - name : " Upload dist-manifest.json"
@@ -89,12 +95,12 @@ jobs:
8995 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') }}
9096 strategy :
9197 fail-fast : false
92- # Target platforms/runners are computed by cargo- dist in create-release.
98+ # Target platforms/runners are computed by dist in create-release.
9399 # Each member of the matrix has the following arguments:
94100 #
95101 # - 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
102+ # - dist-args: cli flags to pass to dist
103+ # - install-dist: expression to run to install dist on the runner
98104 #
99105 # Typically there will be:
100106 # - 1 "global" task that builds universal installers
@@ -105,11 +111,13 @@ jobs:
105111 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
106112 BUILD_MANIFEST_NAME : target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
107113 steps :
114+ - name : enable windows longpaths
115+ run : |
116+ git config --global core.longpaths true
108117 - uses : actions/checkout@v4
109118 with :
110119 submodules : recursive
111- - uses : swatinem/rust-cache@v2
112- - name : Install cargo-dist
120+ - name : Install dist
113121 run : ${{ matrix.install_dist }}
114122 # Get the dist-manifest
115123 - name : Fetch local artifacts
@@ -124,8 +132,8 @@ jobs:
124132 - name : Build artifacts
125133 run : |
126134 # 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"
135+ dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
136+ echo "dist ran successfully"
129137 - id : cargo-dist
130138 name : Post-build
131139 # We force bash here just because github makes it really hard to get values up
@@ -135,7 +143,7 @@ jobs:
135143 run : |
136144 # Parse out what we just built and upload it to scratch storage
137145 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
138- jq --raw-output ".artifacts[]?.path | select( . != null ) " dist-manifest.json >> "$GITHUB_OUTPUT"
146+ jq --raw-output ".upload_files[] " dist-manifest.json >> "$GITHUB_OUTPUT"
139147 echo "EOF" >> "$GITHUB_OUTPUT"
140148
141149 cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -160,9 +168,12 @@ jobs:
160168 - uses : actions/checkout@v4
161169 with :
162170 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.11.1/cargo-dist-installer.sh | sh"
171+ - name : Install cached dist
172+ uses : actions/download-artifact@v4
173+ with :
174+ name : cargo-dist-cache
175+ path : ~/.cargo/bin/
176+ - run : chmod +x ~/.cargo/bin/dist
166177 # Get all the local artifacts for the global tasks to use (for e.g. checksums)
167178 - name : Fetch local artifacts
168179 uses : actions/download-artifact@v4
@@ -173,12 +184,12 @@ jobs:
173184 - id : cargo-dist
174185 shell : bash
175186 run : |
176- cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
177- echo "cargo dist ran successfully"
187+ dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
188+ echo "dist ran successfully"
178189
179190 # Parse out what we just built and upload it to scratch storage
180191 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
181- jq --raw-output ".artifacts[]?.path | select( . != null ) " dist-manifest.json >> "$GITHUB_OUTPUT"
192+ jq --raw-output ".upload_files[] " dist-manifest.json >> "$GITHUB_OUTPUT"
182193 echo "EOF" >> "$GITHUB_OUTPUT"
183194
184195 cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -206,20 +217,23 @@ jobs:
206217 - uses : actions/checkout@v4
207218 with :
208219 submodules : recursive
209- - name : Install cargo-dist
210- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/cargo-dist-installer.sh | sh"
220+ - name : Install cached dist
221+ uses : actions/download-artifact@v4
222+ with :
223+ name : cargo-dist-cache
224+ path : ~/.cargo/bin/
225+ - run : chmod +x ~/.cargo/bin/dist
211226 # Fetch artifacts from scratch-storage
212227 - name : Fetch artifacts
213228 uses : actions/download-artifact@v4
214229 with :
215230 pattern : artifacts-*
216231 path : target/distrib/
217232 merge-multiple : true
218- # This is a harmless no-op for Github Releases, hosting for that happens in "announce"
219233 - id : host
220234 shell : bash
221235 run : |
222- cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
236+ dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
223237 echo "artifacts uploaded and released successfully"
224238 cat dist-manifest.json
225239 echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
@@ -229,6 +243,28 @@ jobs:
229243 # Overwrite the previous copy
230244 name : artifacts-dist-manifest
231245 path : dist-manifest.json
246+ # Create a GitHub Release while uploading all files to it
247+ - name : " Download GitHub Artifacts"
248+ uses : actions/download-artifact@v4
249+ with :
250+ pattern : artifacts-*
251+ path : artifacts
252+ merge-multiple : true
253+ - name : Cleanup
254+ run : |
255+ # Remove the granular manifests
256+ rm -f artifacts/*-dist-manifest.json
257+ - name : Create GitHub Release
258+ env :
259+ PRERELEASE_FLAG : " ${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
260+ ANNOUNCEMENT_TITLE : " ${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
261+ ANNOUNCEMENT_BODY : " ${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
262+ RELEASE_COMMIT : " ${{ github.sha }}"
263+ run : |
264+ # Write and read notes from a file to avoid quoting breaking things
265+ echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
266+
267+ gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
232268
233269 publish-homebrew-formula :
234270 needs :
@@ -247,7 +283,7 @@ jobs:
247283 repository : " W-Mai/homebrew-cellar"
248284 token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
249285 # So we have access to the formula
250- - name : Fetch local artifacts
286+ - name : Fetch homebrew formulae
251287 uses : actions/download-artifact@v4
252288 with :
253289 pattern : artifacts-*
@@ -265,12 +301,16 @@ jobs:
265301 name=$(echo "$filename" | sed "s/\.rb$//")
266302 version=$(echo "$release" | jq .app_version --raw-output)
267303
304+ export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
305+ brew update
306+ # We avoid reformatting user-provided data such as the app description and homepage.
307+ brew style --except-cops FormulaAudit/Homepage,FormulaAudit/Desc,FormulaAuditStrict --fix "Formula/${filename}" || true
308+
268309 git add "Formula/${filename}"
269310 git commit -m "${name} ${version}"
270311 done
271312 git push
272313
273- # Create a Github Release while uploading all files to it
274314 announce :
275315 needs :
276316 - plan
@@ -287,21 +327,3 @@ jobs:
287327 - uses : actions/checkout@v4
288328 with :
289329 submodules : recursive
290- - name : " Download Github Artifacts"
291- uses : actions/download-artifact@v4
292- with :
293- pattern : artifacts-*
294- path : artifacts
295- merge-multiple : true
296- - name : Cleanup
297- run : |
298- # Remove the granular manifests
299- rm -f artifacts/*-dist-manifest.json
300- - name : Create Github Release
301- uses : ncipollo/release-action@v1
302- with :
303- tag : ${{ needs.plan.outputs.tag }}
304- name : ${{ fromJson(needs.host.outputs.val).announcement_title }}
305- body : ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
306- prerelease : ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
307- artifacts : " artifacts/*"
0 commit comments