Skip to content

Commit db6c670

Browse files
authored
Merge pull request #10 from quodlibetor/cargo-dist-binaries
Cargo dist binaries
2 parents aa18202 + 3ed9eef commit db6c670

File tree

7 files changed

+579
-80
lines changed

7 files changed

+579
-80
lines changed

.github/workflows/release.yml

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
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+
pull_request:
45+
46+
jobs:
47+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
48+
plan:
49+
runs-on: ubuntu-latest
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.10.0/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+
- uses: actions/checkout@v4
109+
with:
110+
submodules: recursive
111+
- uses: swatinem/rust-cache@v2
112+
- name: Install cargo-dist
113+
run: ${{ matrix.install_dist }}
114+
# Get the dist-manifest
115+
- name: Fetch local artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
pattern: artifacts-*
119+
path: target/distrib/
120+
merge-multiple: true
121+
- name: Install dependencies
122+
run: |
123+
${{ matrix.packages_install }}
124+
- name: Build artifacts
125+
run: |
126+
# Actually do builds and make zips and whatnot
127+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
128+
echo "cargo dist ran successfully"
129+
- id: cargo-dist
130+
name: Post-build
131+
# We force bash here just because github makes it really hard to get values up
132+
# to "real" actions without writing to env-vars, and writing to env-vars has
133+
# inconsistent syntax between shell and powershell.
134+
shell: bash
135+
run: |
136+
# Parse out what we just built and upload it to scratch storage
137+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
138+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
139+
echo "EOF" >> "$GITHUB_OUTPUT"
140+
141+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
142+
- name: "Upload artifacts"
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
146+
path: |
147+
${{ steps.cargo-dist.outputs.paths }}
148+
${{ env.BUILD_MANIFEST_NAME }}
149+
150+
# Build and package all the platform-agnostic(ish) things
151+
build-global-artifacts:
152+
needs:
153+
- plan
154+
- build-local-artifacts
155+
runs-on: "ubuntu-20.04"
156+
env:
157+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
159+
steps:
160+
- uses: actions/checkout@v4
161+
with:
162+
submodules: recursive
163+
- name: Install cargo-dist
164+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.10.0/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.10.0/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+
publish-homebrew-formula:
233+
needs:
234+
- plan
235+
- host
236+
runs-on: "ubuntu-20.04"
237+
env:
238+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
239+
PLAN: ${{ needs.plan.outputs.val }}
240+
GITHUB_USER: "axo bot"
241+
GITHUB_EMAIL: "[email protected]"
242+
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
243+
steps:
244+
- uses: actions/checkout@v4
245+
with:
246+
repository: "quodlibetor/homebrew-git-fixup"
247+
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
248+
# So we have access to the formula
249+
- name: Fetch local artifacts
250+
uses: actions/download-artifact@v4
251+
with:
252+
pattern: artifacts-*
253+
path: Formula/
254+
merge-multiple: true
255+
- name: Commit formula files
256+
run: |
257+
git config --global user.name "${GITHUB_USER}"
258+
git config --global user.email "${GITHUB_EMAIL}"
259+
260+
for release in $(echo "$PLAN" | jq --compact-output '.releases[]'); do
261+
name=$(echo "$release" | jq .app_name --raw-output)
262+
version=$(echo "$release" | jq .app_version --raw-output)
263+
264+
git add Formula/${name}.rb
265+
git commit -m "${name} ${version}"
266+
done
267+
git push
268+
269+
# Create a Github Release while uploading all files to it
270+
announce:
271+
needs:
272+
- plan
273+
- host
274+
- publish-homebrew-formula
275+
# use "always() && ..." to allow us to wait for all publish jobs while
276+
# still allowing individual publish jobs to skip themselves (for prereleases).
277+
# "host" however must run to completion, no skipping allowed!
278+
if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }}
279+
runs-on: "ubuntu-20.04"
280+
env:
281+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
282+
steps:
283+
- uses: actions/checkout@v4
284+
with:
285+
submodules: recursive
286+
- name: "Download Github Artifacts"
287+
uses: actions/download-artifact@v4
288+
with:
289+
pattern: artifacts-*
290+
path: artifacts
291+
merge-multiple: true
292+
- name: Cleanup
293+
run: |
294+
# Remove the granular manifests
295+
rm -f artifacts/*-dist-manifest.json
296+
- name: Create Github Release
297+
uses: ncipollo/release-action@v1
298+
with:
299+
tag: ${{ needs.plan.outputs.tag }}
300+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
301+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
302+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
303+
artifacts: "artifacts/*"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Version 0.1.9
2+
3+
* CI and doc improvements
4+
* Use libgit2 instead of shelling out for more things.
5+
* Create binaries and install scripts with cargo-dist

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
[package]
22
name = "git-fixup"
3-
version = "0.1.8"
3+
version = "0.1.9-prerelease.5"
44
authors = ["Brandon W Maister <[email protected]>"]
55
edition = "2021"
66
default-run = "git-fixup"
7+
publish = false
8+
repository = "https://github.com/quodlibetor/git-fixup"
9+
description = """Apply staged git changes to an ancestor git commit.
10+
"""
11+
12+
[package.metadata.wix]
13+
upgrade-guid = "F5B771EA-3725-4523-9EE3-06FA112A5573"
14+
path-guid = "A8CD8E47-6A93-4B11-B617-865BFCA4C29F"
15+
license = false
16+
eula = false
717

818
[dependencies]
919
anyhow = "1.0.58"
@@ -16,3 +26,33 @@ git2 = { version = "0.14.4", default_features = false }
1626
assert_cmd = "2.0.4"
1727
assert_fs = "1.0.7"
1828
itertools = "0.10.3"
29+
30+
# The profile that 'cargo dist' will build with
31+
[profile.dist]
32+
inherits = "release"
33+
lto = "thin"
34+
35+
[package.metadata.dist]
36+
dist = true
37+
38+
# Config for 'cargo dist'
39+
[workspace.metadata.dist]
40+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
41+
cargo-dist-version = "0.10.0"
42+
# CI backends to support
43+
ci = ["github"]
44+
# The installers to generate for each app
45+
installers = ["shell", "npm", "homebrew", "msi"]
46+
# A GitHub repo to push Homebrew formulas to
47+
tap = "quodlibetor/homebrew-git-fixup"
48+
# Target platforms to build apps for (Rust target-triple syntax)
49+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl"]
50+
# The archive format to use for windows builds (defaults .zip)
51+
windows-archive = ".tar.gz"
52+
# The archive format to use for non-windows builds (defaults .tar.xz)
53+
unix-archive = ".tar.gz"
54+
# Publish jobs to run in CI
55+
publish-jobs = ["homebrew"]
56+
publish-prerelease = true
57+
# Publish jobs to run in CI
58+
pr-run-mode = "plan"

src/bin/git-rebase-with-intermediates.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)