Skip to content

Commit 3d5247e

Browse files
committed
Add cross-platform release pipeline
1 parent 7486387 commit 3d5247e

13 files changed

Lines changed: 677 additions & 6 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Publish Homebrew Formula
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: "Stable Trail release tag to publish"
10+
required: true
11+
type: string
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
publish:
18+
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.prerelease }}
19+
runs-on: ubuntu-latest
20+
env:
21+
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.event.release.tag_name }}
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
steps:
24+
- name: Download formula from the GitHub Release
25+
run: |
26+
mkdir -p "${RUNNER_TEMP}/formula"
27+
gh release download "${RELEASE_TAG}" \
28+
--repo "${GITHUB_REPOSITORY}" \
29+
--pattern trail.rb \
30+
--dir "${RUNNER_TEMP}/formula"
31+
ruby -c "${RUNNER_TEMP}/formula/trail.rb"
32+
- name: Check out the Crab Build tap
33+
uses: actions/checkout@v6
34+
with:
35+
repository: crabbuild/homebrew-tap
36+
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
37+
path: homebrew-tap
38+
- name: Commit and push the formula
39+
run: |
40+
mkdir -p homebrew-tap/Formula
41+
install -m 0644 "${RUNNER_TEMP}/formula/trail.rb" homebrew-tap/Formula/trail.rb
42+
cd homebrew-tap
43+
unexpected="$(git status --porcelain | awk '$2 != "Formula/trail.rb"')"
44+
if [[ -n "${unexpected}" ]]; then
45+
echo "Refusing to publish because unrelated tap files changed:"
46+
echo "${unexpected}"
47+
exit 1
48+
fi
49+
if git diff --quiet -- Formula/trail.rb && \
50+
git ls-files --error-unmatch Formula/trail.rb >/dev/null 2>&1; then
51+
echo "Formula/trail.rb is already current"
52+
exit 0
53+
fi
54+
git config user.name "Crab Build Release Bot"
55+
git config user.email "[email protected]"
56+
git add Formula/trail.rb
57+
git commit -m "trail ${RELEASE_TAG#v}"
58+
git push
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release Readiness
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "Cargo.toml"
7+
- "Cargo.lock"
8+
- "trail/Cargo.toml"
9+
- "trail/src/cli/command.rs"
10+
- "CHANGELOG.md"
11+
- "RELEASING.md"
12+
- ".github/workflows/release.yml"
13+
- ".github/workflows/publish-homebrew.yml"
14+
- ".github/workflows/release-readiness.yml"
15+
workflow_dispatch:
16+
17+
jobs:
18+
package-smoke:
19+
name: Package smoke (${{ matrix.os }})
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
os: [ubuntu-latest, macos-latest, windows-latest]
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- uses: actions/checkout@v6
27+
with:
28+
submodules: recursive
29+
- uses: dtolnay/rust-toolchain@stable
30+
- uses: Swatinem/rust-cache@v2
31+
- name: Build release binary
32+
run: cargo build --locked -p trail --profile dist
33+
- name: Verify packaged CLI
34+
shell: bash
35+
run: |
36+
set -euo pipefail
37+
suffix=""
38+
if [[ "${RUNNER_OS}" == "Windows" ]]; then
39+
suffix=".exe"
40+
fi
41+
binary="${PWD}/target/dist/trail${suffix}"
42+
expected="$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\([^"]*\)"/\1/p' Cargo.toml)"
43+
actual="$("${binary}" --version)"
44+
test "${actual}" = "trail ${expected}"
45+
"${binary}" --help >/dev/null
46+
47+
smoke_dir="$(mktemp -d)"
48+
trap 'rm -rf "${smoke_dir}"' EXIT
49+
cd "${smoke_dir}"
50+
printf 'release smoke test\n' > README.md
51+
"${binary}" init --working-tree
52+
"${binary}" status
53+
54+
dist-plan:
55+
name: Generated release workflow is current
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v6
59+
with:
60+
submodules: recursive
61+
- name: Install pinned dist
62+
shell: bash
63+
run: |
64+
curl --proto '=https' --tlsv1.2 -LsSf \
65+
https://github.com/axodotdev/cargo-dist/releases/download/v0.32.0/cargo-dist-installer.sh | sh
66+
- name: Check release configuration
67+
run: |
68+
dist generate --mode=ci --check
69+
dist plan --tag="v$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\([^"]*\)"/\1/p' Cargo.toml)"

0 commit comments

Comments
 (0)