Skip to content

Commit 176d1d5

Browse files
Merge pull request #25 from ferrous-systems/update-cargo-dist
Upgrade cargo-dist to 0.25
2 parents 6ddda8a + d0d7acb commit 176d1d5

File tree

3 files changed

+176
-90
lines changed

3 files changed

+176
-90
lines changed

.github/workflows/release.yml

Lines changed: 157 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
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.
13-
name: Release
1415

16+
name: Release
1517
permissions:
16-
contents: write
18+
"contents": "write"
1719

1820
# This task will run whenever you push a git tag that looks like a version
1921
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
2022
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
2123
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
2224
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
2325
#
24-
# If PACKAGE_NAME is specified, then the release will be for that
25-
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
26+
# If PACKAGE_NAME is specified, then the announcement will be for that
27+
# package (erroring out if it doesn't have the given version or isn't dist-able).
2628
#
27-
# If PACKAGE_NAME isn't specified, then the release will be for all
28-
# (cargo-dist-able) packages in the workspace with that version (this mode is
29+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
30+
# (dist-able) packages in the workspace with that version (this mode is
2931
# intended for workspaces with only one dist-able package, or with all dist-able
3032
# packages versioned/released in lockstep).
3133
#
3234
# 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
35+
# spin up, creating an independent announcement for each one. However, GitHub
3436
# will hard limit this to 3 tags per commit, as it will assume more tags is a
3537
# mistake.
3638
#
37-
# If there's a prerelease-style suffix to the version, then the Github Release™
39+
# If there's a prerelease-style suffix to the version, then the release(s)
3840
# will be marked as a prerelease.
3941
on:
42+
pull_request:
4043
push:
4144
tags:
4245
- '**[0-9]+.[0-9]+.[0-9]+*'
43-
pull_request:
4446

4547
jobs:
46-
# Run 'cargo dist plan' to determine what tasks we need to do
48+
# Run 'dist plan' (or host) to determine what tasks we need to do
4749
plan:
48-
runs-on: ubuntu-latest
50+
runs-on: "ubuntu-20.04"
4951
outputs:
5052
val: ${{ steps.plan.outputs.manifest }}
5153
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -57,33 +59,48 @@ jobs:
5759
- uses: actions/checkout@v4
5860
with:
5961
submodules: recursive
60-
- name: Install cargo-dist
61-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.0/cargo-dist-installer.sh | sh"
62+
- name: Install dist
63+
# we specify bash to get pipefail; it guards against the `curl` command
64+
# failing. otherwise `sh` won't catch that `curl` returned non-0
65+
shell: bash
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
72+
# sure would be cool if github gave us proper conditionals...
73+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
74+
# functionality based on whether this is a pull_request, and whether it's from a fork.
75+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
76+
# but also really annoying to build CI around when it needs secrets to work right.)
6277
- id: plan
6378
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"
66-
cat dist-manifest.json
67-
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"
6883
- name: "Upload dist-manifest.json"
69-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
7085
with:
71-
name: artifacts
72-
path: dist-manifest.json
86+
name: artifacts-plan-dist-manifest
87+
path: plan-dist-manifest.json
7388

7489
# Build and packages all the platform-specific things
75-
upload-local-artifacts:
90+
build-local-artifacts:
91+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
7692
# 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') }}
93+
needs:
94+
- plan
95+
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') }}
7996
strategy:
8097
fail-fast: false
81-
# Target platforms/runners are computed by cargo-dist in create-release.
98+
# Target platforms/runners are computed by dist in create-release.
8299
# Each member of the matrix has the following arguments:
83100
#
84101
# - runner: the github runner
85-
# - dist-args: cli flags to pass to cargo dist
86-
# - 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
87104
#
88105
# Typically there will be:
89106
# - 1 "global" task that builds universal installers
@@ -94,110 +111,173 @@ jobs:
94111
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95112
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
96113
steps:
114+
- name: enable windows longpaths
115+
run: |
116+
git config --global core.longpaths true
97117
- uses: actions/checkout@v4
98118
with:
99119
submodules: recursive
100-
- uses: swatinem/rust-cache@v2
101-
- name: Install cargo-dist
120+
- name: Install dist
102121
run: ${{ matrix.install_dist }}
122+
# Get the dist-manifest
123+
- name: Fetch local artifacts
124+
uses: actions/download-artifact@v4
125+
with:
126+
pattern: artifacts-*
127+
path: target/distrib/
128+
merge-multiple: true
103129
- name: Install dependencies
104130
run: |
105131
${{ matrix.packages_install }}
106132
- name: Build artifacts
107133
run: |
108134
# Actually do builds and make zips and whatnot
109-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
110-
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"
111137
- id: cargo-dist
112138
name: Post-build
113139
# We force bash here just because github makes it really hard to get values up
114140
# to "real" actions without writing to env-vars, and writing to env-vars has
115141
# inconsistent syntax between shell and powershell.
116142
shell: bash
117143
run: |
118-
# Parse out what we just built and upload it to the Github Release™
144+
# Parse out what we just built and upload it to scratch storage
119145
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
120-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
146+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
121147
echo "EOF" >> "$GITHUB_OUTPUT"
122148
123149
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
124150
- name: "Upload artifacts"
125-
uses: actions/upload-artifact@v3
151+
uses: actions/upload-artifact@v4
126152
with:
127-
name: artifacts
153+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
128154
path: |
129155
${{ steps.cargo-dist.outputs.paths }}
130156
${{ env.BUILD_MANIFEST_NAME }}
131157
132158
# Build and package all the platform-agnostic(ish) things
133-
upload-global-artifacts:
134-
needs: [plan, upload-local-artifacts]
159+
build-global-artifacts:
160+
needs:
161+
- plan
162+
- build-local-artifacts
135163
runs-on: "ubuntu-20.04"
136164
env:
137165
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
166+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
138167
steps:
139168
- uses: actions/checkout@v4
140169
with:
141170
submodules: recursive
142-
- name: Install cargo-dist
143-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.4.0/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
144177
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
145178
- name: Fetch local artifacts
146-
uses: actions/download-artifact@v3
179+
uses: actions/download-artifact@v4
147180
with:
148-
name: artifacts
181+
pattern: artifacts-*
149182
path: target/distrib/
183+
merge-multiple: true
150184
- id: cargo-dist
151185
shell: bash
152186
run: |
153-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
154-
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"
155189
156-
# Parse out what we just built and upload it to the Github Release™
190+
# Parse out what we just built and upload it to scratch storage
157191
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
158-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
192+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
159193
echo "EOF" >> "$GITHUB_OUTPUT"
194+
195+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
160196
- name: "Upload artifacts"
161-
uses: actions/upload-artifact@v3
197+
uses: actions/upload-artifact@v4
162198
with:
163-
name: artifacts
164-
path: ${{ steps.cargo-dist.outputs.paths }}
165-
166-
should-publish:
199+
name: artifacts-build-global
200+
path: |
201+
${{ steps.cargo-dist.outputs.paths }}
202+
${{ env.BUILD_MANIFEST_NAME }}
203+
# Determines if we should publish/announce
204+
host:
167205
needs:
168206
- plan
169-
- upload-local-artifacts
170-
- upload-global-artifacts
171-
if: ${{ needs.plan.outputs.publishing == 'true' }}
172-
runs-on: ubuntu-latest
173-
steps:
174-
- name: print tag
175-
run: echo "ok we're publishing!"
176-
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
207+
- build-local-artifacts
208+
- build-global-artifacts
209+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
210+
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') }}
181211
env:
182212
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
213+
runs-on: "ubuntu-20.04"
214+
outputs:
215+
val: ${{ steps.host.outputs.manifest }}
183216
steps:
184217
- uses: actions/checkout@v4
185218
with:
186219
submodules: recursive
187-
- name: "Download artifacts"
188-
uses: actions/download-artifact@v3
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
226+
# Fetch artifacts from scratch-storage
227+
- name: Fetch artifacts
228+
uses: actions/download-artifact@v4
229+
with:
230+
pattern: artifacts-*
231+
path: target/distrib/
232+
merge-multiple: true
233+
- id: host
234+
shell: bash
235+
run: |
236+
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
237+
echo "artifacts uploaded and released successfully"
238+
cat dist-manifest.json
239+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
240+
- name: "Upload dist-manifest.json"
241+
uses: actions/upload-artifact@v4
242+
with:
243+
# Overwrite the previous copy
244+
name: artifacts-dist-manifest
245+
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
189249
with:
190-
name: artifacts
250+
pattern: artifacts-*
191251
path: artifacts
252+
merge-multiple: true
192253
- name: Cleanup
193254
run: |
194255
# Remove the granular manifests
195-
rm artifacts/*-dist-manifest.json
196-
- name: Create Release
197-
uses: ncipollo/release-action@v1
198-
with:
199-
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 }}
203-
artifacts: "artifacts/*"
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/*
268+
269+
announce:
270+
needs:
271+
- plan
272+
- host
273+
# use "always() && ..." to allow us to wait for all publish jobs while
274+
# still allowing individual publish jobs to skip themselves (for prereleases).
275+
# "host" however must run to completion, no skipping allowed!
276+
if: ${{ always() && needs.host.result == 'success' }}
277+
runs-on: "ubuntu-20.04"
278+
env:
279+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
280+
steps:
281+
- uses: actions/checkout@v4
282+
with:
283+
submodules: recursive

Cargo.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,3 @@ toml = "0.7"
2424
[profile.dist]
2525
inherits = "release"
2626
lto = "thin"
27-
28-
# Config for 'cargo dist'
29-
[workspace.metadata.dist]
30-
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
31-
cargo-dist-version = "0.4.0"
32-
# CI backends to support
33-
ci = ["github"]
34-
# Target platforms to build apps for (Rust target-triple syntax)
35-
targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"]
36-
# The installers to generate for each app
37-
installers = ["shell", "powershell"]
38-
# Publish jobs to run in CI
39-
pr-run-mode = "plan"

dist-workspace.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[workspace]
2+
members = ["cargo:."]
3+
4+
# Config for 'dist'
5+
[dist]
6+
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
7+
cargo-dist-version = "0.25.1"
8+
# CI backends to support
9+
ci = "github"
10+
# Target platforms to build apps for (Rust target-triple syntax)
11+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"]
12+
# The installers to generate for each app
13+
installers = ["shell", "powershell"]
14+
# Which actions to run on pull requests
15+
pr-run-mode = "plan"
16+
# Path that installers should place binaries in
17+
install-path = "CARGO_HOME"
18+
# Whether to install an updater program
19+
install-updater = true

0 commit comments

Comments
 (0)