Files
matcha/.github/workflows/release.yml
T
chrnx a273c249c3
CI / check (pull_request) Successful in 27s
ci: publish to crates.io via OIDC Trusted Publishing (no token)
Replaces CARGO_TOKEN with crates.io Trusted Publishing: id-token: write + rust-lang/crates-io-auth-action exchanges the OIDC token for a short-lived crates.io token. Requires a trusted publisher configured on crates.io (Expressive-Tea/matcha, release.yml).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-07-18 14:54:25 -05:00

106 lines
3.7 KiB
YAML

name: Release
# On a version tag: build cross-platform binaries and attach them to the release (on
# whichever forge fired — the release API calls are portable). ADDITIONALLY, on GitHub
# only (production), publish the crate to crates.io.
on:
push:
tags: ['v*']
permissions:
contents: write
jobs:
# Gitea's delete-asset API differs from GitHub's (it requires the release id in the
# path), so softprops' delete-then-reupload 404s when re-releasing an existing tag.
# Delete the whole release first so every run's uploads are fresh. Portable: the
# get-by-tag + delete-by-id endpoints exist on both Gitea and GitHub, and deleting
# first is harmless on GitHub (softprops just recreates it).
prepare:
runs-on: ubuntu-latest
steps:
- name: Delete existing release for this tag
env:
GT_TOKEN: ${{ github.token }}
run: |
tag="$GITHUB_REF_NAME"
api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
id=$(curl -sSL -H "Authorization: token $GT_TOKEN" "$api/releases/tags/$tag" \
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
if [ -n "${id:-}" ]; then
echo "deleting existing release id=$id for $tag"
curl -sS -X DELETE -H "Authorization: token $GT_TOKEN" "$api/releases/$id" || true
else
echo "no existing release for $tag — nothing to delete"
fi
build:
needs: prepare
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-14
- target: x86_64-apple-darwin
os: macos-14
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Add target + musl tooling
run: |
rustup target add ${{ matrix.target }}
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-musl" ]; then
sudo apt-get update && sudo apt-get install -y musl-tools
fi
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package
run: |
TAR="matcha-${{ matrix.target }}.tar.gz"
tar -czf "$TAR" -C "target/${{ matrix.target }}/release" matcha
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$TAR" > "$TAR.sha256"
else
shasum -a 256 "$TAR" > "$TAR.sha256"
fi
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: |
matcha-${{ matrix.target }}.tar.gz
matcha-${{ matrix.target }}.tar.gz.sha256
# crates.io = production only.
# crates.io = production only, via OIDC Trusted Publishing (no CARGO_TOKEN).
# Requires a trusted publisher configured on crates.io (Expressive-Tea/matcha, release.yml).
publish-crate:
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
# Exchanges the OIDC id-token for a short-lived crates.io token.
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked