Repository navigation
ci(release): choose patch, minor, or major when dispatching a release #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4b1700a
feat(release): add version bump script
senamakel 75f2132
feat(release): add test script for bump-version
senamakel 678acc7
chore(release): make bump-version scripts executable
senamakel 6ffd82b
ci(release): add one-click semver release workflow
senamakel 3a9414b
docs(developing): document the release workflow's version bump and ta…
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <patch|minor|major> [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 <patch|minor|major> [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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.