Skip to content

Commit 1ab6237

Browse files
committed
upgrades cargo-dist version
1 parent 3fbab4e commit 1ab6237

File tree

2 files changed

+143
-43
lines changed

2 files changed

+143
-43
lines changed

.github/workflows/release.yml

+141-41
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# Copyright 2022-2023, axodotdev
1+
# Copyright 2022-2024, axodotdev
22
# SPDX-License-Identifier: MIT or Apache-2.0
33
#
44
# CI that:
55
#
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.4.2/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.13.1/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.
@@ -98,8 +109,17 @@ jobs:
98109
with:
99110
submodules: recursive
100111
- uses: swatinem/rust-cache@v2
112+
with:
113+
key: ${{ join(matrix.targets, '-') }}
101114
- name: Install cargo-dist
102115
run: ${{ matrix.install_dist }}
116+
# Get the dist-manifest
117+
- name: Fetch local artifacts
118+
uses: actions/download-artifact@v4
119+
with:
120+
pattern: artifacts-*
121+
path: target/distrib/
122+
merge-multiple: true
103123
- name: Install dependencies
104124
run: |
105125
${{ matrix.packages_install }}
@@ -115,54 +135,134 @@ jobs:
115135
# inconsistent syntax between shell and powershell.
116136
shell: bash
117137
run: |
118-
# Parse out what we just built and upload it to the Github Release™
138+
# Parse out what we just built and upload it to scratch storage
119139
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
120-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
140+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
121141
echo "EOF" >> "$GITHUB_OUTPUT"
122142
123143
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
124144
- name: "Upload artifacts"
125-
uses: actions/upload-artifact@v3
145+
uses: actions/upload-artifact@v4
126146
with:
127-
name: artifacts
147+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
128148
path: |
129149
${{ steps.cargo-dist.outputs.paths }}
130150
${{ env.BUILD_MANIFEST_NAME }}
131151
132-
should-publish:
152+
# Build and package all the platform-agnostic(ish) things
153+
build-global-artifacts:
133154
needs:
134155
- plan
135-
- upload-local-artifacts
136-
if: ${{ needs.plan.outputs.publishing == 'true' }}
137-
runs-on: ubuntu-latest
156+
- build-local-artifacts
157+
runs-on: "ubuntu-20.04"
158+
env:
159+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
138161
steps:
139-
- name: print tag
140-
run: echo "ok we're publishing!"
162+
- uses: actions/checkout@v4
163+
with:
164+
submodules: recursive
165+
- name: Install cargo-dist
166+
shell: bash
167+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.1/cargo-dist-installer.sh | sh"
168+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
169+
- name: Fetch local artifacts
170+
uses: actions/download-artifact@v4
171+
with:
172+
pattern: artifacts-*
173+
path: target/distrib/
174+
merge-multiple: true
175+
- id: cargo-dist
176+
shell: bash
177+
run: |
178+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
179+
echo "cargo dist ran successfully"
141180
142-
# Create a Github Release with all the results once everything is done
143-
publish-release:
144-
needs: [plan, should-publish]
145-
runs-on: ubuntu-latest
181+
# Parse out what we just built and upload it to scratch storage
182+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
183+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
184+
echo "EOF" >> "$GITHUB_OUTPUT"
185+
186+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
187+
- name: "Upload artifacts"
188+
uses: actions/upload-artifact@v4
189+
with:
190+
name: artifacts-build-global
191+
path: |
192+
${{ steps.cargo-dist.outputs.paths }}
193+
${{ env.BUILD_MANIFEST_NAME }}
194+
# Determines if we should publish/announce
195+
host:
196+
needs:
197+
- plan
198+
- build-local-artifacts
199+
- build-global-artifacts
200+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
201+
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') }}
202+
env:
203+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
204+
runs-on: "ubuntu-20.04"
205+
outputs:
206+
val: ${{ steps.host.outputs.manifest }}
207+
steps:
208+
- uses: actions/checkout@v4
209+
with:
210+
submodules: recursive
211+
- name: Install cargo-dist
212+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.1/cargo-dist-installer.sh | sh"
213+
# Fetch artifacts from scratch-storage
214+
- name: Fetch artifacts
215+
uses: actions/download-artifact@v4
216+
with:
217+
pattern: artifacts-*
218+
path: target/distrib/
219+
merge-multiple: true
220+
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
221+
- id: host
222+
shell: bash
223+
run: |
224+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
225+
echo "artifacts uploaded and released successfully"
226+
cat dist-manifest.json
227+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
228+
- name: "Upload dist-manifest.json"
229+
uses: actions/upload-artifact@v4
230+
with:
231+
# Overwrite the previous copy
232+
name: artifacts-dist-manifest
233+
path: dist-manifest.json
234+
235+
# Create a GitHub Release while uploading all files to it
236+
announce:
237+
needs:
238+
- plan
239+
- host
240+
# use "always() && ..." to allow us to wait for all publish jobs while
241+
# still allowing individual publish jobs to skip themselves (for prereleases).
242+
# "host" however must run to completion, no skipping allowed!
243+
if: ${{ always() && needs.host.result == 'success' }}
244+
runs-on: "ubuntu-20.04"
146245
env:
147246
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148247
steps:
149248
- uses: actions/checkout@v4
150249
with:
151250
submodules: recursive
152-
- name: "Download artifacts"
153-
uses: actions/download-artifact@v3
251+
- name: "Download GitHub Artifacts"
252+
uses: actions/download-artifact@v4
154253
with:
155-
name: artifacts
254+
pattern: artifacts-*
156255
path: artifacts
256+
merge-multiple: true
157257
- name: Cleanup
158258
run: |
159259
# Remove the granular manifests
160-
rm artifacts/*-dist-manifest.json
161-
- name: Create Release
260+
rm -f artifacts/*-dist-manifest.json
261+
- name: Create GitHub Release
162262
uses: ncipollo/release-action@v1
163263
with:
164264
tag: ${{ needs.plan.outputs.tag }}
165-
name: ${{ fromJson(needs.plan.outputs.val).announcement_title }}
166-
body: ${{ fromJson(needs.plan.outputs.val).announcement_github_body }}
167-
prerelease: ${{ fromJson(needs.plan.outputs.val).announcement_is_prerelease }}
265+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
266+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
267+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
168268
artifacts: "artifacts/*"

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ lto = "thin"
2424
# Config for 'cargo dist'
2525
[workspace.metadata.dist]
2626
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
27-
cargo-dist-version = "0.4.2"
27+
cargo-dist-version = "0.13.1"
2828
# CI backends to support
2929
ci = ["github"]
3030
# The installers to generate for each app
3131
installers = []
3232
# Target platforms to build apps for (Rust target-triple syntax)
33-
targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-pc-windows-msvc"]
33+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
3434
# Publish jobs to run in CI
3535
pr-run-mode = "plan"

0 commit comments

Comments
 (0)