Skip to content

Commit e49cd65

Browse files
authored
cargo-dist support (#195)
cargo-dist allows to create binary releases
1 parent 45b7bce commit e49cd65

File tree

2 files changed

+283
-0
lines changed

2 files changed

+283
-0
lines changed

.github/workflows/release.yml

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
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+
# * builds artifacts with cargo-dist (archives, installers, hashes)
8+
# * uploads those artifacts to temporary workflow zip
9+
# * on success, uploads the artifacts to a Github Release
10+
#
11+
# Note that the Github Release will be created with a generated
12+
# title/body based on your changelogs.
13+
#
14+
# This file was generated by cargo dist init.
15+
# Some tips you could find here https://opensource.axo.dev/cargo-dist/book
16+
17+
name: Release
18+
19+
permissions:
20+
contents: 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 cargo-dist-able).
30+
#
31+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
32+
# (cargo-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+
push:
45+
tags:
46+
- '**[0-9]+.[0-9]+.[0-9]+*'
47+
48+
jobs:
49+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
50+
plan:
51+
runs-on: ubuntu-latest
52+
outputs:
53+
val: ${{ steps.plan.outputs.manifest }}
54+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
55+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
56+
publishing: ${{ !github.event.pull_request }}
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
steps:
60+
- uses: actions/checkout@v4
61+
with:
62+
submodules: recursive
63+
- name: Install cargo-dist
64+
# we specify bash to get pipefail; it guards against the `curl` command
65+
# failing. otherwise `sh` won't catch that `curl` returned non-0
66+
shell: bash
67+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
68+
# sure would be cool if github gave us proper conditionals...
69+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
70+
# functionality based on whether this is a pull_request, and whether it's from a fork.
71+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
72+
# but also really annoying to build CI around when it needs secrets to work right.)
73+
- id: plan
74+
run: |
75+
cargo dist ${{ !github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name) || (github.event.pull_request.head.repo.fork && 'plan' || 'host --steps=check') }} --output-format=json > dist-manifest.json
76+
echo "cargo dist ran successfully"
77+
cat dist-manifest.json
78+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
79+
- name: "Upload dist-manifest.json"
80+
uses: actions/upload-artifact@v3
81+
with:
82+
name: artifacts
83+
path: dist-manifest.json
84+
85+
# Build and packages all the platform-specific things
86+
build-local-artifacts:
87+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
88+
# Let the initial task tell us to not run (currently very blunt)
89+
needs:
90+
- plan
91+
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') }}
92+
strategy:
93+
fail-fast: false
94+
# Target platforms/runners are computed by cargo-dist in create-release.
95+
# Each member of the matrix has the following arguments:
96+
#
97+
# - runner: the github runner
98+
# - dist-args: cli flags to pass to cargo dist
99+
# - install-dist: expression to run to install cargo-dist on the runner
100+
#
101+
# Typically there will be:
102+
# - 1 "global" task that builds universal installers
103+
# - N "local" tasks that build each platform's binaries and platform-specific installers
104+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
105+
runs-on: ${{ matrix.runner }}
106+
env:
107+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
109+
steps:
110+
- uses: actions/checkout@v4
111+
with:
112+
submodules: recursive
113+
- uses: swatinem/rust-cache@v2
114+
- name: Install cargo-dist
115+
run: ${{ matrix.install_dist }}
116+
# Get the dist-manifest
117+
- name: Fetch local artifacts
118+
uses: actions/download-artifact@v3
119+
with:
120+
name: artifacts
121+
path: target/distrib/
122+
- name: Install dependencies
123+
run: |
124+
${{ matrix.packages_install }}
125+
- name: Build artifacts
126+
run: |
127+
# Actually do builds and make zips and whatnot
128+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
129+
echo "cargo dist ran successfully"
130+
- id: cargo-dist
131+
name: Post-build
132+
# We force bash here just because github makes it really hard to get values up
133+
# to "real" actions without writing to env-vars, and writing to env-vars has
134+
# inconsistent syntax between shell and powershell.
135+
shell: bash
136+
run: |
137+
# Parse out what we just built and upload it to scratch storage
138+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
139+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
140+
echo "EOF" >> "$GITHUB_OUTPUT"
141+
142+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
143+
- name: "Upload artifacts"
144+
uses: actions/upload-artifact@v3
145+
with:
146+
name: artifacts
147+
path: |
148+
${{ steps.cargo-dist.outputs.paths }}
149+
${{ env.BUILD_MANIFEST_NAME }}
150+
151+
# Build and package all the platform-agnostic(ish) things
152+
build-global-artifacts:
153+
needs:
154+
- plan
155+
- build-local-artifacts
156+
runs-on: "ubuntu-20.04"
157+
env:
158+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
159+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
160+
steps:
161+
- uses: actions/checkout@v4
162+
with:
163+
submodules: recursive
164+
- name: Install cargo-dist
165+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
166+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
167+
- name: Fetch local artifacts
168+
uses: actions/download-artifact@v3
169+
with:
170+
name: artifacts
171+
path: target/distrib/
172+
- id: cargo-dist
173+
shell: bash
174+
run: |
175+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
176+
echo "cargo dist ran successfully"
177+
178+
# Parse out what we just built and upload it to scratch storage
179+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
180+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
181+
echo "EOF" >> "$GITHUB_OUTPUT"
182+
183+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
184+
- name: "Upload artifacts"
185+
uses: actions/upload-artifact@v3
186+
with:
187+
name: artifacts
188+
path: |
189+
${{ steps.cargo-dist.outputs.paths }}
190+
${{ env.BUILD_MANIFEST_NAME }}
191+
# Determines if we should publish/announce
192+
host:
193+
needs:
194+
- plan
195+
- build-local-artifacts
196+
- build-global-artifacts
197+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
198+
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') }}
199+
env:
200+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201+
runs-on: "ubuntu-20.04"
202+
outputs:
203+
val: ${{ steps.host.outputs.manifest }}
204+
steps:
205+
- uses: actions/checkout@v4
206+
with:
207+
submodules: recursive
208+
- name: Install cargo-dist
209+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
210+
# Fetch artifacts from scratch-storage
211+
- name: Fetch artifacts
212+
uses: actions/download-artifact@v3
213+
with:
214+
name: artifacts
215+
path: target/distrib/
216+
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
217+
- id: host
218+
shell: bash
219+
run: |
220+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
221+
echo "artifacts uploaded and released successfully"
222+
cat dist-manifest.json
223+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
224+
- name: "Upload dist-manifest.json"
225+
uses: actions/upload-artifact@v3
226+
with:
227+
name: artifacts
228+
path: dist-manifest.json
229+
230+
# Create a Github Release while uploading all files to it
231+
announce:
232+
needs:
233+
- plan
234+
- host
235+
# use "always() && ..." to allow us to wait for all publish jobs while
236+
# still allowing individual publish jobs to skip themselves (for prereleases).
237+
# "host" however must run to completion, no skipping allowed!
238+
if: ${{ always() && needs.host.result == 'success' }}
239+
runs-on: "ubuntu-20.04"
240+
env:
241+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
242+
steps:
243+
- uses: actions/checkout@v4
244+
with:
245+
submodules: recursive
246+
- name: "Download Github Artifacts"
247+
uses: actions/download-artifact@v3
248+
with:
249+
name: artifacts
250+
path: artifacts
251+
- name: Cleanup
252+
run: |
253+
# Remove the granular manifests
254+
rm -f artifacts/*-dist-manifest.json
255+
- name: Create Github Release
256+
uses: ncipollo/release-action@v1
257+
with:
258+
tag: ${{ needs.plan.outputs.tag }}
259+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
260+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
261+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
262+
# Upload only binary release and checksum for it.
263+
artifacts: "artifacts/casr-x86_64-unknown-linux-gnu.tar.xz*"

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@
22
version = "2.10.0"
33
authors = ["Andrey Fedotov <splashgitar@gmail.com>", "Alexey Vishnyakov <pmvishnya@gmail.com>", "Georgy Savidov <avgor46@ispras.ru>", "Ilya Yegorov <Yegorov_Ilya@ispras.ru>", "Darya Parygina <pa_darochek@ispras.ru>"]
44

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.8.0"
9+
# CI backends to support
10+
ci = ["github"]
11+
# The installers to generate for each app
12+
installers = []
13+
# Target platforms to build apps for (Rust target-triple syntax)
14+
targets = ["x86_64-unknown-linux-gnu"]
15+
# Publish jobs to run in CI
16+
pr-run-mode = "skip"
17+
# Whether to pass --all-features to cargo build
18+
all-features = true
19+
allow-dirty = ["ci"]
20+
521
[workspace]
622
resolver = "2"
723
members = ["casr", "libcasr"]
824

925
[profile.release]
1026
lto = true
1127
opt-level = 3
28+
29+
# The profile that 'cargo dist' will build with
30+
[profile.dist]
31+
inherits = "release"

0 commit comments

Comments
 (0)