From 4b1700aa219c39a43b4a06905bb87316010a5bd7 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 28 Oct 2026 17:40:39 +0000 Subject: [PATCH 1/5] feat(release): add version bump script Add a script that bumps the project version for releases, automating the manual edit so version updates stay consistent. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- scripts/release/bump-version.sh | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 scripts/release/bump-version.sh diff --git a/scripts/release/bump-version.sh b/scripts/release/bump-version.sh new file mode 100644 index 000000000..066f6ff4f --- /dev/null +++ b/scripts/release/bump-version.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# +# bump-version.sh — apply a semver bump to the workspace version. +# +# Usage: scripts/release/bump-version.sh [repo-root] +# +# The `[workspace.package]` version in the root Cargo.toml is the one version +# every member crate inherits. Bumping it also means rewriting the lockfile's +# entries for the workspace's own packages, or `cargo build --locked` in the +# release jobs rejects the tree. This script edits both files, verifies that +# they agree, and prints `version=` / `tag=` lines (also appended to +# $GITHUB_OUTPUT when that is set). It does not commit, tag, or push. + +set -euo pipefail + +bump="${1:-}" +root="${2:-.}" +cargo_toml="${root}/Cargo.toml" +cargo_lock="${root}/Cargo.lock" +# Workspace members whose lockfile entries carry the shared version. +packages=(medulla medulla-link medulla-tui) + +case "$bump" in + patch | minor | major) ;; + *) + echo "usage: $0 [repo-root]" >&2 + exit 2 + ;; +esac + +# The first `version = "…"` line is the [workspace.package] one; dependency +# versions are written inline (`{ version = … }`) and never start a line. +current="$(sed -n 's/^version = "\(.*\)"$/\1/p' "$cargo_toml" | head -1)" +if [[ ! "$current" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + echo "Cargo.toml workspace version '${current}' is not plain MAJOR.MINOR.PATCH" >&2 + exit 1 +fi +major="${BASH_REMATCH[1]}" +minor="${BASH_REMATCH[2]}" +patch="${BASH_REMATCH[3]}" + +case "$bump" in + major) next="$((major + 1)).0.0" ;; + minor) next="${major}.$((minor + 1)).0" ;; + patch) next="${major}.${minor}.$((patch + 1))" ;; +esac + +python3 - "$cargo_toml" "$cargo_lock" "$current" "$next" "${packages[@]}" <<'PY' +import sys + +toml_path, lock_path, current, new, *packages = sys.argv[1:] + +with open(toml_path, encoding="utf-8") as f: + toml = f.read() +old_line = f'\nversion = "{current}"\n' +if old_line not in toml: + raise SystemExit(f"{toml_path}: no workspace version line for {current}") +toml = toml.replace(old_line, f'\nversion = "{new}"\n', 1) + +with open(lock_path, encoding="utf-8") as f: + lock = f.read() +for name in packages: + old = f'name = "{name}"\nversion = "{current}"\n' + if old not in lock: + raise SystemExit(f"{lock_path}: no {name} package at version {current}") + lock = lock.replace(old, f'name = "{name}"\nversion = "{new}"\n', 1) + +with open(toml_path, "w", encoding="utf-8") as f: + f.write(toml) +with open(lock_path, "w", encoding="utf-8") as f: + f.write(lock) +PY + +# Re-read both files so a partial edit cannot slip through as a release. +written="$(sed -n 's/^version = "\(.*\)"$/\1/p' "$cargo_toml" | head -1)" +if [[ "$written" != "$next" ]]; then + echo "Cargo.toml version is ${written} after bump, expected ${next}" >&2 + exit 1 +fi +for name in "${packages[@]}"; do + if ! grep -qzF "name = \"${name}\" +version = \"${next}\"" "$cargo_lock"; then + echo "Cargo.lock ${name} is not at ${next} after bump" >&2 + exit 1 + fi +done + +echo "Bumped ${current} -> ${next} (${bump})" >&2 +echo "version=${next}" +echo "tag=v${next}" +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + { + echo "previous=${current}" + echo "version=${next}" + echo "tag=v${next}" + } >> "$GITHUB_OUTPUT" +fi From 75f213256f101beeb2d6314cc7b81f8b83b5b277 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 28 Oct 2026 17:40:47 +0000 Subject: [PATCH 2/5] feat(release): add test script for bump-version Add a shell test script that exercises the bump-version release helper, covering version increment behaviour so regressions in the release tooling are caught before publishing. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- scripts/release/test-bump-version.sh | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 scripts/release/test-bump-version.sh diff --git a/scripts/release/test-bump-version.sh b/scripts/release/test-bump-version.sh new file mode 100644 index 000000000..cedc2fefb --- /dev/null +++ b/scripts/release/test-bump-version.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# +# test-bump-version.sh — exercise bump-version.sh against a scratch copy of a +# minimal manifest and lockfile. Run from the repository root; no cargo needed. + +set -euo pipefail + +script="$(cd "$(dirname "$0")" && pwd)/bump-version.sh" +work="$(mktemp -d)" +trap 'rm -rf "$work"' EXIT +failures=0 + +seed() { + cat > "$work/Cargo.toml" <<'EOF' +[workspace.package] +version = "0.14.1" + +[workspace.dependencies] +serde = { version = "1" } +EOF + cat > "$work/Cargo.lock" <<'EOF' +[[package]] +name = "medulla" +version = "0.14.1" + +[[package]] +name = "medulla-link" +version = "0.14.1" + +[[package]] +name = "medulla-tui" +version = "0.14.1" + +[[package]] +name = "other" +version = "0.14.1" +EOF +} + +expect_bump() { + local kind="$1" want="$2" out + seed + out="$(bash "$script" "$kind" "$work" 2>/dev/null)" + if [[ "$out" != "version=${want}"$'\n'"tag=v${want}" ]]; then + echo "FAIL ${kind}: got '${out}'" + failures=$((failures + 1)) + return + fi + if [[ "$(grep -c "version = \"${want}\"" "$work/Cargo.lock")" != 3 ]] || + ! grep -q '^name = "other"$' "$work/Cargo.lock" || + [[ "$(grep -A1 '^name = "other"$' "$work/Cargo.lock" | tail -1)" != 'version = "0.14.1"' ]]; then + echo "FAIL ${kind}: lockfile not rewritten for exactly the workspace packages" + failures=$((failures + 1)) + return + fi + echo "ok ${kind} -> ${want}" +} + +expect_bump patch 0.14.2 +expect_bump minor 0.15.0 +expect_bump major 1.0.0 + +seed +if bash "$script" bogus "$work" >/dev/null 2>&1; then + echo "FAIL rejects unknown bump type" + failures=$((failures + 1)) +else + echo "ok rejects unknown bump type" +fi + +seed +sed -i 's/name = "medulla-tui"/name = "renamed"/' "$work/Cargo.lock" +if bash "$script" patch "$work" >/dev/null 2>&1; then + echo "FAIL rejects a lockfile missing a workspace package" + failures=$((failures + 1)) +elif ! grep -q '^version = "0.14.1"$' "$work/Cargo.toml"; then + echo "FAIL left Cargo.toml edited after a lockfile failure" + failures=$((failures + 1)) +else + echo "ok rejects a lockfile missing a workspace package" +fi + +exit "$failures" From 678acc7a519e71f39aabd37542a6bab9c7bf3206 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 28 Oct 2026 17:40:49 +0000 Subject: [PATCH 3/5] chore(release): make bump-version scripts executable Mark the version bump script and its test as executable so they can be run directly without invoking a shell interpreter. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- scripts/release/bump-version.sh | 0 scripts/release/test-bump-version.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/release/bump-version.sh mode change 100644 => 100755 scripts/release/test-bump-version.sh diff --git a/scripts/release/bump-version.sh b/scripts/release/bump-version.sh old mode 100644 new mode 100755 diff --git a/scripts/release/test-bump-version.sh b/scripts/release/test-bump-version.sh old mode 100644 new mode 100755 From 6ffd82b03d20583c732d72b97ca2dbc2c5816bc8 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 28 Oct 2026 17:41:06 +0000 Subject: [PATCH 4/5] ci(release): add one-click semver release workflow The release workflow now takes a patch, minor, or major input, bumps the workspace version, commits and tags it on main, and pushes both atomically so a rejected push leaves nothing behind. Releases always run from main and are serialized to avoid two runs racing for the same tag. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .github/workflows/release.yml | 70 +++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70b11c413..97944d467 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,42 +1,82 @@ name: Release +# One-click release: pick a semver bump (patch, minor, or major) and this +# workflow bumps the shared workspace version in Cargo.toml/Cargo.lock, commits +# `chore(release): vX.Y.Z` to main, pushes a matching annotated tag, builds the +# `medulla` binary for each supported target from that tag, and publishes a +# GitHub Release with the packaged binaries and `latest.json` attached. +# +# Always releases from main, whatever ref it is dispatched on. The bump commit +# and tag go up in one atomic push, so a rejected push (main moved underneath +# the run) leaves neither behind. The release is created in this same workflow, +# so GITHUB_TOKEN pushes not triggering other workflows is fine. + on: workflow_dispatch: + inputs: + release_type: + description: Semver increment to apply to the current version. + required: true + default: patch + type: choice + options: [patch, minor, major] permissions: contents: write concurrency: - group: release-${{ github.ref }} + # One release at a time: two concurrent bumps would race for the same tag. + group: release cancel-in-progress: false jobs: prepare: - name: Tag current main version - if: github.ref == 'refs/heads/main' + name: Bump version and tag (${{ inputs.release_type }}) runs-on: ubuntu-latest outputs: - tag: ${{ steps.version.outputs.tag }} - version: ${{ steps.version.outputs.version }} + tag: ${{ steps.bump.outputs.tag }} + version: ${{ steps.bump.outputs.version }} steps: - uses: actions/checkout@v7 with: + ref: main fetch-depth: 0 - - name: Read version and create tag - id: version + - name: Configure git identity + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Test the bump script + run: bash scripts/release/test-bump-version.sh + + - name: Bump version + id: bump + run: bash scripts/release/bump-version.sh "${{ inputs.release_type }}" + + - name: Ensure tag does not already exist + env: + TAG: ${{ steps.bump.outputs.tag }} run: | set -euo pipefail - version="$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -1)" - tag="v${version}" - if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then - echo "Release tag ${tag} already exists" >&2 + git fetch origin --tags --force + if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null || + git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null; then + echo "Release tag ${TAG} already exists" >&2 exit 1 fi - git tag -a "${tag}" -m "${tag}" - git push origin "refs/tags/${tag}" - echo "version=${version}" >> "$GITHUB_OUTPUT" - echo "tag=${tag}" >> "$GITHUB_OUTPUT" + + - name: Commit, tag, and push + env: + TAG: ${{ steps.bump.outputs.tag }} + run: | + set -euo pipefail + git add Cargo.toml Cargo.lock + git commit -m "chore(release): ${TAG}" + # Annotated tag + explicit ref push: --follow-tags skips lightweight + # tags, which would leave the build jobs nothing to check out. + git tag -a "${TAG}" -m "${TAG}" + git push --atomic origin HEAD:refs/heads/main "refs/tags/${TAG}" build: needs: prepare From 3a9414b4783efe069fdbb0d744e3e5f8dc7ded71 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Wed, 28 Oct 2026 17:41:15 +0000 Subject: [PATCH 5/5] docs(developing): document the release workflow's version bump and tagging The releasing section now describes how the manual Release workflow takes a patch, minor, or major release type, bumps the workspace version and lockfile, commits and tags on main, and publishes artifacts. It also adds the gh command to dispatch a release and notes the offline bump script and its test. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- DEVELOPING.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index afa9f49d9..946d5ab62 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -36,10 +36,18 @@ for the full loop and the release process. ## Releasing -`Release` (`.github/workflows/release.yml`, dispatched manually) bumps the -version here, tags it here, builds the binary for every supported target, and -publishes the packaged artifacts — binaries, checksums, and the `latest.json` -update manifest `medulla update` reads — as a GitHub Release on the public -[tinyhumansai/medulla](https://github.com/tinyhumansai/medulla) repository. It -authenticates there with a GitHub App installation token scoped to that one -repository. Only build output crosses the boundary; no source is pushed there. +`Release` (`.github/workflows/release.yml`, dispatched manually on `main`) +takes a `release_type` of `patch`, `minor`, or `major`. It bumps the shared +`[workspace.package]` version and the workspace entries in `Cargo.lock` with +`scripts/release/bump-version.sh`, commits `chore(release): vX.Y.Z` to `main`, +pushes the matching annotated tag, builds the binary for every supported target +from that tag, and publishes the packaged artifacts — binaries, checksums, and +the `latest.json` update manifest `medulla update` reads — as a GitHub Release. + +```sh +gh workflow run release.yml -R tinyhumansai/medulla -f release_type=minor +``` + +`bash scripts/release/test-bump-version.sh` exercises the bump script offline; +`bash scripts/release/bump-version.sh minor` shows the bump on your own tree +(revert `Cargo.toml` and `Cargo.lock` afterwards).