Skip to content

Commit f35adb9

Browse files
committed
Update cargo dist
1 parent 6fd10a0 commit f35adb9

File tree

2 files changed

+270
-7
lines changed

2 files changed

+270
-7
lines changed

.github/workflows/release.yml

+265
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
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+
name: Release
15+
16+
permissions:
17+
contents: write
18+
19+
# This task will run whenever you push a git tag that looks like a version
20+
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
21+
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
22+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
23+
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
24+
#
25+
# If PACKAGE_NAME is specified, then the announcement will be for that
26+
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
27+
#
28+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
29+
# (cargo-dist-able) packages in the workspace with that version (this mode is
30+
# intended for workspaces with only one dist-able package, or with all dist-able
31+
# packages versioned/released in lockstep).
32+
#
33+
# If you push multiple tags at once, separate instances of this workflow will
34+
# spin up, creating an independent announcement for each one. However Github
35+
# will hard limit this to 3 tags per commit, as it will assume more tags is a
36+
# mistake.
37+
#
38+
# If there's a prerelease-style suffix to the version, then the release(s)
39+
# will be marked as a prerelease.
40+
on:
41+
push:
42+
tags:
43+
- '**[0-9]+.[0-9]+.[0-9]+*'
44+
45+
jobs:
46+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
47+
plan:
48+
runs-on: ubuntu-latest
49+
outputs:
50+
val: ${{ steps.plan.outputs.manifest }}
51+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
52+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
53+
publishing: ${{ !github.event.pull_request }}
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
submodules: recursive
60+
- name: Install cargo-dist
61+
# we specify bash to get pipefail; it guards against the `curl` command
62+
# failing. otherwise `sh` won't catch that `curl` returned non-0
63+
shell: bash
64+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.2/cargo-dist-installer.sh | sh"
65+
# sure would be cool if github gave us proper conditionals...
66+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
67+
# functionality based on whether this is a pull_request, and whether it's from a fork.
68+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
69+
# but also really annoying to build CI around when it needs secrets to work right.)
70+
- id: plan
71+
run: |
72+
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
73+
echo "cargo dist ran successfully"
74+
cat plan-dist-manifest.json
75+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
76+
- name: "Upload dist-manifest.json"
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: artifacts-plan-dist-manifest
80+
path: plan-dist-manifest.json
81+
82+
# Build and packages all the platform-specific things
83+
build-local-artifacts:
84+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
85+
# Let the initial task tell us to not run (currently very blunt)
86+
needs:
87+
- plan
88+
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') }}
89+
strategy:
90+
fail-fast: false
91+
# Target platforms/runners are computed by cargo-dist in create-release.
92+
# Each member of the matrix has the following arguments:
93+
#
94+
# - runner: the github runner
95+
# - dist-args: cli flags to pass to cargo dist
96+
# - install-dist: expression to run to install cargo-dist on the runner
97+
#
98+
# Typically there will be:
99+
# - 1 "global" task that builds universal installers
100+
# - N "local" tasks that build each platform's binaries and platform-specific installers
101+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
102+
runs-on: ${{ matrix.runner }}
103+
env:
104+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
submodules: recursive
110+
- uses: swatinem/rust-cache@v2
111+
- name: Install cargo-dist
112+
run: ${{ matrix.install_dist }}
113+
# Get the dist-manifest
114+
- name: Fetch local artifacts
115+
uses: actions/download-artifact@v4
116+
with:
117+
pattern: artifacts-*
118+
path: target/distrib/
119+
merge-multiple: true
120+
- name: Install dependencies
121+
run: |
122+
${{ matrix.packages_install }}
123+
- name: Build artifacts
124+
run: |
125+
# Actually do builds and make zips and whatnot
126+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
127+
echo "cargo dist ran successfully"
128+
- id: cargo-dist
129+
name: Post-build
130+
# We force bash here just because github makes it really hard to get values up
131+
# to "real" actions without writing to env-vars, and writing to env-vars has
132+
# inconsistent syntax between shell and powershell.
133+
shell: bash
134+
run: |
135+
# Parse out what we just built and upload it to scratch storage
136+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
137+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
138+
echo "EOF" >> "$GITHUB_OUTPUT"
139+
140+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
141+
- name: "Upload artifacts"
142+
uses: actions/upload-artifact@v4
143+
with:
144+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
145+
path: |
146+
${{ steps.cargo-dist.outputs.paths }}
147+
${{ env.BUILD_MANIFEST_NAME }}
148+
149+
# Build and package all the platform-agnostic(ish) things
150+
build-global-artifacts:
151+
needs:
152+
- plan
153+
- build-local-artifacts
154+
runs-on: "ubuntu-20.04"
155+
env:
156+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
158+
steps:
159+
- uses: actions/checkout@v4
160+
with:
161+
submodules: recursive
162+
- name: Install cargo-dist
163+
shell: bash
164+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.2/cargo-dist-installer.sh | sh"
165+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
166+
- name: Fetch local artifacts
167+
uses: actions/download-artifact@v4
168+
with:
169+
pattern: artifacts-*
170+
path: target/distrib/
171+
merge-multiple: true
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@v4
186+
with:
187+
name: artifacts-build-global
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.12.2/cargo-dist-installer.sh | sh"
210+
# Fetch artifacts from scratch-storage
211+
- name: Fetch artifacts
212+
uses: actions/download-artifact@v4
213+
with:
214+
pattern: artifacts-*
215+
path: target/distrib/
216+
merge-multiple: true
217+
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
218+
- id: host
219+
shell: bash
220+
run: |
221+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
222+
echo "artifacts uploaded and released successfully"
223+
cat dist-manifest.json
224+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
225+
- name: "Upload dist-manifest.json"
226+
uses: actions/upload-artifact@v4
227+
with:
228+
# Overwrite the previous copy
229+
name: artifacts-dist-manifest
230+
path: dist-manifest.json
231+
232+
# Create a Github Release while uploading all files to it
233+
announce:
234+
needs:
235+
- plan
236+
- host
237+
# use "always() && ..." to allow us to wait for all publish jobs while
238+
# still allowing individual publish jobs to skip themselves (for prereleases).
239+
# "host" however must run to completion, no skipping allowed!
240+
if: ${{ always() && needs.host.result == 'success' }}
241+
runs-on: "ubuntu-20.04"
242+
env:
243+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
244+
steps:
245+
- uses: actions/checkout@v4
246+
with:
247+
submodules: recursive
248+
- name: "Download Github Artifacts"
249+
uses: actions/download-artifact@v4
250+
with:
251+
pattern: artifacts-*
252+
path: artifacts
253+
merge-multiple: true
254+
- name: Cleanup
255+
run: |
256+
# Remove the granular manifests
257+
rm -f artifacts/*-dist-manifest.json
258+
- name: Create Github Release
259+
uses: ncipollo/release-action@v1
260+
with:
261+
tag: ${{ needs.plan.outputs.tag }}
262+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
263+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
264+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
265+
artifacts: "artifacts/*"

Cargo.toml

+5-7
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,14 @@ ci = ["github"]
9898
# The installers to generate for each app
9999
installers = []
100100
# Target platforms to build apps for (Rust target-triple syntax)
101-
targets = ["aarch64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
101+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
102102
# Publish jobs to run in CI
103-
pr-run-mode = "plan"
104-
# Skip checking whether the specified configuration files are up to date
105-
allow-dirty = ["ci"]
103+
pr-run-mode = "skip"
104+
105+
[patch.crates-io]
106+
meilisearch-sdk = { git = "https://github.com/gibbz00/meilisearch-rust.git", branch = "request_clients" }
106107

107108
# The profile that 'cargo dist' will build with
108109
[profile.dist]
109110
inherits = "release"
110111
lto = "thin"
111-
112-
[patch.crates-io]
113-
meilisearch-sdk = { git = "https://github.com/gibbz00/meilisearch-rust.git", branch = "request_clients" }

0 commit comments

Comments
 (0)