name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (linux only)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build
run: |
if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
- name: Package
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../ritalin-${{ matrix.target }}.tar.gz ritalin
cd -
shasum -a 256 ritalin-${{ matrix.target }}.tar.gz > ritalin-${{ matrix.target }}.tar.gz.sha256
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: |
ritalin-${{ matrix.target }}.tar.gz
ritalin-${{ matrix.target }}.tar.gz.sha256
publish-crate:
name: Publish to crates.io
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
bump-homebrew:
name: Bump Homebrew formula
needs: [build, publish-crate]
runs-on: ubuntu-latest
steps:
- name: Check for deploy key
id: cred
env:
DEPLOY_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
run: |
if [ -n "$DEPLOY_KEY" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
else
echo "::warning::HOMEBREW_TAP_DEPLOY_KEY secret not set — Formula/ritalin.rb in 199-biotechnologies/homebrew-tap must be bumped manually"
fi
- name: Update formula to ${{ github.ref_name }}
if: steps.cred.outputs.present == 'true'
env:
DEPLOY_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
run: |
set -euo pipefail
mkdir -p "$HOME/.ssh" && chmod 700 "$HOME/.ssh"
printf '%s\n' "$DEPLOY_KEY" > "$HOME/.ssh/tap_key"
chmod 600 "$HOME/.ssh/tap_key"
ssh-keyscan -t ed25519 github.com >> "$HOME/.ssh/known_hosts" 2>/dev/null
export GIT_SSH_COMMAND="ssh -i $HOME/.ssh/tap_key -o IdentitiesOnly=yes"
tag="${GITHUB_REF_NAME}"
url="https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/${tag}.tar.gz"
sha=$(curl -sL --fail "$url" | sha256sum | cut -d' ' -f1)
git clone git@github.com:199-biotechnologies/homebrew-tap.git tap
cd tap
sed -i -E "s|^ url \".*\"$| url \"${url}\"|" Formula/ritalin.rb
sed -i -E "s|^ sha256 \".*\"$| sha256 \"${sha}\"|" Formula/ritalin.rb
grep -F "refs/tags/${tag}.tar.gz" Formula/ritalin.rb
grep -F "${sha}" Formula/ritalin.rb
if git diff --quiet; then
echo "Formula already at ${tag}; nothing to push."
exit 0
fi
git config user.name "ritalin-release-bot"
git config user.email "bot@paperfoot.com"
git commit -am "ritalin ${tag}"
git push