Skip to content

Commit d9ee654

Browse files
committed
chore: 🔨 cargo dist
1 parent 442d92a commit d9ee654

File tree

4 files changed

+148
-33
lines changed

4 files changed

+148
-33
lines changed

.github/workflows/release.yml

+128-33
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,140 @@
1-
name: 📦 Release Workflow
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
216

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.
339
on:
4-
release:
5-
types: [created]
40+
push:
41+
tags:
42+
- '*-?v[0-9]+*'
643

744
jobs:
8-
release:
9-
name: 🚀 Release ${{ matrix.target }} on ${{ matrix.os }}
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.67.1 --no-self-update && rustup default 1.67.1
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' }}
1084
strategy:
11-
fail-fast: false
1285
matrix:
86+
# For these target platforms
1387
include:
14-
- os: windows-latest
15-
target: x86_64-pc-windows-gnu
16-
archive: zip
17-
- os: ubuntu-latest
18-
target: x86_64-unknown-linux-gnu
19-
archive: tar.gz
20-
- os: macos-latest
21-
target: x86_64-apple-darwin
22-
archive: zip
88+
- os: ubuntu-20.04
89+
dist-args: --artifacts=global
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: macos-11
92+
dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
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: ubuntu-20.04
95+
dist-args: --artifacts=local --target=x86_64-unknown-linux-gnu
96+
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.7/cargo-dist-installer.sh | sh
97+
- os: windows-2019
98+
dist-args: --artifacts=local --target=x86_64-pc-windows-msvc
99+
install-dist: irm https://github.com/axodotdev/cargo-dist/releases/download/v0.0.7/cargo-dist-installer.ps1 | iex
100+
23101
runs-on: ${{ matrix.os }}
102+
env:
103+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24104
steps:
25-
- uses: actions/checkout@master
105+
- uses: actions/checkout@v3
106+
- name: Install Rust
107+
run: rustup update 1.67.1 --no-self-update && rustup default 1.67.1
108+
- name: Install cargo-dist
109+
run: ${{ matrix.install-dist }}
110+
- name: Run cargo-dist
111+
# This logic is a bit janky because it's trying to be a polyglot between
112+
# powershell and bash since this will run on windows, macos, and linux!
113+
# The two platforms don't agree on how to talk about env vars but they
114+
# do agree on 'cat' and '$()' so we use that to marshal values between commands.
115+
run: |
116+
# Actually do builds and make zips and whatnot
117+
cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json
118+
echo "dist ran successfully"
119+
cat dist-manifest.json
26120
27-
- name: 📥 Compiling
28-
run: cargo build --release --target ${{ matrix.target }}
29-
env:
30-
CARGO_TARGET_DIR: target/${{ matrix.target }}
121+
# Parse out what we just built and upload it to the Github Release™
122+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt
123+
echo "uploading..."
124+
cat uploads.txt
125+
gh release upload ${{ github.ref_name }} $(cat uploads.txt)
126+
echo "uploaded!"
31127
32-
- name: 📦 Create Archive
128+
# Mark the Github Release™ as a non-draft now that everything has succeeded!
129+
publish-release:
130+
# Only run after all the other tasks, but it's ok if upload-artifacts was skipped
131+
needs: [create-release, upload-artifacts]
132+
if: ${{ always() && needs.create-release.result == 'success' && (needs.upload-artifacts.result == 'skipped' || needs.upload-artifacts.result == 'success') }}
133+
runs-on: ubuntu-latest
134+
env:
135+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
136+
steps:
137+
- uses: actions/checkout@v3
138+
- name: mark release as non-draft
33139
run: |
34-
cd target/${{ matrix.target }}/release
35-
if [[ "${{ matrix.archive }}" == "zip" ]]; then
36-
zip -r ${{ matrix.target }}.zip *
37-
else
38-
tar czvf ${{ matrix.target }}.tar.gz *
39-
fi
40-
41-
- name: 📤 Upload Release
42-
uses: softprops/action-gh-release@v1
43-
if: startsWith(github.ref, 'refs/tags/')
44-
with:
45-
files: ${{ matrix.target }}.${{ matrix.archive }}
140+
gh release edit ${{ github.ref_name }} --draft=false

Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
[workspace]
22

33
members = ["client", "server", "common"]
4+
5+
# Config for 'cargo dist'
6+
[workspace.metadata.dist]
7+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
8+
cargo-dist-version = "0.0.7"
9+
# The preferred Rust toolchain to use in CI (rustup toolchain syntax)
10+
rust-toolchain-version = "1.67.1"
11+
# CI backends to support (see 'cargo dist generate-ci')
12+
ci = ["github"]
13+
# The installers to generate for each app
14+
installers = ["shell", "powershell"]
15+
# Target platforms to build apps for (Rust target-triple syntax)
16+
targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "aarch64-apple-darwin"]
17+
18+
# The profile that 'cargo dist' will build with
19+
[profile.dist]
20+
inherits = "release"
21+
lto = "thin"

client/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "fresh-client"
33
version = "1.0.0"
44
authors = ["David Frnoch <[email protected]>"]
55
edition = "2021"
6+
repository = "https://github.com/lnxcz/fresh"
67

78
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
89

server/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "fresh-server"
33
version = "1.0.0"
44
authors = ["David Frnoch <[email protected]>"]
55
edition = "2021"
6+
repository = "https://github.com/lnxcz/fresh"
67

78
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
89

0 commit comments

Comments
 (0)