1+ # This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/
2+ #
13# 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
911# * on success, uploads the artifacts to a GitHub Release
1012#
1113# 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,10 +24,10 @@ 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#
4344 - ' **[0-9]+.[0-9]+.[0-9]+*'
4445
4546jobs :
46- # Run 'cargo dist plan' (or host) to determine what tasks we need to do
47+ # Run 'dist plan' (or host) to determine what tasks we need to do
4748 plan :
48- runs-on : ubuntu-latest
49+ runs-on : " ubuntu-20.04 "
4950 outputs :
5051 val : ${{ steps.plan.outputs.manifest }}
5152 tag : ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -57,20 +58,25 @@ jobs:
5758 - uses : actions/checkout@v4
5859 with :
5960 submodules : recursive
60- - name : Install cargo- dist
61+ - name : Install dist
6162 # we specify bash to get pipefail; it guards against the `curl` command
6263 # failing. otherwise `sh` won't catch that `curl` returned non-0
6364 shell : bash
64- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
65+ run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.27.0/cargo-dist-installer.sh | sh"
66+ - name : Cache dist
67+ uses : actions/upload-artifact@v4
68+ with :
69+ name : cargo-dist-cache
70+ path : ~/.cargo/bin/dist
6571 # sure would be cool if github gave us proper conditionals...
6672 # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
6773 # functionality based on whether this is a pull_request, and whether it's from a fork.
6874 # (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
6975 # but also really annoying to build CI around when it needs secrets to work right.)
7076 - id : plan
7177 run : |
72- cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
73- echo "cargo dist ran successfully"
78+ dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
79+ echo "dist ran successfully"
7480 cat plan-dist-manifest.json
7581 echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
7682 - name : " Upload dist-manifest.json"
@@ -88,30 +94,38 @@ jobs:
8894 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') }}
8995 strategy :
9096 fail-fast : false
91- # Target platforms/runners are computed by cargo- dist in create-release.
97+ # Target platforms/runners are computed by dist in create-release.
9298 # Each member of the matrix has the following arguments:
9399 #
94100 # - runner: the github runner
95- # - dist-args: cli flags to pass to cargo dist
96- # - install-dist: expression to run to install cargo- dist on the runner
101+ # - dist-args: cli flags to pass to dist
102+ # - install-dist: expression to run to install dist on the runner
97103 #
98104 # Typically there will be:
99105 # - 1 "global" task that builds universal installers
100106 # - N "local" tasks that build each platform's binaries and platform-specific installers
101107 matrix : ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
102108 runs-on : ${{ matrix.runner }}
109+ container : ${{ matrix.container && matrix.container.image || null }}
103110 env :
104111 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
105112 BUILD_MANIFEST_NAME : target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
106113 steps :
114+ - name : enable windows longpaths
115+ run : |
116+ git config --global core.longpaths true
107117 - uses : actions/checkout@v4
108118 with :
109119 submodules : recursive
110- - uses : swatinem/rust-cache@v2
111- with :
112- key : ${{ join(matrix.targets, '-') }}
113- - name : Install cargo-dist
114- run : ${{ matrix.install_dist }}
120+ - name : Install Rust non-interactively if not already installed
121+ if : ${{ matrix.container }}
122+ run : |
123+ if ! command -v cargo > /dev/null 2>&1; then
124+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
125+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
126+ fi
127+ - name : Install dist
128+ run : ${{ matrix.install_dist.run }}
115129 # Get the dist-manifest
116130 - name : Fetch local artifacts
117131 uses : actions/download-artifact@v4
@@ -125,8 +139,8 @@ jobs:
125139 - name : Build artifacts
126140 run : |
127141 # Actually do builds and make zips and whatnot
128- cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
129- echo "cargo dist ran successfully"
142+ dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
143+ echo "dist ran successfully"
130144 - id : cargo-dist
131145 name : Post-build
132146 # We force bash here just because github makes it really hard to get values up
@@ -136,7 +150,7 @@ jobs:
136150 run : |
137151 # Parse out what we just built and upload it to scratch storage
138152 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
139- jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
153+ dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
140154 echo "EOF" >> "$GITHUB_OUTPUT"
141155
142156 cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -161,9 +175,12 @@ jobs:
161175 - uses : actions/checkout@v4
162176 with :
163177 submodules : recursive
164- - name : Install cargo-dist
165- shell : bash
166- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
178+ - name : Install cached dist
179+ uses : actions/download-artifact@v4
180+ with :
181+ name : cargo-dist-cache
182+ path : ~/.cargo/bin/
183+ - run : chmod +x ~/.cargo/bin/dist
167184 # Get all the local artifacts for the global tasks to use (for e.g. checksums)
168185 - name : Fetch local artifacts
169186 uses : actions/download-artifact@v4
@@ -174,8 +191,8 @@ jobs:
174191 - id : cargo-dist
175192 shell : bash
176193 run : |
177- cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
178- echo "cargo dist ran successfully"
194+ dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
195+ echo "dist ran successfully"
179196
180197 # Parse out what we just built and upload it to scratch storage
181198 echo "paths<<EOF" >> "$GITHUB_OUTPUT"
@@ -207,20 +224,23 @@ jobs:
207224 - uses : actions/checkout@v4
208225 with :
209226 submodules : recursive
210- - name : Install cargo-dist
211- run : " curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
227+ - name : Install cached dist
228+ uses : actions/download-artifact@v4
229+ with :
230+ name : cargo-dist-cache
231+ path : ~/.cargo/bin/
232+ - run : chmod +x ~/.cargo/bin/dist
212233 # Fetch artifacts from scratch-storage
213234 - name : Fetch artifacts
214235 uses : actions/download-artifact@v4
215236 with :
216237 pattern : artifacts-*
217238 path : target/distrib/
218239 merge-multiple : true
219- # This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
220240 - id : host
221241 shell : bash
222242 run : |
223- cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
243+ dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
224244 echo "artifacts uploaded and released successfully"
225245 cat dist-manifest.json
226246 echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
@@ -230,38 +250,87 @@ jobs:
230250 # Overwrite the previous copy
231251 name : artifacts-dist-manifest
232252 path : dist-manifest.json
253+ # Create a GitHub Release while uploading all files to it
254+ - name : " Download GitHub Artifacts"
255+ uses : actions/download-artifact@v4
256+ with :
257+ pattern : artifacts-*
258+ path : artifacts
259+ merge-multiple : true
260+ - name : Cleanup
261+ run : |
262+ # Remove the granular manifests
263+ rm -f artifacts/*-dist-manifest.json
264+ - name : Create GitHub Release
265+ env :
266+ PRERELEASE_FLAG : " ${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
267+ ANNOUNCEMENT_TITLE : " ${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
268+ ANNOUNCEMENT_BODY : " ${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
269+ RELEASE_COMMIT : " ${{ github.sha }}"
270+ run : |
271+ # Write and read notes from a file to avoid quoting breaking things
272+ echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
233273
234- # Create a GitHub Release while uploading all files to it
235- announce :
274+ gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
275+
276+ publish-homebrew-formula :
236277 needs :
237278 - plan
238279 - host
239- # use "always() && ..." to allow us to wait for all publish jobs while
240- # still allowing individual publish jobs to skip themselves (for prereleases).
241- # "host" however must run to completion, no skipping allowed!
242- if : ${{ always() && needs.host.result == 'success' }}
243280 runs-on : " ubuntu-20.04"
244281 env :
245282 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
283+ PLAN : ${{ needs.plan.outputs.val }}
284+ GITHUB_USER : " axo bot"
285+ GITHUB_EMAIL : " admin+bot@axo.dev"
286+ if : ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
246287 steps :
247288 - uses : actions/checkout@v4
248289 with :
249- submodules : recursive
250- - name : " Download GitHub Artifacts"
290+ repository : " jacktabscode/homebrew-tap"
291+ token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
292+ # So we have access to the formula
293+ - name : Fetch homebrew formulae
251294 uses : actions/download-artifact@v4
252295 with :
253296 pattern : artifacts-*
254- path : artifacts
297+ path : Formula/
255298 merge-multiple : true
256- - name : Cleanup
299+ # This is extra complex because you can make your Formula name not match your app name
300+ # so we need to find releases with a *.rb file, and publish with that filename.
301+ - name : Commit formula files
257302 run : |
258- # Remove the granular manifests
259- rm -f artifacts/*-dist-manifest.json
260- - name : Create GitHub Release
261- uses : ncipollo/release-action@v1
303+ git config --global user.name "${GITHUB_USER}"
304+ git config --global user.email "${GITHUB_EMAIL}"
305+
306+ for release in $(echo "$PLAN" | jq --compact-output '.releases[] | select([.artifacts[] | endswith(".rb")] | any)'); do
307+ filename=$(echo "$release" | jq '.artifacts[] | select(endswith(".rb"))' --raw-output)
308+ name=$(echo "$filename" | sed "s/\.rb$//")
309+ version=$(echo "$release" | jq .app_version --raw-output)
310+
311+ export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
312+ brew update
313+ # We avoid reformatting user-provided data such as the app description and homepage.
314+ brew style --except-cops FormulaAudit/Homepage,FormulaAudit/Desc,FormulaAuditStrict --fix "Formula/${filename}" || true
315+
316+ git add "Formula/${filename}"
317+ git commit -m "${name} ${version}"
318+ done
319+ git push
320+
321+ announce :
322+ needs :
323+ - plan
324+ - host
325+ - publish-homebrew-formula
326+ # use "always() && ..." to allow us to wait for all publish jobs while
327+ # still allowing individual publish jobs to skip themselves (for prereleases).
328+ # "host" however must run to completion, no skipping allowed!
329+ if : ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }}
330+ runs-on : " ubuntu-20.04"
331+ env :
332+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
333+ steps :
334+ - uses : actions/checkout@v4
262335 with :
263- tag : ${{ needs.plan.outputs.tag }}
264- name : ${{ fromJson(needs.host.outputs.val).announcement_title }}
265- body : ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
266- prerelease : ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
267- artifacts : " artifacts/*"
336+ submodules : recursive
0 commit comments