Skip to content

Commit 738644f

Browse files
authored
bump cargo-dist (#2790)
1 parent ea3b4a0 commit 738644f

File tree

3 files changed

+130
-54
lines changed

3 files changed

+130
-54
lines changed

.github/workflows/release.yml

+126-51
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# * checks for a Git Tag that looks like a release
77
# * builds artifacts with cargo-dist (archives, installers, hashes)
88
# * uploads those artifacts to temporary workflow zip
9-
# * on success, uploads the artifacts to a Github Release
9+
# * on success, uploads the artifacts to a Github Release
1010
#
11-
# Note that the Github Release will be created with a generated
11+
# Note that the Github Release will be created with a generated
1212
# title/body based on your changelogs.
13+
1314
name: Release
1415

1516
permissions:
@@ -21,20 +22,20 @@ permissions:
2122
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
2223
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
2324
#
24-
# If PACKAGE_NAME is specified, then the release will be for that
25+
# If PACKAGE_NAME is specified, then the announcement will be for that
2526
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
2627
#
27-
# If PACKAGE_NAME isn't specified, then the release will be for all
28+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
2829
# (cargo-dist-able) packages in the workspace with that version (this mode is
2930
# intended for workspaces with only one dist-able package, or with all dist-able
3031
# packages versioned/released in lockstep).
3132
#
3233
# 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
34+
# spin up, creating an independent announcement for each one. However Github
3435
# will hard limit this to 3 tags per commit, as it will assume more tags is a
3536
# mistake.
3637
#
37-
# If there's a prerelease-style suffix to the version, then the Github Release™
38+
# If there's a prerelease-style suffix to the version, then the release(s)
3839
# will be marked as a prerelease.
3940
on:
4041
push:
@@ -43,7 +44,7 @@ on:
4344
pull_request:
4445

4546
jobs:
46-
# Run 'cargo dist plan' to determine what tasks we need to do
47+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
4748
plan:
4849
runs-on: ubuntu-latest
4950
outputs:
@@ -58,24 +59,34 @@ jobs:
5859
with:
5960
submodules: recursive
6061
- name: Install cargo-dist
61-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh"
62+
# we specify bash to get pipefail; it guards against the `curl` command
63+
# failing. otherwise `sh` won't catch that `curl` returned non-0
64+
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"
66+
# sure would be cool if github gave us proper conditionals...
67+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
68+
# functionality based on whether this is a pull_request, and whether it's from a fork.
69+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
70+
# but also really annoying to build CI around when it needs secrets to work right.)
6271
- id: plan
6372
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"
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"
75+
cat plan-dist-manifest.json
76+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
6877
- name: "Upload dist-manifest.json"
69-
uses: actions/upload-artifact@v3
78+
uses: actions/upload-artifact@v4
7079
with:
71-
name: artifacts
72-
path: dist-manifest.json
80+
name: artifacts-plan-dist-manifest
81+
path: plan-dist-manifest.json
7382

7483
# Build and packages all the platform-specific things
75-
upload-local-artifacts:
84+
build-local-artifacts:
85+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
7686
# 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') }}
87+
needs:
88+
- plan
89+
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') }}
7990
strategy:
8091
fail-fast: false
8192
# Target platforms/runners are computed by cargo-dist in create-release.
@@ -92,17 +103,28 @@ jobs:
92103
runs-on: ${{ matrix.runner }}
93104
env:
94105
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
95107
steps:
96108
- uses: actions/checkout@v4
97109
with:
98110
submodules: recursive
99111
- uses: swatinem/rust-cache@v2
100112
- name: Install cargo-dist
101113
run: ${{ matrix.install_dist }}
114+
# Get the dist-manifest
115+
- name: Fetch local artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
pattern: artifacts-*
119+
path: target/distrib/
120+
merge-multiple: true
121+
- name: Install dependencies
122+
run: |
123+
${{ matrix.packages_install }}
102124
- name: Build artifacts
103125
run: |
104126
# Actually do builds and make zips and whatnot
105-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
127+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
106128
echo "cargo dist ran successfully"
107129
- id: cargo-dist
108130
name: Post-build
@@ -111,81 +133,134 @@ jobs:
111133
# inconsistent syntax between shell and powershell.
112134
shell: bash
113135
run: |
114-
# Parse out what we just built and upload it to the Github Release™
136+
# Parse out what we just built and upload it to scratch storage
115137
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
116138
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
117139
echo "EOF" >> "$GITHUB_OUTPUT"
140+
141+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
118142
- name: "Upload artifacts"
119-
uses: actions/upload-artifact@v3
143+
uses: actions/upload-artifact@v4
120144
with:
121-
name: artifacts
122-
path: ${{ steps.cargo-dist.outputs.paths }}
145+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
146+
path: |
147+
${{ steps.cargo-dist.outputs.paths }}
148+
${{ env.BUILD_MANIFEST_NAME }}
123149
124150
# Build and package all the platform-agnostic(ish) things
125-
upload-global-artifacts:
126-
needs: [plan, upload-local-artifacts]
151+
build-global-artifacts:
152+
needs:
153+
- plan
154+
- build-local-artifacts
127155
runs-on: "ubuntu-20.04"
128156
env:
129157
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
130159
steps:
131160
- uses: actions/checkout@v4
132161
with:
133162
submodules: recursive
134163
- name: Install cargo-dist
135-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh"
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"
136166
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
137167
- name: Fetch local artifacts
138-
uses: actions/download-artifact@v3
168+
uses: actions/download-artifact@v4
139169
with:
140-
name: artifacts
170+
pattern: artifacts-*
141171
path: target/distrib/
172+
merge-multiple: true
142173
- id: cargo-dist
143174
shell: bash
144175
run: |
145176
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
146177
echo "cargo dist ran successfully"
147178
148-
# Parse out what we just built and upload it to the Github Release™
179+
# Parse out what we just built and upload it to scratch storage
149180
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
150181
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
151182
echo "EOF" >> "$GITHUB_OUTPUT"
183+
184+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
152185
- name: "Upload artifacts"
153-
uses: actions/upload-artifact@v3
186+
uses: actions/upload-artifact@v4
154187
with:
155-
name: artifacts
156-
path: ${{ steps.cargo-dist.outputs.paths }}
157-
158-
should-publish:
188+
name: artifacts-build-global
189+
path: |
190+
${{ steps.cargo-dist.outputs.paths }}
191+
${{ env.BUILD_MANIFEST_NAME }}
192+
# Determines if we should publish/announce
193+
host:
159194
needs:
160195
- plan
161-
- upload-local-artifacts
162-
- upload-global-artifacts
163-
if: ${{ needs.plan.outputs.publishing == 'true' }}
164-
runs-on: ubuntu-latest
196+
- build-local-artifacts
197+
- 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') }}
200+
env:
201+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
202+
runs-on: "ubuntu-20.04"
203+
outputs:
204+
val: ${{ steps.host.outputs.manifest }}
165205
steps:
166-
- name: print tag
167-
run: echo "ok we're publishing!"
206+
- uses: actions/checkout@v4
207+
with:
208+
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"
211+
# Fetch artifacts from scratch-storage
212+
- name: Fetch artifacts
213+
uses: actions/download-artifact@v4
214+
with:
215+
pattern: artifacts-*
216+
path: target/distrib/
217+
merge-multiple: true
218+
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
219+
- id: host
220+
shell: bash
221+
run: |
222+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
223+
echo "artifacts uploaded and released successfully"
224+
cat dist-manifest.json
225+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
226+
- name: "Upload dist-manifest.json"
227+
uses: actions/upload-artifact@v4
228+
with:
229+
# Overwrite the previous copy
230+
name: artifacts-dist-manifest
231+
path: dist-manifest.json
168232

169-
# Create a Github Release with all the results once everything is done,
170-
publish-release:
171-
needs: [plan, should-publish]
172-
runs-on: ubuntu-latest
233+
# Create a Github Release while uploading all files to it
234+
announce:
235+
needs:
236+
- plan
237+
- host
238+
# use "always() && ..." to allow us to wait for all publish jobs while
239+
# still allowing individual publish jobs to skip themselves (for prereleases).
240+
# "host" however must run to completion, no skipping allowed!
241+
if: ${{ always() && needs.host.result == 'success' }}
242+
runs-on: "ubuntu-20.04"
173243
env:
174244
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175245
steps:
176246
- uses: actions/checkout@v4
177247
with:
178248
submodules: recursive
179-
- name: "Download artifacts"
180-
uses: actions/download-artifact@v3
249+
- name: "Download Github Artifacts"
250+
uses: actions/download-artifact@v4
181251
with:
182-
name: artifacts
252+
pattern: artifacts-*
183253
path: artifacts
184-
- name: Create Release
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
185260
uses: ncipollo/release-action@v1
186261
with:
187262
tag: ${{ needs.plan.outputs.tag }}
188-
name: ${{ fromJson(needs.plan.outputs.val).announcement_title }}
189-
body: ${{ fromJson(needs.plan.outputs.val).announcement_github_body }}
190-
prerelease: ${{ fromJson(needs.plan.outputs.val).announcement_is_prerelease }}
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 }}
191266
artifacts: "artifacts/*"

CONTRIBUTING.md

-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ when a new cargo-dist is available:
595595

596596
```
597597
cargo dist init # from "cargo install cargo-dist"
598-
cargo dist generate-ci # to update .github/workflows/release.yml
599598
```
600599

601600
### What to do if a Github release fails

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ default-members = [
1717
# Config for 'cargo dist'
1818
[workspace.metadata.dist]
1919
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
20-
cargo-dist-version = "0.3.1"
20+
cargo-dist-version = "0.12.0"
2121
# CI backends to support
2222
ci = ["github"]
2323
# The installers to generate for each app
2424
installers = ["shell", "powershell"]
2525
# Target platforms to build apps for (Rust target-triple syntax)
26-
targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin"]
26+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]
2727
# Whether to consider the binaries in a package for distribution (defaults true)
2828
dist = false
2929
# Publish jobs to run in CI
3030
pr-run-mode = "plan"
31+
# Whether to install an updater program
32+
install-updater = false
3133

3234
# Config for 'cargo release'
3335
[workspace.metadata.release]

0 commit comments

Comments
 (0)