Skip to content

Commit 3d95b2f

Browse files
feat(packaging): integrate cargo-dist
1 parent 6d8102e commit 3d95b2f

File tree

17 files changed

+1288
-10
lines changed

17 files changed

+1288
-10
lines changed

.github/workflows/cd.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
name: Continuous Deployment
44

55
on:
6-
push:
7-
branches: ["main"]
8-
tags:
9-
- "v*"
6+
# push:
7+
# branches: ["main"]
8+
# tags:
9+
# - "v*"
10+
workflow_dispatch:
1011

1112
env:
1213
CARGO_TERM_COLOR: always
@@ -19,6 +20,7 @@ concurrency:
1920
jobs:
2021
build:
2122
name: Build - ${{ matrix.binary}} for ${{ matrix.platform.os_name }}
23+
if: startsWith(github.ref, 'refs/tags/')
2224
strategy:
2325
matrix:
2426
binary: [mecomp-tui, mecomp-cli, mecomp-daemon, mecomp-mpris]
@@ -87,7 +89,7 @@ jobs:
8789
- name: Setup cache
8890
uses: Swatinem/rust-cache@v2
8991
with:
90-
shared-key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
92+
shared-key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
9193

9294
- name: Build binary (Linux)
9395
shell: bash

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
- name: Setup cache
7070
uses: Swatinem/rust-cache@v2
7171
with:
72-
shared-key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
72+
shared-key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
7373

7474
- name: install cargo-nextest
7575
uses: taiki-e/install-action@v2

.github/workflows/codecov-action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Setup cache
3838
uses: Swatinem/rust-cache@v2
3939
with:
40-
shared-key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
40+
shared-key: ${{ runner.os }}-cargo-tarpaulin-${{ hashFiles('**/Cargo.lock') }}
4141

4242
- name: install cargo-tarpaulin
4343
uses: taiki-e/install-action@v2

.github/workflows/publish-crates.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
CARGO_TERM_COLOR: always
1010
RUST_BACKTRACE: "full"
1111

12-
concurrency:
12+
concurrency:
1313
group: Publish-${{ github.ref }}
1414
cancel-in-progress: true
1515

.github/workflows/release.yml

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/
2+
#
3+
# Copyright 2022-2024, axodotdev
4+
# SPDX-License-Identifier: MIT or Apache-2.0
5+
#
6+
# CI that:
7+
#
8+
# * checks for a Git Tag that looks like a release
9+
# * builds artifacts with dist (archives, installers, hashes)
10+
# * uploads those artifacts to temporary workflow zip
11+
# * on success, uploads the artifacts to a GitHub Release
12+
#
13+
# Note that the GitHub Release will be created with a generated
14+
# title/body based on your changelogs.
15+
16+
name: Release
17+
permissions:
18+
"attestations": "write"
19+
"contents": "write"
20+
"id-token": "write"
21+
22+
# This task will run whenever you push a git tag that looks like a version
23+
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
24+
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
25+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
26+
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
27+
#
28+
# If PACKAGE_NAME is specified, then the announcement will be for that
29+
# package (erroring out if it doesn't have the given version or isn't dist-able).
30+
#
31+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
32+
# (dist-able) packages in the workspace with that version (this mode is
33+
# intended for workspaces with only one dist-able package, or with all dist-able
34+
# packages versioned/released in lockstep).
35+
#
36+
# If you push multiple tags at once, separate instances of this workflow will
37+
# spin up, creating an independent announcement for each one. However, GitHub
38+
# will hard limit this to 3 tags per commit, as it will assume more tags is a
39+
# mistake.
40+
#
41+
# If there's a prerelease-style suffix to the version, then the release(s)
42+
# will be marked as a prerelease.
43+
on:
44+
pull_request:
45+
push:
46+
tags:
47+
- '**[0-9]+.[0-9]+.[0-9]+*'
48+
49+
jobs:
50+
# Run 'dist plan' (or host) to determine what tasks we need to do
51+
plan:
52+
runs-on: "ubuntu-22.04"
53+
outputs:
54+
val: ${{ steps.plan.outputs.manifest }}
55+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
56+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
57+
publishing: ${{ !github.event.pull_request }}
58+
env:
59+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
steps:
61+
- uses: actions/checkout@v4
62+
with:
63+
submodules: recursive
64+
- name: Install dist
65+
# we specify bash to get pipefail; it guards against the `curl` command
66+
# failing. otherwise `sh` won't catch that `curl` returned non-0
67+
shell: bash
68+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.28.0/cargo-dist-installer.sh | sh"
69+
- name: Cache dist
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: cargo-dist-cache
73+
path: ~/.cargo/bin/dist
74+
# sure would be cool if github gave us proper conditionals...
75+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
76+
# functionality based on whether this is a pull_request, and whether it's from a fork.
77+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
78+
# but also really annoying to build CI around when it needs secrets to work right.)
79+
- id: plan
80+
run: |
81+
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
82+
echo "dist ran successfully"
83+
cat plan-dist-manifest.json
84+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
85+
- name: "Upload dist-manifest.json"
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: artifacts-plan-dist-manifest
89+
path: plan-dist-manifest.json
90+
91+
# Build and packages all the platform-specific things
92+
build-local-artifacts:
93+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
94+
# Let the initial task tell us to not run (currently very blunt)
95+
needs:
96+
- plan
97+
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') }}
98+
strategy:
99+
fail-fast: false
100+
# Target platforms/runners are computed by dist in create-release.
101+
# Each member of the matrix has the following arguments:
102+
#
103+
# - runner: the github runner
104+
# - dist-args: cli flags to pass to dist
105+
# - install-dist: expression to run to install dist on the runner
106+
#
107+
# Typically there will be:
108+
# - 1 "global" task that builds universal installers
109+
# - N "local" tasks that build each platform's binaries and platform-specific installers
110+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
111+
runs-on: ${{ matrix.runner }}
112+
container: ${{ matrix.container && matrix.container.image || null }}
113+
env:
114+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
116+
steps:
117+
- name: enable windows longpaths
118+
run: |
119+
git config --global core.longpaths true
120+
- uses: actions/checkout@v4
121+
with:
122+
submodules: recursive
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 }}
132+
# Get the dist-manifest
133+
- name: Fetch local artifacts
134+
uses: actions/download-artifact@v4
135+
with:
136+
pattern: artifacts-*
137+
path: target/distrib/
138+
merge-multiple: true
139+
- name: Install dependencies
140+
run: |
141+
${{ matrix.packages_install }}
142+
- name: Build artifacts
143+
run: |
144+
# Actually do builds and make zips and whatnot
145+
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
146+
echo "dist ran successfully"
147+
- name: Attest
148+
uses: actions/attest-build-provenance@v1
149+
with:
150+
subject-path: "target/distrib/*${{ join(matrix.targets, ', ') }}*"
151+
- id: cargo-dist
152+
name: Post-build
153+
# We force bash here just because github makes it really hard to get values up
154+
# to "real" actions without writing to env-vars, and writing to env-vars has
155+
# inconsistent syntax between shell and powershell.
156+
shell: bash
157+
run: |
158+
# Parse out what we just built and upload it to scratch storage
159+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
160+
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
161+
echo "EOF" >> "$GITHUB_OUTPUT"
162+
163+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
164+
- name: "Upload artifacts"
165+
uses: actions/upload-artifact@v4
166+
with:
167+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
168+
path: |
169+
${{ steps.cargo-dist.outputs.paths }}
170+
${{ env.BUILD_MANIFEST_NAME }}
171+
172+
# Build and package all the platform-agnostic(ish) things
173+
build-global-artifacts:
174+
needs:
175+
- plan
176+
- build-local-artifacts
177+
runs-on: "ubuntu-22.04"
178+
env:
179+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
181+
steps:
182+
- uses: actions/checkout@v4
183+
with:
184+
submodules: recursive
185+
- name: Install cached dist
186+
uses: actions/download-artifact@v4
187+
with:
188+
name: cargo-dist-cache
189+
path: ~/.cargo/bin/
190+
- run: chmod +x ~/.cargo/bin/dist
191+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
192+
- name: Fetch local artifacts
193+
uses: actions/download-artifact@v4
194+
with:
195+
pattern: artifacts-*
196+
path: target/distrib/
197+
merge-multiple: true
198+
- id: cargo-dist
199+
shell: bash
200+
run: |
201+
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
202+
echo "dist ran successfully"
203+
204+
# Parse out what we just built and upload it to scratch storage
205+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
206+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
207+
echo "EOF" >> "$GITHUB_OUTPUT"
208+
209+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
210+
- name: "Upload artifacts"
211+
uses: actions/upload-artifact@v4
212+
with:
213+
name: artifacts-build-global
214+
path: |
215+
${{ steps.cargo-dist.outputs.paths }}
216+
${{ env.BUILD_MANIFEST_NAME }}
217+
# Determines if we should publish/announce
218+
host:
219+
needs:
220+
- plan
221+
- build-local-artifacts
222+
- build-global-artifacts
223+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
224+
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') }}
225+
env:
226+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227+
runs-on: "ubuntu-22.04"
228+
outputs:
229+
val: ${{ steps.host.outputs.manifest }}
230+
steps:
231+
- uses: actions/checkout@v4
232+
with:
233+
submodules: recursive
234+
- name: Install cached dist
235+
uses: actions/download-artifact@v4
236+
with:
237+
name: cargo-dist-cache
238+
path: ~/.cargo/bin/
239+
- run: chmod +x ~/.cargo/bin/dist
240+
# Fetch artifacts from scratch-storage
241+
- name: Fetch artifacts
242+
uses: actions/download-artifact@v4
243+
with:
244+
pattern: artifacts-*
245+
path: target/distrib/
246+
merge-multiple: true
247+
- id: host
248+
shell: bash
249+
run: |
250+
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
251+
echo "artifacts uploaded and released successfully"
252+
cat dist-manifest.json
253+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
254+
- name: "Upload dist-manifest.json"
255+
uses: actions/upload-artifact@v4
256+
with:
257+
# Overwrite the previous copy
258+
name: artifacts-dist-manifest
259+
path: dist-manifest.json
260+
# Create a GitHub Release while uploading all files to it
261+
- name: "Download GitHub Artifacts"
262+
uses: actions/download-artifact@v4
263+
with:
264+
pattern: artifacts-*
265+
path: artifacts
266+
merge-multiple: true
267+
- name: Cleanup
268+
run: |
269+
# Remove the granular manifests
270+
rm -f artifacts/*-dist-manifest.json
271+
- name: Create GitHub Release
272+
env:
273+
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
274+
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
275+
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
276+
RELEASE_COMMIT: "${{ github.sha }}"
277+
run: |
278+
# Write and read notes from a file to avoid quoting breaking things
279+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
280+
281+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
282+
283+
announce:
284+
needs:
285+
- plan
286+
- host
287+
# use "always() && ..." to allow us to wait for all publish jobs while
288+
# still allowing individual publish jobs to skip themselves (for prereleases).
289+
# "host" however must run to completion, no skipping allowed!
290+
if: ${{ always() && needs.host.result == 'success' }}
291+
runs-on: "ubuntu-22.04"
292+
env:
293+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
294+
steps:
295+
- uses: actions/checkout@v4
296+
with:
297+
submodules: recursive

.github/workflows/rust-clippy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Setup cache
5555
uses: Swatinem/rust-cache@v2
5656
with:
57-
shared-key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
57+
shared-key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
5858

5959
- name: Install required cargo
6060
run: cargo install clippy-sarif sarif-fmt

.github/workflows/typo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
CARGO_TERM_COLOR: always
1313
RUST_BACKTRACE: "full"
1414

15-
concurrency:
15+
concurrency:
1616
group: Typo-${{ github.ref }}
1717
cancel-in-progress: true
1818

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ rodio.opt-level = 3
8080
inherits = "test"
8181
opt-level = 0
8282

83+
# The profile that 'dist' will build with
84+
[profile.dist]
85+
inherits = "release"
86+
lto = "thin"
87+
8388
[workspace.dependencies]
8489
# shared dependencies
8590
anyhow = { version = "1.0", default-features = false }

0 commit comments

Comments
 (0)