name: release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
cross: false
- target: x86_64-apple-darwin
os: macos-latest
cross: false
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
cross: true
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
cross: true
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install the pinned toolchain
run: rustup show
- name: Add the target to the PINNED toolchain
run: rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 with:
key: release-${{ matrix.target }}
- name: Install zig and cargo-zigbuild
if: matrix.cross
run: |
python3 -m pip install --break-system-packages ziglang \
|| python3 -m pip install ziglang
python3 -m ziglang version
cargo install cargo-zigbuild --locked
- name: Build
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cargo zigbuild --profile release --locked --bin croft \
--target ${{ matrix.target }}
else
cargo build --profile release --locked --bin croft \
--target ${{ matrix.target }}
fi
- name: The artifact must exist and be the right kind of binary
run: |
set -euo pipefail
bin="target/${{ matrix.target }}/release/croft"
test -x "$bin" || { echo "::error::no artifact at $bin"; exit 1; }
file "$bin"
# Exact triples, not suffixes: a typo in a matrix target then reaches
# the catch-all rather than silently matching `*-linux-musl`.
case "${{ matrix.target }}" in
x86_64-unknown-linux-musl) file "$bin" | grep -qE 'ELF 64-bit LSB.*x86-64' ;;
aarch64-unknown-linux-musl) file "$bin" | grep -qE 'ELF 64-bit LSB.*aarch64' ;;
x86_64-apple-darwin) file "$bin" | grep -qE 'Mach-O 64-bit.*(x86_64|x86-64)' ;;
aarch64-apple-darwin) file "$bin" | grep -qE 'Mach-O 64-bit.*arm64e?' ;;
# A `case` with no match exits 0, so without this arm the whole
# assertion becomes a silent no-op for any target the list does
# not name - green step, unchecked artifact (#551). Adding a
# target now has to add its assertion.
*) echo "::error::no artifact-kind assertion for ${{ matrix.target }}"; exit 1 ;;
esac
- name: Package
id: package
run: |
name="croft-${{ matrix.target }}"
mkdir -p "dist/$name"
cp "target/${{ matrix.target }}/release/croft" "dist/$name/croft"
cp README.md LICENSE "dist/$name/" 2>/dev/null || true
tar -czf "dist/$name.tar.gz" -C dist "$name"
echo "archive=dist/$name.tar.gz" >> "$GITHUB_OUTPUT"
- name: Checksum
run: |
cd dist
if command -v sha256sum >/dev/null; then
sha256sum "croft-${{ matrix.target }}.tar.gz" > "croft-${{ matrix.target }}.tar.gz.sha256"
else
shasum -a 256 "croft-${{ matrix.target }}.tar.gz" > "croft-${{ matrix.target }}.tar.gz.sha256"
fi
cat "croft-${{ matrix.target }}.tar.gz.sha256"
- uses: actions/upload-artifact@v7
with:
name: croft-${{ matrix.target }}
path: |
dist/croft-${{ matrix.target }}.tar.gz
dist/croft-${{ matrix.target }}.tar.gz.sha256
if-no-files-found: error
publish:
name: publish the release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/download-artifact@v8
with:
path: staged
- name: Collect the archives and build SHA256SUMS
run: |
mkdir -p dist
find staged -name 'croft-*.tar.gz' -exec cp {} dist/ \;
cd dist
# Four archives, or the release is incomplete. Publishing three and
# a checksum file that says three is worse than failing: binstall
# would resolve for some users and 404 for others.
count=$(ls -1 croft-*.tar.gz | wc -l | tr -d ' ')
if [ "$count" -ne 4 ]; then
echo "expected 4 archives, found $count:"
ls -1
exit 1
fi
# Build SHA256SUMS from the sums the BUILD runners computed, not
# by re-hashing what arrived here. Re-hashing and then checking
# compares the downloaded bytes against themselves: it passes on a
# corrupted archive, which is the one thing it exists to catch.
# The per-target .sha256 files are the only independent evidence,
# so they are the input.
cat ../staged/*/croft-*.tar.gz.sha256 > SHA256SUMS
cat SHA256SUMS
# `sha256sum -c` verifies the lines that ARE there; it cannot report
# one that is missing. A leg whose .sha256 never arrived would ship
# its archive with no sum and this step would stay green (#557).
# So every archive must be named by exactly one line, and there
# must be no other lines. A bare line count is not enough: one
# duplicated sum plus one missing sum still counts to four.
fail=0
for a in croft-*.tar.gz; do
n=$(awk -v f="$a" '$2 == f || $2 == "*" f' SHA256SUMS | wc -l | tr -d ' ')
if [ "$n" -ne 1 ]; then
echo "::error::SHA256SUMS names $a $n times, expected once"
fail=1
fi
done
lines=$(wc -l < SHA256SUMS | tr -d ' ')
if [ "$lines" -ne "$count" ]; then
echo "::error::SHA256SUMS has $lines lines for $count archives"
fail=1
fi
[ "$fail" -eq 0 ] || exit 1
# Now the check has something to disagree with: these sums were
# produced on the machine that built each artifact, and this runner
# hashes the bytes that actually arrived.
sha256sum -c SHA256SUMS
- uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6
- name: Sign SHA256SUMS
run: |
cosign sign-blob --yes --bundle dist/SHA256SUMS.sigstore.json dist/SHA256SUMS
# Verify with the same identity a user will check, so a signature
# that would not verify for them never ships.
cosign verify-blob \
--bundle dist/SHA256SUMS.sigstore.json \
--certificate-identity "https://github.com/${GITHUB_REPOSITORY}/.github/workflows/release.yml@${GITHUB_REF}" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
dist/SHA256SUMS
- name: Publish
env:
GH_TOKEN: ${{ github.token }}
run: |
tag="${GITHUB_REF#refs/tags/}"
version="${tag#v}"
notes="src/release_notes/$version.md"
if [ -f "$notes" ]; then
gh release create "$tag" --title "$tag" --notes-file "$notes" \
dist/croft-*.tar.gz dist/SHA256SUMS dist/SHA256SUMS.sigstore.json
else
# Every shipped version has a notes file by the release-hygiene
# gate, so a missing one means the tag does not match any version
# that went through it. Say so rather than inventing a body.
echo "no src/release_notes/$version.md for tag $tag" >&2
exit 1
fi
homebrew:
name: bump the Homebrew formula
needs: publish
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Render the formula from the published SHA256SUMS
env:
GH_TOKEN: ${{ github.token }}
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release download "$tag" --pattern SHA256SUMS --dir dist
python3 scripts/homebrew_formula.py "${tag#v}" dist/SHA256SUMS > croft.rb
ruby -c croft.rb
cat croft.rb
- name: Open a pull request against the tap
env:
TAP: vitali87/homebrew-croft
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
if [ -z "$GH_TOKEN" ]; then
echo "::warning::HOMEBREW_TAP_TOKEN is not set; the formula for ${GITHUB_REF#refs/tags/} was rendered above but not proposed to $TAP"
exit 0
fi
version="${GITHUB_REF#refs/tags/v}"
branch="croft-$version"
gh repo clone "$TAP" tap -- --depth 1
cd tap
mkdir -p Formula
cp ../croft.rb Formula/croft.rb
if git diff --quiet -- Formula/croft.rb && git ls-files --error-unmatch Formula/croft.rb >/dev/null 2>&1; then
echo "Formula/croft.rb already describes $version"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$branch"
git add Formula/croft.rb
git commit -m "croft $version"
# gh's credential helper, not a token in the remote URL, so the
# token never lands in .git/config or the log.
gh auth setup-git
git push origin "$branch"
gh pr create --repo "$TAP" --head "$branch" \
--title "croft $version" \
--body "Formula for croft $version, rendered by vitali87/croft's release workflow from the release's signed SHA256SUMS."