Files
matcha/.github/workflows/release.yml
T
chrnx 483cc23dea
CI / installer (macos-14) (pull_request) Successful in 3s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Successful in 30s
CI / starter (deno) (pull_request) Successful in 31s
CI / starter (edge) (pull_request) Successful in 36s
CI / starter (node) (pull_request) Successful in 32s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 10s
ci: make this forge the gate it was meant to be, and stop pushing every tag
Two problems in one place, one of them latent since before this release.

`promote.yml` and `release.yml` both fired on the same `v*` tag push, so Gitea
started building and handed the tag to GitHub at the same moment — and the tag
arriving there is what starts GitHub's build and its crates.io publish. The local
build was therefore a parallel opinion rather than a check: by the time it could
have said no, the crate was already going out, and crates.io has no unpublish,
only yank. Tag promotion moves into `release.yml` behind `needs: build`, so the
sequence is what it was always described as — Gitea builds all four targets and
runs every artifact it can, and only then does GitHub hear about the tag.

`promote.yml` also ran `git push github --tags` on every push to `main`, which
has been failing every time. The tags diverged before this: `v26.7.0` points at
`371c5f7` here and `2a3dae9` there, and `v26.8.0-beta.0` is annotated here and
lightweight there — so the push is a non-fast-forward on refs that already exist.
`main` itself was pushed by the line above and always succeeded, so the job went
red while its actual work had already been done, which is the worst shape a CI
failure can take: permanent, and therefore ignored on the day it means something.
Dropped rather than forced, because reconciling the divergence rewrites what a
published tag points at — a decision, not a fix. New tags are unaffected; they go
through `release.yml` now.

Branched from `main` rather than `develop` so it is active for the v26.9.0-beta.0
tag, and so merging it back carries the release's version bump to `develop` with
it.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-05 17:32:30 -05:00

219 lines
9.4 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
- target: aarch64-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
run: rustup target add ${{ matrix.target }}
# Both Linux targets go through zig rather than through apt's musl-tools.
# `tree-sitter` and `tree-sitter-typescript` compile C with the `cc` crate,
# so `rustup target add` alone cannot produce an aarch64 binary — a real
# cross C toolchain is required, and Ubuntu ships none for aarch64 musl.
# zig is one, for both arches, which is also why the x86_64 leg moved onto
# it: one toolchain for Linux beats a working one plus a second one.
- name: Install zig cross toolchain
if: contains(matrix.target, 'linux')
run: |
# `--break-system-packages` is required from pip 23 (PEP 668) and is an
# unknown flag before it, so try the plain form first.
python3 -m pip install --user ziglang \
|| python3 -m pip install --user --break-system-packages ziglang
cargo install --locked cargo-zigbuild
- name: Build (Linux, cross via zig)
if: contains(matrix.target, 'linux')
run: cargo zigbuild --release --locked --target ${{ matrix.target }}
- name: Build (macOS)
if: contains(matrix.target, 'darwin')
run: cargo build --release --locked --target ${{ matrix.target }}
# Run the artifact wherever the runner can actually execute it, and say so
# where it cannot. A binary that links and will not start is the failure a
# release pipeline must not leave for a user's terminal to find.
#
# A matching architecture always can. An x86_64 macOS binary on the arm64
# macOS runners can too — through Rosetta, which is a system component
# shared by every user on the host, so the runner account inherits it. It
# is probed rather than assumed: a hosted runner may not have it, and a
# smoke that hard-failed there would block a release over the runner's
# configuration rather than over the binary.
#
# Across the two forges that leaves nothing unexecuted. Gitea's
# `ubuntu-latest` is arm64 Linux (containers in a colima VM on the macOS
# host), so it runs the aarch64 binary; GitHub's is x86_64 and runs the
# other. Both macOS binaries run on either forge's arm64 macOS runner.
- name: Smoke the binary
shell: bash
run: |
target='${{ matrix.target }}'
arch='${{ runner.arch }}'
bin="./target/$target/release/matcha"
runnable=no
case "$target:$arch" in
aarch64-*:ARM64|x86_64-*:X64) runnable=yes ;;
x86_64-apple-darwin:ARM64)
# An `if` rather than `[ … ] && …`: under `set -e` the AND-list's
# failure is the case branch's exit status, and whether that ends
# the step is a subtlety of the shell rather than a decision. A
# missing Rosetta must skip the smoke, never fail the release.
if [ -d /Library/Apple/usr/libexec/oah ]; then runnable=yes; fi ;;
esac
if [ "$runnable" = yes ]; then
"$bin" --version
else
echo "::notice::smoke skipped: this $arch runner cannot execute $target"
fi
- 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:
# A tag with a hyphen is a prerelease (26.9.0-beta.1). Unflagged, it
# would answer /releases/latest — which is what install.sh resolves
# with no MATCHA_VERSION — so the first stable release would be
# displaced by the next beta published after it.
prerelease: ${{ contains(github.ref_name, '-') }}
files: |
matcha-${{ matrix.target }}.tar.gz
matcha-${{ matrix.target }}.tar.gz.sha256
# Guarantees the arm64 Linux binary is executed before it reaches anyone.
#
# The `Smoke the binary` step above runs each artifact only where the runner
# can, which depends on what `ubuntu-latest` resolves to on the forge that
# fired — so whether the aarch64 Linux binary gets started is a property of the
# runner pool rather than of the pipeline. This job removes that dependency:
# it pins an arm64 Linux runner, so the answer is the same on every release.
#
# GitHub offers such runners and Gitea does not, and a job pinned to a label a
# forge lacks would queue there forever — hence the same `server_url` guard
# `publish-crate` below already uses, which skips the job before a runner is
# ever looked for.
#
# It goes through `install.sh` rather than running the binary directly, so the
# same job also covers the installer's arm64 branch and its checksum
# verification against the release assets exactly as a user receives them.
verify-linux-arm64:
needs: build
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: Install the published arm64 binary and run it
run: |
set -eu
test "$(uname -m)" = aarch64 || { echo "expected an arm64 runner, got $(uname -m)"; exit 1; }
MATCHA_VERSION="$GITHUB_REF_NAME" MATCHA_INSTALL_DIR="$PWD/.bin" sh ./install.sh
"$PWD/.bin/matcha" --version
"$PWD/.bin/matcha" --help > /dev/null
# Gitea only: hand the tag to GitHub, but only once this forge has built all
# four targets and run every artifact it can.
#
# This is the gate. Pushing the tag is what starts GitHub's release and, with
# it, the crates.io publish — and crates.io has no unpublish, only yank. So the
# local build is not a parallel opinion, it is the thing that has to pass
# first. `needs: build` is what makes the two sequential; when both workflows
# fired on the same tag push they were not.
promote-tag:
needs: build
if: ${{ github.server_url != 'https://github.com' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push the tag to GitHub
env:
GH_TOKEN: ${{ secrets.GH_PROMOTE_TOKEN }}
run: |
git remote add github "https://x-access-token:${GH_TOKEN}@github.com/Expressive-Tea/matcha.git"
git push github "refs/tags/$GITHUB_REF_NAME"
# 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