Skip to content

Commit 3bddb3b

Browse files
committed
Trying out new release process via cargo dist
1 parent 6bf2200 commit 3bddb3b

File tree

8 files changed

+303
-5
lines changed

8 files changed

+303
-5
lines changed

.github/workflows/release.yml

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

Cargo.toml

+23
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ turbopack-wasi = [
7676
"path:crates/turbo-tasks-build",
7777
]
7878

79+
# Config for 'cargo dist'
80+
[workspace.metadata.dist]
81+
dist = false
82+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
83+
cargo-dist-version = "0.15.1"
84+
# CI backends to support
85+
ci = "github"
86+
# The installers to generate for each app
87+
installers = ["npm"]
88+
# Target platforms to build apps for (Rust target-triple syntax)
89+
targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-musl", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"]
90+
# The archive format to use for windows builds (defaults .zip)
91+
windows-archive = ".tar.gz"
92+
# The archive format to use for non-windows builds (defaults .tar.xz)
93+
unix-archive = ".tar.gz"
94+
# Publish jobs to run in CI
95+
pr-run-mode = "plan"
96+
7997
[workspace.lints.clippy]
8098
too_many_arguments = "allow"
8199

@@ -103,6 +121,11 @@ opt-level = "z"
103121
inherits = "release"
104122
strip = true
105123

124+
# The profile that 'cargo dist' will build with
125+
[profile.dist]
126+
inherits = "release"
127+
lto = "thin"
128+
106129
# Declare dependencies used across workspace packages requires single version bump.
107130
# ref: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace
108131
[workspace.dependencies]

crates/turborepo-lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "turborepo-lib"
3-
version = "0.1.0"
3+
version = "2.0.2-canary.1"
44
edition = "2021"
55
license = "MIT"
66

crates/turborepo-lsp/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ tokio = { workspace = true, features = ["rt-multi-thread", "macros", "io-std"] }
2121
tokio-retry = "0.3.0"
2222
tower-lsp = "0.20.0"
2323
turbopath = { version = "0.1.0", path = "../turborepo-paths" }
24-
turborepo-lib = { version = "0.1.0", path = "../turborepo-lib" }
24+
turborepo-lib = { path = "../turborepo-lib" }
2525
turborepo-repository = { version = "0.1.0", path = "../turborepo-repository" }
2626
wax.workspace = true

crates/turborepo-pidlock/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Paul Hummer <[email protected]>"]
55
license = "MIT"
66
edition = "2021"
77
description = "A library for using pidfiles as resource locks"
8-
repository = "https://github.com/rockstar/pidlock"
8+
# repository = "https://github.com/rockstar/pidlock"
99
keywords = ["pidfile", "file", "filelock", "server", "lock"]
1010
categories = ["filesystem"]
1111
readme = "README.md"

crates/turborepo-vercel-api-mock/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "turborepo-vercel-api-mock"
33
version = "0.1.0"
44
edition = "2021"
55
license = "MIT"
6+
publish = false
67

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

crates/turborepo-wax/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "wax"
33
version = "0.6.0"
44
authors = ["Sean Olson <[email protected]>"]
55
description = "Opinionated and portable globs that can be matched against paths and directory trees."
6-
repository = "https://github.com/olson-sean-k/wax"
6+
# repository = "https://github.com/olson-sean-k/wax"
77
readme = "README.md"
88
edition = "2021"
99
rust-version = "1.66.1"

crates/turborepo/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[package]
22
name = "turbo"
3-
version = "0.1.0"
3+
version = "2.0.2-canary.1"
44
edition = "2021"
55
license = "MIT"
66

7+
[package.metadata.dist]
8+
dist = true
9+
710
[features]
811
# By default, we enable rustls-tls for reqwest via downstream transitive features.
912
# This is for the convenience of running daily dev workflows, i.e running

0 commit comments

Comments
 (0)