Skip to content

Commit 0111ed6

Browse files
add cargo-dist CI
1 parent 31c93fa commit 0111ed6

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

.github/workflows/release.yml

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# CI that:
2+
#
3+
# * checks for a Git Tag that looks like a release
4+
# * creates a Github Release™ and fills in its text
5+
# * builds artifacts with cargo-dist (executable-zips, installers)
6+
# * uploads those artifacts to the Github Release™
7+
#
8+
# Note that the Github Release™ will be created before the artifacts,
9+
# so there will be a few minutes where the release has no artifacts
10+
# and then they will slowly trickle in, possibly failing. To make
11+
# this more pleasant we mark the release as a "draft" until all
12+
# artifacts have been successfully uploaded. This allows you to
13+
# choose what to do with partial successes and avoids spamming
14+
# anyone with notifications before the release is actually ready.
15+
name: Release
16+
17+
permissions:
18+
contents: write
19+
20+
# This task will run whenever you push a git tag that looks like a version
21+
# like "v1", "v1.2.0", "v0.1.0-prerelease01", "my-app-v1.0.0", etc.
22+
# The version will be roughly parsed as ({PACKAGE_NAME}-)?v{VERSION}, where
23+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
24+
# must be a Cargo-style SemVer Version.
25+
#
26+
# If PACKAGE_NAME is specified, then we will create a Github Release™ for that
27+
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
28+
#
29+
# If PACKAGE_NAME isn't specified, then we will create a Github Release™ for all
30+
# (cargo-dist-able) packages in the workspace with that version (this is mode is
31+
# intended for workspaces with only one dist-able package, or with all dist-able
32+
# packages versioned/released in lockstep).
33+
#
34+
# If you push multiple tags at once, separate instances of this workflow will
35+
# spin up, creating an independent Github Release™ for each one.
36+
#
37+
# If there's a prerelease-style suffix to the version then the Github Release™
38+
# will be marked as a prerelease.
39+
on:
40+
push:
41+
tags:
42+
- '*-?v[0-9]+*'
43+
44+
jobs:
45+
# Create the Github Release™ so the packages have something to be uploaded to
46+
create-release:
47+
runs-on: ubuntu-latest
48+
outputs:
49+
has-releases: ${{ steps.create-release.outputs.has-releases }}
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
steps:
53+
- uses: actions/checkout@v3
54+
- name: Install Rust
55+
run: rustup update 1.71.0 --no-self-update && rustup default 1.71.0
56+
- name: Install cargo-dist
57+
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.7/cargo-dist-installer.sh | sh
58+
- id: create-release
59+
run: |
60+
cargo dist plan --tag=${{ github.ref_name }} --output-format=json > dist-manifest.json
61+
echo "dist plan ran successfully"
62+
cat dist-manifest.json
63+
64+
# Create the Github Release™ based on what cargo-dist thinks it should be
65+
ANNOUNCEMENT_TITLE=$(jq --raw-output ".announcement_title" dist-manifest.json)
66+
IS_PRERELEASE=$(jq --raw-output ".announcement_is_prerelease" dist-manifest.json)
67+
jq --raw-output ".announcement_github_body" dist-manifest.json > new_dist_announcement.md
68+
gh release create ${{ github.ref_name }} --draft --prerelease="$IS_PRERELEASE" --title="$ANNOUNCEMENT_TITLE" --notes-file=new_dist_announcement.md
69+
echo "created announcement!"
70+
71+
# Upload the manifest to the Github Release™
72+
gh release upload ${{ github.ref_name }} dist-manifest.json
73+
echo "uploaded manifest!"
74+
75+
# Disable all the upload-artifacts tasks if we have no actual releases
76+
HAS_RELEASES=$(jq --raw-output ".releases != null" dist-manifest.json)
77+
echo "has-releases=$HAS_RELEASES" >> "$GITHUB_OUTPUT"
78+
79+
# Build and packages all the things
80+
upload-artifacts:
81+
# Let the initial task tell us to not run (currently very blunt)
82+
needs: create-release
83+
if: ${{ needs.create-release.outputs.has-releases == 'true' }}
84+
strategy:
85+
matrix:
86+
# For these target platforms
87+
include:
88+
- os: macos-11
89+
dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
90+
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.7/cargo-dist-installer.sh | sh
91+
- os: ubuntu-20.04
92+
dist-args: --artifacts=local --target=x86_64-unknown-linux-gnu
93+
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.7/cargo-dist-installer.sh | sh
94+
- os: windows-2019
95+
dist-args: --artifacts=local --target=x86_64-pc-windows-msvc
96+
install-dist: irm https://github.com/axodotdev/cargo-dist/releases/download/v0.0.7/cargo-dist-installer.ps1 | iex
97+
98+
runs-on: ${{ matrix.os }}
99+
env:
100+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
steps:
102+
- uses: actions/checkout@v3
103+
- name: Install Rust
104+
run: rustup update 1.71.0 --no-self-update && rustup default 1.71.0
105+
- name: Install cargo-dist
106+
run: ${{ matrix.install-dist }}
107+
- name: Run cargo-dist
108+
# This logic is a bit janky because it's trying to be a polyglot between
109+
# powershell and bash since this will run on windows, macos, and linux!
110+
# The two platforms don't agree on how to talk about env vars but they
111+
# do agree on 'cat' and '$()' so we use that to marshal values between commands.
112+
run: |
113+
# Actually do builds and make zips and whatnot
114+
cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json
115+
echo "dist ran successfully"
116+
cat dist-manifest.json
117+
118+
# Parse out what we just built and upload it to the Github Release™
119+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt
120+
echo "uploading..."
121+
cat uploads.txt
122+
gh release upload ${{ github.ref_name }} $(cat uploads.txt)
123+
echo "uploaded!"
124+
125+
# Mark the Github Release™ as a non-draft now that everything has succeeded!
126+
publish-release:
127+
# Only run after all the other tasks, but it's ok if upload-artifacts was skipped
128+
needs: [create-release, upload-artifacts]
129+
if: ${{ always() && needs.create-release.result == 'success' && (needs.upload-artifacts.result == 'skipped' || needs.upload-artifacts.result == 'success') }}
130+
runs-on: ubuntu-latest
131+
env:
132+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
steps:
134+
- uses: actions/checkout@v3
135+
- name: mark release as non-draft
136+
run: |
137+
gh release edit ${{ github.ref_name }} --draft=false

Cargo.toml

+23
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,26 @@ html2text = "0.6.0"
4040
lto = true
4141
strip = true
4242
codegen-units = 1
43+
44+
# The profile that 'cargo dist' will build with
45+
[profile.dist]
46+
inherits = "release"
47+
lto = "thin"
48+
49+
# Config for 'cargo dist'
50+
[workspace.metadata.dist]
51+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
52+
cargo-dist-version = "0.0.7"
53+
# The preferred Rust toolchain to use in CI (rustup toolchain syntax)
54+
rust-toolchain-version = "1.67.1"
55+
# CI backends to support (see 'cargo dist generate-ci')
56+
ci = ["github"]
57+
# The installers to generate for each app
58+
installers = []
59+
# Target platforms to build apps for (Rust target-triple syntax)
60+
targets = [
61+
"x86_64-unknown-linux-gnu",
62+
"x86_64-apple-darwin",
63+
"x86_64-pc-windows-msvc",
64+
"aarch64-apple-darwin",
65+
]

0 commit comments

Comments
 (0)