Skip to content

Commit d10634e

Browse files
committed
Preparing for dist publish
1 parent df2a032 commit d10634e

4 files changed

Lines changed: 170 additions & 94 deletions

File tree

.github/workflows/release.yml

Lines changed: 147 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
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

1416
name: Release
15-
1617
permissions:
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.
4041
on:
42+
pull_request:
4143
push:
4244
tags:
4345
- '**[0-9]+.[0-9]+.[0-9]+*'
44-
pull_request:
4546

4647
jobs:
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,27 +59,32 @@ 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.8.0/cargo-dist-installer.sh | sh"
66+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.27.0/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) || (github.event.pull_request.head.repo.fork && 'plan' || 'host --steps=check') }} --output-format=json > dist-manifest.json
74-
echo "cargo dist ran successfully"
75-
cat dist-manifest.json
76-
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
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"
81+
cat plan-dist-manifest.json
82+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
7783
- name: "Upload dist-manifest.json"
78-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
7985
with:
80-
name: artifacts
81-
path: dist-manifest.json
86+
name: artifacts-plan-dist-manifest
87+
path: plan-dist-manifest.json
8288

8389
# Build and packages all the platform-specific things
8490
build-local-artifacts:
@@ -89,42 +95,53 @@ 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
101107
# - N "local" tasks that build each platform's binaries and platform-specific installers
102108
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
103109
runs-on: ${{ matrix.runner }}
110+
container: ${{ matrix.container && matrix.container.image || null }}
104111
env:
105112
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106113
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
107114
steps:
115+
- name: enable windows longpaths
116+
run: |
117+
git config --global core.longpaths true
108118
- uses: actions/checkout@v4
109119
with:
110120
submodules: recursive
111-
- uses: swatinem/rust-cache@v2
112-
- name: Install cargo-dist
113-
run: ${{ matrix.install_dist }}
121+
- name: Install Rust non-interactively if not already installed
122+
if: ${{ matrix.container }}
123+
run: |
124+
if ! command -v cargo > /dev/null 2>&1; then
125+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
126+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
127+
fi
128+
- name: Install dist
129+
run: ${{ matrix.install_dist.run }}
114130
# Get the dist-manifest
115131
- name: Fetch local artifacts
116-
uses: actions/download-artifact@v3
132+
uses: actions/download-artifact@v4
117133
with:
118-
name: artifacts
134+
pattern: artifacts-*
119135
path: target/distrib/
136+
merge-multiple: true
120137
- name: Install dependencies
121138
run: |
122139
${{ matrix.packages_install }}
123140
- name: Build artifacts
124141
run: |
125142
# Actually do builds and make zips and whatnot
126-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
127-
echo "cargo dist ran successfully"
143+
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
144+
echo "dist ran successfully"
128145
- id: cargo-dist
129146
name: Post-build
130147
# We force bash here just because github makes it really hard to get values up
@@ -134,14 +151,14 @@ jobs:
134151
run: |
135152
# Parse out what we just built and upload it to scratch storage
136153
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
137-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
154+
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
138155
echo "EOF" >> "$GITHUB_OUTPUT"
139156
140157
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
141158
- name: "Upload artifacts"
142-
uses: actions/upload-artifact@v3
159+
uses: actions/upload-artifact@v4
143160
with:
144-
name: artifacts
161+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
145162
path: |
146163
${{ steps.cargo-dist.outputs.paths }}
147164
${{ env.BUILD_MANIFEST_NAME }}
@@ -159,30 +176,35 @@ jobs:
159176
- uses: actions/checkout@v4
160177
with:
161178
submodules: recursive
162-
- name: Install cargo-dist
163-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
179+
- name: Install cached dist
180+
uses: actions/download-artifact@v4
181+
with:
182+
name: cargo-dist-cache
183+
path: ~/.cargo/bin/
184+
- run: chmod +x ~/.cargo/bin/dist
164185
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
165186
- name: Fetch local artifacts
166-
uses: actions/download-artifact@v3
187+
uses: actions/download-artifact@v4
167188
with:
168-
name: artifacts
189+
pattern: artifacts-*
169190
path: target/distrib/
191+
merge-multiple: true
170192
- id: cargo-dist
171193
shell: bash
172194
run: |
173-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
174-
echo "cargo dist ran successfully"
195+
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
196+
echo "dist ran successfully"
175197
176198
# Parse out what we just built and upload it to scratch storage
177199
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
178-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
200+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
179201
echo "EOF" >> "$GITHUB_OUTPUT"
180202
181203
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
182204
- name: "Upload artifacts"
183-
uses: actions/upload-artifact@v3
205+
uses: actions/upload-artifact@v4
184206
with:
185-
name: artifacts
207+
name: artifacts-build-global
186208
path: |
187209
${{ steps.cargo-dist.outputs.paths }}
188210
${{ env.BUILD_MANIFEST_NAME }}
@@ -203,58 +225,113 @@ jobs:
203225
- uses: actions/checkout@v4
204226
with:
205227
submodules: recursive
206-
- name: Install cargo-dist
207-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
228+
- name: Install cached dist
229+
uses: actions/download-artifact@v4
230+
with:
231+
name: cargo-dist-cache
232+
path: ~/.cargo/bin/
233+
- run: chmod +x ~/.cargo/bin/dist
208234
# Fetch artifacts from scratch-storage
209235
- name: Fetch artifacts
210-
uses: actions/download-artifact@v3
236+
uses: actions/download-artifact@v4
211237
with:
212-
name: artifacts
238+
pattern: artifacts-*
213239
path: target/distrib/
214-
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
240+
merge-multiple: true
215241
- id: host
216242
shell: bash
217243
run: |
218-
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
244+
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
219245
echo "artifacts uploaded and released successfully"
220246
cat dist-manifest.json
221247
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
222248
- name: "Upload dist-manifest.json"
223-
uses: actions/upload-artifact@v3
249+
uses: actions/upload-artifact@v4
224250
with:
225-
name: artifacts
251+
# Overwrite the previous copy
252+
name: artifacts-dist-manifest
226253
path: dist-manifest.json
254+
# Create a GitHub Release while uploading all files to it
255+
- name: "Download GitHub Artifacts"
256+
uses: actions/download-artifact@v4
257+
with:
258+
pattern: artifacts-*
259+
path: artifacts
260+
merge-multiple: true
261+
- name: Cleanup
262+
run: |
263+
# Remove the granular manifests
264+
rm -f artifacts/*-dist-manifest.json
265+
- name: Create GitHub Release
266+
env:
267+
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
268+
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
269+
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
270+
RELEASE_COMMIT: "${{ github.sha }}"
271+
run: |
272+
# Write and read notes from a file to avoid quoting breaking things
273+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
274+
275+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
276+
277+
publish-homebrew-formula:
278+
needs:
279+
- plan
280+
- host
281+
runs-on: "ubuntu-20.04"
282+
env:
283+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
284+
PLAN: ${{ needs.plan.outputs.val }}
285+
GITHUB_USER: "axo bot"
286+
GITHUB_EMAIL: "admin+bot@axo.dev"
287+
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
288+
steps:
289+
- uses: actions/checkout@v4
290+
with:
291+
repository: "RandomStudio/homebrew-tap"
292+
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
293+
# So we have access to the formula
294+
- name: Fetch homebrew formulae
295+
uses: actions/download-artifact@v4
296+
with:
297+
pattern: artifacts-*
298+
path: Formula/
299+
merge-multiple: true
300+
# This is extra complex because you can make your Formula name not match your app name
301+
# so we need to find releases with a *.rb file, and publish with that filename.
302+
- name: Commit formula files
303+
run: |
304+
git config --global user.name "${GITHUB_USER}"
305+
git config --global user.email "${GITHUB_EMAIL}"
306+
307+
for release in $(echo "$PLAN" | jq --compact-output '.releases[] | select([.artifacts[] | endswith(".rb")] | any)'); do
308+
filename=$(echo "$release" | jq '.artifacts[] | select(endswith(".rb"))' --raw-output)
309+
name=$(echo "$filename" | sed "s/\.rb$//")
310+
version=$(echo "$release" | jq .app_version --raw-output)
311+
312+
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
313+
brew update
314+
# We avoid reformatting user-provided data such as the app description and homepage.
315+
brew style --except-cops FormulaAudit/Homepage,FormulaAudit/Desc,FormulaAuditStrict --fix "Formula/${filename}" || true
316+
317+
git add "Formula/${filename}"
318+
git commit -m "${name} ${version}"
319+
done
320+
git push
227321
228-
# Create a Github Release while uploading all files to it
229322
announce:
230323
needs:
231324
- plan
232325
- host
326+
- publish-homebrew-formula
233327
# use "always() && ..." to allow us to wait for all publish jobs while
234328
# still allowing individual publish jobs to skip themselves (for prereleases).
235329
# "host" however must run to completion, no skipping allowed!
236-
if: ${{ always() && needs.host.result == 'success' }}
330+
if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }}
237331
runs-on: "ubuntu-20.04"
238332
env:
239333
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
240334
steps:
241335
- uses: actions/checkout@v4
242336
with:
243337
submodules: recursive
244-
- name: "Download Github Artifacts"
245-
uses: actions/download-artifact@v3
246-
with:
247-
name: artifacts
248-
path: artifacts
249-
- name: Cleanup
250-
run: |
251-
# Remove the granular manifests
252-
rm -f artifacts/*-dist-manifest.json
253-
- name: Create Github Release
254-
uses: ncipollo/release-action@v1
255-
with:
256-
tag: ${{ needs.plan.outputs.tag }}
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 }}
260-
artifacts: "artifacts/*"

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)