Skip to content

Commit 1506544

Browse files
authored
Merge pull request #226 from rust-secure-code/update-dist
Update dist
2 parents 0bfbeca + 8d44726 commit 1506544

File tree

2 files changed

+82
-57
lines changed

2 files changed

+82
-57
lines changed

.github/workflows/release.yml

Lines changed: 76 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
# This file was autogenerated by dist: https://axodotdev.github.io/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

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,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
#
@@ -38,15 +39,15 @@ permissions:
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-22.04"
5051
outputs:
5152
val: ${{ steps.plan.outputs.manifest }}
5253
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -57,21 +58,27 @@ jobs:
5758
steps:
5859
- uses: actions/checkout@v4
5960
with:
61+
persist-credentials: false
6062
submodules: recursive
61-
- name: Install cargo-dist
63+
- name: Install dist
6264
# we specify bash to get pipefail; it guards against the `curl` command
6365
# failing. otherwise `sh` won't catch that `curl` returned non-0
6466
shell: bash
65-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh"
67+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.30.0/cargo-dist-installer.sh | sh"
68+
- name: Cache dist
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: cargo-dist-cache
72+
path: ~/.cargo/bin/dist
6673
# sure would be cool if github gave us proper conditionals...
6774
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
6875
# functionality based on whether this is a pull_request, and whether it's from a fork.
6976
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
7077
# but also really annoying to build CI around when it needs secrets to work right.)
7178
- id: plan
7279
run: |
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"
80+
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
81+
echo "dist ran successfully"
7582
cat plan-dist-manifest.json
7683
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
7784
- name: "Upload dist-manifest.json"
@@ -89,18 +96,19 @@ jobs:
8996
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') }}
9097
strategy:
9198
fail-fast: false
92-
# Target platforms/runners are computed by cargo-dist in create-release.
99+
# Target platforms/runners are computed by dist in create-release.
93100
# Each member of the matrix has the following arguments:
94101
#
95102
# - 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
103+
# - dist-args: cli flags to pass to dist
104+
# - install-dist: expression to run to install dist on the runner
98105
#
99106
# Typically there will be:
100107
# - 1 "global" task that builds universal installers
101108
# - N "local" tasks that build each platform's binaries and platform-specific installers
102109
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
103110
runs-on: ${{ matrix.runner }}
111+
container: ${{ matrix.container && matrix.container.image || null }}
104112
env:
105113
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106114
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
@@ -110,12 +118,17 @@ jobs:
110118
git config --global core.longpaths true
111119
- uses: actions/checkout@v4
112120
with:
121+
persist-credentials: false
113122
submodules: recursive
114-
- uses: swatinem/rust-cache@v2
115-
with:
116-
key: ${{ join(matrix.targets, '-') }}
117-
- name: Install cargo-dist
118-
run: ${{ matrix.install_dist }}
123+
- name: Install Rust non-interactively if not already installed
124+
if: ${{ matrix.container }}
125+
run: |
126+
if ! command -v cargo > /dev/null 2>&1; then
127+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
128+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
129+
fi
130+
- name: Install dist
131+
run: ${{ matrix.install_dist.run }}
119132
# Get the dist-manifest
120133
- name: Fetch local artifacts
121134
uses: actions/download-artifact@v4
@@ -129,8 +142,8 @@ jobs:
129142
- name: Build artifacts
130143
run: |
131144
# Actually do builds and make zips and whatnot
132-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
133-
echo "cargo dist ran successfully"
145+
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
146+
echo "dist ran successfully"
134147
- id: cargo-dist
135148
name: Post-build
136149
# We force bash here just because github makes it really hard to get values up
@@ -140,7 +153,7 @@ jobs:
140153
run: |
141154
# Parse out what we just built and upload it to scratch storage
142155
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
143-
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
156+
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
144157
echo "EOF" >> "$GITHUB_OUTPUT"
145158
146159
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -164,10 +177,14 @@ jobs:
164177
steps:
165178
- uses: actions/checkout@v4
166179
with:
180+
persist-credentials: false
167181
submodules: recursive
168-
- name: Install cargo-dist
169-
shell: bash
170-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh"
182+
- name: Install cached dist
183+
uses: actions/download-artifact@v4
184+
with:
185+
name: cargo-dist-cache
186+
path: ~/.cargo/bin/
187+
- run: chmod +x ~/.cargo/bin/dist
171188
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
172189
- name: Fetch local artifacts
173190
uses: actions/download-artifact@v4
@@ -178,8 +195,8 @@ jobs:
178195
- id: cargo-dist
179196
shell: bash
180197
run: |
181-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
182-
echo "cargo dist ran successfully"
198+
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
199+
echo "dist ran successfully"
183200
184201
# Parse out what we just built and upload it to scratch storage
185202
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
@@ -210,21 +227,25 @@ jobs:
210227
steps:
211228
- uses: actions/checkout@v4
212229
with:
230+
persist-credentials: false
213231
submodules: recursive
214-
- name: Install cargo-dist
215-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh"
232+
- name: Install cached dist
233+
uses: actions/download-artifact@v4
234+
with:
235+
name: cargo-dist-cache
236+
path: ~/.cargo/bin/
237+
- run: chmod +x ~/.cargo/bin/dist
216238
# Fetch artifacts from scratch-storage
217239
- name: Fetch artifacts
218240
uses: actions/download-artifact@v4
219241
with:
220242
pattern: artifacts-*
221243
path: target/distrib/
222244
merge-multiple: true
223-
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
224245
- id: host
225246
shell: bash
226247
run: |
227-
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
248+
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
228249
echo "artifacts uploaded and released successfully"
229250
cat dist-manifest.json
230251
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
@@ -234,8 +255,29 @@ jobs:
234255
# Overwrite the previous copy
235256
name: artifacts-dist-manifest
236257
path: dist-manifest.json
258+
# Create a GitHub Release while uploading all files to it
259+
- name: "Download GitHub Artifacts"
260+
uses: actions/download-artifact@v4
261+
with:
262+
pattern: artifacts-*
263+
path: artifacts
264+
merge-multiple: true
265+
- name: Cleanup
266+
run: |
267+
# Remove the granular manifests
268+
rm -f artifacts/*-dist-manifest.json
269+
- name: Create GitHub Release
270+
env:
271+
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
272+
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
273+
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
274+
RELEASE_COMMIT: "${{ github.sha }}"
275+
run: |
276+
# Write and read notes from a file to avoid quoting breaking things
277+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
278+
279+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
237280
238-
# Create a GitHub Release while uploading all files to it
239281
announce:
240282
needs:
241283
- plan
@@ -250,22 +292,5 @@ jobs:
250292
steps:
251293
- uses: actions/checkout@v4
252294
with:
295+
persist-credentials: false
253296
submodules: recursive
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-
uses: ncipollo/release-action@v1
266-
with:
267-
tag: ${{ needs.plan.outputs.tag }}
268-
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
269-
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
270-
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
271-
artifacts: "artifacts/*"

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ members = [
1010
"resolverver",
1111
]
1212

13-
# Config for 'cargo dist'
13+
# Config for 'dist'
1414
[workspace.metadata.dist]
15-
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
16-
cargo-dist-version = "0.14.1"
15+
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
16+
cargo-dist-version = "0.30.0"
1717
# CI backends to support
1818
ci = "github"
1919
# The installers to generate for each app
2020
installers = ["shell", "powershell"]
2121
# Target platforms to build apps for (Rust target-triple syntax)
2222
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"]
23-
# Publish jobs to run in CI
23+
# Which actions to run on pull requests
2424
pr-run-mode = "plan"
2525
# Whether to install an updater program
2626
install-updater = false
27-
# Suppress dist failure because we bumped ubuntu-20.04 to ubuntu-22.04
28-
allow-dirty = ["ci"]
27+
# Path that installers should place binaries in
28+
install-path = "CARGO_HOME"
2929

3030
# The profile that 'cargo dist' will build with
3131
[profile.dist]

0 commit comments

Comments
 (0)