Skip to content

Commit 0369242

Browse files
committed
ci: create release with cargo-dist
1 parent 16ea6de commit 0369242

File tree

2 files changed

+225
-1
lines changed

2 files changed

+225
-1
lines changed

.github/workflows/release.yml

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

Cargo.toml

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,32 @@ anyhow = "1"
115115
serde = { version = "1", features = ["serde_derive"] }
116116
serde_with = { version = "3.4", features = ["base64"] }
117117
serde_json = "1"
118+
serde-aux = "4"
119+
120+
# local backend
121+
walkdir = "2"
122+
ignore = "0.4"
123+
cached = {version = "0.44", default-features = false, features = ["proc_macro"]}
124+
nix = "0.26"
125+
filetime = "0.2"
126+
127+
# rest backend
128+
reqwest = { version = "0.11", default-features = false, features = [
129+
"json",
130+
"rustls-tls-native-roots",
131+
"stream",
132+
"blocking",
133+
] }
134+
backoff = "0.4"
135+
url = "2.3.1"
136+
137+
# rclone backend
138+
semver = "1"
118139

119140
# other dependencies
120141
aho-corasick = "1.1.2"
121142
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }
122143
rhai = { version = "1.16", features = ["sync", "serde", "no_optimize", "no_module", "no_custom_syntax", "only_i64"] }
123-
semver = "1"
124144
simplelog = "0.12"
125145
comfy-table = "7.1.0"
126146

@@ -158,6 +178,40 @@ pkg-fmt = "tgz"
158178
algorithm = "minisign"
159179
pubkey = "RWSWSCEJEEacVeCy0va71hlrVtiW8YzMzOyJeso0Bfy/ZXq5OryWi/8T"
160180

181+
# Config for 'cargo dist'
182+
[workspace.metadata.dist]
183+
# Include the example config files into the distribution archives
184+
include = ["./config/"]
185+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
186+
cargo-dist-version = "0.1.0"
187+
# CI backends to support (see 'cargo dist generate-ci')
188+
ci = ["github"]
189+
# The installers to generate for each app
190+
installers = ["shell", "powershell"]
191+
# Archive formats to generate for each operating system
192+
unix-archive = ".tar.xz"
193+
windows-archive = ".zip"
194+
# Although cargo-dist was built around the "keep trying" approach, it can be
195+
# it's useful to fail-fast in CI to not waste resources on a failed build
196+
# that we might need to fix first.
197+
fail-fast = true
198+
# Generated checksum
199+
checksum = "sha512"
200+
# The path to install app to
201+
install-path = "~/.rustic/"
202+
# Target platforms to build apps for (Rust target-triple syntax)
203+
targets = [
204+
"x86_64-unknown-linux-gnu",
205+
"x86_64-unknown-linux-musl",
206+
"aarch64-unknown-linux-gnu",
207+
"i686-unknown-linux-gnu",
208+
"x86_64-unknown-netbsd",
209+
"armv7-unknown-linux-gnueabihf",
210+
"x86_64-apple-darwin",
211+
"x86_64-pc-windows-msvc",
212+
"aarch64-apple-darwin",
213+
]
214+
161215
# see: https://nnethercote.github.io/perf-book/build-configuration.html
162216
[profile.dev]
163217
opt-level = 0
@@ -206,3 +260,8 @@ codegen-units = 1
206260
assets = [
207261
{ source = "target/release/rustic", dest = "/usr/bin/rustic", mode = "0755", config = false, doc = false, user = "root", group = "root" },
208262
]
263+
264+
# The profile that 'cargo dist' will build with
265+
[profile.dist]
266+
inherits = "release"
267+
lto = "thin"

0 commit comments

Comments
 (0)