Skip to content

Release v1.0.0

Release v1.0.0 #5

Workflow file for this run

name: Release
# Tag a release to trigger: git tag v0.1.0 && git push origin v0.1.0
on:
push:
tags: ["v*"]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BINARY: sb1
jobs:
# Build a static-ish binary per platform and attach a tarball to the Release.
binaries:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install cross-linker (Linux aarch64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package
run: |
os=$(echo "${{ matrix.target }}" | grep -q apple && echo darwin || echo linux)
arch=$(echo "${{ matrix.target }}" | cut -d- -f1)
tar -C "target/${{ matrix.target }}/release" -czf "${BINARY}-${os}-${arch}.tar.gz" "${BINARY}"
- uses: softprops/action-gh-release@v2
with:
files: "${{ env.BINARY }}-*.tar.gz"
# Publish to crates.io. Requires the CARGO_REGISTRY_TOKEN repo secret.
# Idempotent: skips if this version is already published (so a manual
# `cargo publish` and the tag-triggered run don't collide).
crates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Publish if this version is not already on crates.io
env:
# cargo reads the token from this env var; passing --token is deprecated.
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
meta=$(cargo metadata --no-deps --format-version 1)
name=$(echo "$meta" | python3 -c "import sys,json;print(json.load(sys.stdin)['packages'][0]['name'])")
version=$(echo "$meta" | python3 -c "import sys,json;print(json.load(sys.stdin)['packages'][0]['version'])")
# Query the crates.io API directly (no index lag). The API rejects
# requests without a User-Agent (403), so send one or the guard below
# never matches and we'd always attempt a redundant publish.
code=$(curl -s -o /dev/null -w "%{http_code}" \
-H "User-Agent: sparebank1-cli release workflow (github.com/magnusrodseth/sparebank1-cli)" \
"https://crates.io/api/v1/crates/$name/$version")
if [ "$code" = "200" ]; then
echo "$name v$version already on crates.io, skipping."
exit 0
fi
# Belt and suspenders: if a manual publish raced this run, treat
# "already exists" as success instead of failing the release.
if ! out=$(cargo publish 2>&1); then
echo "$out"
if echo "$out" | grep -q "already exists"; then
echo "Already on crates.io, treating as success."
exit 0
fi
exit 1
fi
echo "$out"