8000 Release from the tag: crates, image and GitHub Release by one workflow (0.1.2) by ynishi · Pull Request #15 · ynishi/evalhub · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 137 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# On a version tag: build the container image from the tagged commit and
# push it to GitHub Container Registry as ghcr.io/ynishi/evalhub:<version>
# and :latest. That image is how the application is distributed; the
# hosted service itself is deployed with `fly deploy` from the checkout
# (docs/hosting.md). crates.io publishing of the three SDK crates is not
# done here; it is a hand-typed `cargo publish` (see CONTRIBUTING.md), and
# the tag that triggers this workflow is pushed as part of that same
# release script.
# On a version tag, everything a release is, from that one push:
#
# check the tag names the version in Cargo.toml and sits on main
# crates `just package`, cargo-semver-checks against crates.io, then
# publish whichever of the three SDK crates is not on crates.io
# at this version (so a rerun publishes nothing twice)
8000 # image ghcr.io/ynishi/evalhub:<version> and :latest
# release a GitHub Release for the tag, notes from the merged PR
#
# crates.io is authenticated by Trusted Publishing (OIDC): the owner has
# registered this repository and workflow file for each crate, and no
# token is stored anywhere. That registration is per crate and needs the
# first version of each crate published by hand, which 0.1.0 was.
#
# The tag is the human gate. It is pushed by `deploy/release/tag.sh`
# (usually through `deploy/release/land.sh`), which checks the same two
# things `check` does before the push, so `check` failing here means the
# tag was made some other way. The hosted service is not deployed by this
# workflow; that is `fly deploy`, by hand (docs/hosting.md).

name: release

Expand All @@ -14,12 +25,89 @@ on:
tags: ["v*"]

permissions:
contents: read
packages: write
contents: write # the GitHub Release
packages: write # ghcr.io
id-token: write # crates.io Trusted Publishing

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

env:
CARGO_TERM_COLOR: always
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0"

jobs:
check:
name: tag matches the manifest and is on main
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: version
run: |
version="${GITHUB_REF_NAME#v}"
grep -q "^version = \"$version\"" Cargo.toml \
|| { echo "tag $GITHUB_REF_NAME but Cargo.toml is at $(grep -m1 '^version' Cargo.toml)"; exit 1; }
git merge-base --is-ancestor "$GITHUB_SHA" origin/main \
|| { echo "tagged commit $GITHUB_SHA is not on main"; exit 1; }
echo "version=$version" >> "$GITHUB_OUTPUT"

crates:
10000 name: SDK crates to crates.io
needs: check
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.check.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: just
- name: just package
run: just package
- name: semver against the published versions
# A break shipped under a patch or 0.x minor bump stops the
# release here, before anything is published; the fix is a
# higher version, not a flag.
uses: obi1kenobi/cargo-semver-checks-action@v2
with:
package: evalhub-schema,evalhub-core,evalhub-query
- name: which of the three are not published yet
id: pending
run: |
pending=""
for c in evalhub-schema evalhub-core evalhub-query; do
code=$(curl -s -o /dev/null -w '%{http_code}' \
-A "evalhub release workflow (github.com/${GITHUB_REPOSITORY})" \
"https://crates.io/api/v1/crates/$c/$VERSION")
case "$code" in
200) echo "$c $VERSION is already on crates.io" ;;
404) pending="$pending -p $c" ;;
*) echo "crates.io answered $code for $c"; exit 1 ;;
esac
done
echo "args=$pending" >> "$GITHUB_OUTPUT"
- name: crates.io token (Trusted Publishing)
if: steps.pending.outputs.args != ''
id: auth
uses: rust-lang/crates-io-auth-action@v1
- name: cargo publish
if: steps.pending.outputs.args != ''
# One command for all pending crates: cargo orders them by
# dependency and waits for each to be indexed before the next.
run: cargo publish ${{ steps.pending.outputs.args }} --locked
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

image:
name: container image
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -44,3 +132,42 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

release:
name: GitHub Release
needs: [check, crates, image]
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.check.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: notes from the merged pull request
# The tag points at a merge commit; the PR that produced it is
# the release's description. Without one (a tag on a direct
# commit), GitHub's generated notes are used.
run: |
gh pr list --repo "$GITHUB_REPOSITORY" --state merged --search "$GITHUB_SHA" \
--json number,title,body --jq '.[0] // empty' > pr.json
if [ -s pr.json ]; then
{
printf '%s (#%s)\n\n' "$(jq -r .title pr.json)" "$(jq -r .number pr.json)"
jq -r .body pr.json
printf '\n---\nSDK crates: '
for c in evalhub-schema evalhub-core evalhub-query; do
printf '[%s](https://crates.io/crates/%s/%s) ' "$c" "$c" "$VERSION"
done
printf '\nImage: `ghcr.io/%s:%s`\n' "$GITHUB_REPOSITORY" "$VERSION"
} > notes.md
echo "notes=--notes-file notes.md" >> "$GITHUB_ENV"
else
echo "notes=--generate-notes" >> "$GITHUB_ENV"
fi
- name: create the release (once)
run: |
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "release $GITHUB_REF_NAME exists"
else
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
--verify-tag --title "evalhub $VERSION" $notes
fi
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ copy of anything; follow the links.
way when editing them. Only the three SDK crates (`evalhub-schema`,
`-core`, `-query`) are published to crates.io; the store and the server
are `publish = false` and ship as the image.
- **Releases**: CONTRIBUTING §Releases. Merge commits only (never
squash). `deploy/release/land.sh <pr> <issue>` merges, closes, tags;
the `release` workflow publishes the crates, the image and the GitHub
Release from the tag. Nothing is `cargo publish`ed by hand.
- **Verification**: per crate, `cargo test -p <crate>` (`just check` runs
the full list). Never `cargo test --workspace` as the routine check.
`evalhub-store` and `evalhub-server` tests need Docker.
Expand Down
37 changes: 35 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ published to crates.io: `evalhub-schema`, `evalhub-core` and
`publish = false` and ship as the container image (`Dockerfile`), the way a
web application is not uploaded to npm. `just package` packages the three,
then inspects each `.crate`: LICENSE and README present, none over the
crates.io size limit. `cargo publish` is not a recipe; it is typed by hand
after `just package`, naming the three crates.
crates.io size limit. Publishing is not typed by anyone: the `release`
workflow does it from the tag (see Releases below).

The UI reaches the binary through `build.rs`, which refuses a release build
without `crates/evalhub-server/web-dist`; the image build and `just e2e`
Expand Down Expand Up @@ -209,6 +209,39 @@ outcome), and what it deliberately does not cover, and ends with
`Refs #<issue>`. Longer bodies are easier to write as a file and pass with
`--body-file`; keep that file somewhere `.gitignore` excludes.

## Releases

A release is a pull request whose last commit carries the version bump
(above), merged, then tagged. The tag push is the only release action a
person takes; `.github/workflows/release.yml` does the rest from it:

1. `check`: the tag names the version in `Cargo.toml` and the tagged
commit is on `main`. Otherwise nothing below runs.
2. `crates`: `just package`, then `cargo semver-checks` against the
versions on crates.io, then `cargo publish` for whichever of
`evalhub-schema`, `evalhub-core` and `evalhub-query` is not yet on
crates.io at that version. Authentication is crates.io Trusted
Publishing (OIDC from this repository and this workflow file); no
token is stored. A rerun publishes nothing twice.
3. `image`: `ghcr.io/ynishi/evalhub:<version>` and `:latest`.
4. `release`: a GitHub Release for the tag, its notes taken from the
merged pull request's body, so write that body as the release notes.

`deploy/release/land.sh <pr> <issue>` merges the pull request (a merge
commit, never a squash: the commits carry the `Signed-off-by`), closes the
issue, fast-forwards `main`, waits for its CI, tags, pushes the tag and
follows the workflow to the end. `deploy/release/tag.sh` is the second
half on its own. Both refuse to tag a commit whose CI is not green or
whose version does not match.

Merges are merge commits only; squash and rebase merges rewrite the
commits and drop the sign-off. A break in an SDK crate's public API needs
a higher version than a patch (0.1.x → 0.2.0 while on 0.x); `just
semver-check` says so before the workflow does.

The hosted service is not deployed by the workflow; that is `fly deploy`,
by hand (`docs/hosting.md`).

## Working with coding agents

What this repository tells an agent is `AGENTS.md` at the root. It is a page of
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/*"]

[workspace.package]
version = "0.1.1"
version = "0.1.2"
edition = "2024"
# sqlx 0.9 declares rust-version 1.94.0; the workspace cannot claim less.
rust-version = "1.94"
Expand All @@ -21,10 +21,10 @@ categories = ["web-programming::http-server", "science"]

[workspace.dependencies]
# internal
evalhub-schema = { path = "crates/evalhub-schema", version = "0.1.1" }
evalhub-core = { path = "crates/evalhub-core", version = "0.1.1" }
evalhub-query = { path = "crates/evalhub-query", version = "0.1.1" }
evalhub-store = { path = "crates/evalhub-store", version = "0.1.1" }
evalhub-schema = { path = "crates/evalhub-schema", version = "0.1.2" }
evalhub-core = { path = "crates/evalhub-core", version = "0.1.2" }
evalhub-query = { path = "crates/evalhub-query", version = "0.1.2" }
evalhub-store = { path = "crates/evalhub-store", version = "0.1.2" }

# serde
serde = { version = "1", features = ["derive"] }
Expand Down
45 changes: 45 additions & 0 deletions deploy/release/land.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Land a merge-ready pull request and, if it ends a release, release it:
# merge (a merge commit, never squash: the branch commits carry the
# Signed-off-by), close the issue, fast-forward main, drop the local
# branch, then `tag.sh` (waits for CI, tags, pushes, follows the release
# workflow).
#
# bash deploy/release/land.sh <pr> <issue> # merge, close, tag
# bash deploy/release/land.sh <pr> <issue> --no-tag # merge and close only
# bash deploy/release/land.sh <pr> - ... # keep the issue open
#
# The merge and the issue close are the remote writes here; the tag push
# is tag.sh's. `set -e`: a step that fails stops the ones after it.
set -euo pipefail
cd "$(dirname "$0")/../.."
repo=ynishi/evalhub
pr=${1:?usage: land.sh <pr> <issue> [--no-tag]}
issue=${2:?usage: land.sh <pr> <issue> [--no-tag]}
tag=1; [ "${3:-}" = --no-tag ] && tag=0

[ -z "$(git status --porcelain)" ] || { echo "working tree not clean" >&2; git status --short >&2; exit 1; }

read -r state branch < <(gh pr view "$pr" -R "$repo" --json state,headRefName --jq '"\(.state) \(.headRefName)"')
case "$state" in
OPEN)
gh pr merge "$pr" -R "$repo" --merge
[ "$issue" = - ] || gh issue close "$issue" -R "$repo" --comment "Shipped in #${pr}."
;;
MERGED) echo "PR #$pr already merged" ;;
*) echo "PR #$pr is $state" >&2; exit 1 ;;
esac

git switch -q main
git pull -q --ff-only origin main
if git show-ref -q --verify "refs/heads/$branch"; then
if git worktree list --porcelain | grep -q "^branch refs/heads/$branch$"; then
echo "branch $branch is checked out in a worktree; remove it with workspace/after-merge.sh"
else
git branch -D "$branch" >/dev/null && echo "deleted local branch $branch"
fi
fi
git log --oneline -1

[ "$tag" = 1 ] && exec bash deploy/release/tag.sh
echo "merged; not tagged (--no-tag)"
Loading
Loading
0