Files
OpenResearch/.github/workflows/ci.yml
T
Daniel Kim 10933a6ae8 Tag releases automatically when Cargo.toml's version is bumped on main
tag-release.yml: on every push to main, mirror the package version into a
v<version> tag if one doesn't exist yet; the tag push triggers the existing
cargo-dist release workflow. The version is never invented or incremented
by CI — merging a PR that bumps Cargo.toml IS the release act. Refuses
(loudly, before tagging) when the RELEASE_TAG_TOKEN secret is missing,
because tags pushed with the default GITHUB_TOKEN don't trigger workflows.

ci.yml version-guard (PRs only): the version may only move forward, may not
reuse an already-released tag, and a bump must come with a regenerated
Cargo.lock — so a malformed bump can't reach main, where merging it would
be the release trigger. Closes the tag/manifest drift class that produced
v0.1.15 (tagged while main said 0.1.14) and v0.1.16 (tagged on a pre-merge
commit, shipping without the feature it was cut for).
2026-06-11 16:06:10 -07:00

92 lines
2.8 KiB
YAML

name: CI
on:
push:
branches: [main]
pull_request:
# Cancel in-flight runs for the same ref when new commits land.
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: fmt, clippy, test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all --check
- name: Clippy
run: cargo clippy --all-targets -- -D warnings
- name: Build
run: cargo build --locked
- name: Test
run: cargo test --locked
# Guards the tag-on-bump release flow (tag-release.yml): the version in
# Cargo.toml may only move forward, may not reuse an already-released tag,
# and a bump must come with a regenerated Cargo.lock. Catching these here
# means a malformed bump can't reach main, where merging it would be the
# release trigger.
version-guard:
name: version sanity
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Version must move forward (with a fresh lockfile)
run: |
set -euo pipefail
pkg_version() { grep -m1 '^version = ' "$1" | sed -E 's/version = "(.*)"/\1/'; }
git fetch --quiet origin "${{ github.base_ref }}"
git show "origin/${{ github.base_ref }}:Cargo.toml" > /tmp/base-Cargo.toml
base=$(pkg_version /tmp/base-Cargo.toml)
head=$(pkg_version Cargo.toml)
echo "base: ${base} pr: ${head}"
if [ "${head}" = "${base}" ]; then
echo "No version change — OK (merging this PR will not release)."
exit 0
fi
# Reject a version that sorts at or below the base (semver-aware sort).
if [ "$(printf '%s\n%s\n' "${base}" "${head}" | sort -V | head -1)" = "${head}" ]; then
echo "::error::Version went backwards: ${base} -> ${head}."
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/v${head}" >/dev/null 2>&1; then
echo "::error::v${head} is already a released tag; bump past it."
exit 1
fi
# A bump must carry a regenerated lockfile, or release builds
# (--locked) would fail.
if ! grep -A1 '^name = "openresearch-cli"$' Cargo.lock | grep -q "version = \"${head}\""; then
echo "::error::Cargo.toml says ${head} but Cargo.lock was not regenerated (run cargo build and commit the lockfile)."
exit 1
fi
echo "Version bump ${base} -> ${head} looks good. Merging this PR WILL cut release v${head}."