Fix version-bump
All checks were successful
CI / lint-and-test (push) Successful in 10s
CI / lint-and-test (pull_request) Successful in 10s
Version bump / version-bump (pull_request) Successful in 5s

This commit is contained in:
pedro-bento 2026-09-30 18:32:54 +01:00
parent 8d6f8dfa6c
commit a6df84eca4
2 changed files with 75 additions and 61 deletions

View file

@ -9,6 +9,10 @@ name: CI
# Actions are pinned to node20-compatible releases. Older forgejo-runner # Actions are pinned to node20-compatible releases. Older forgejo-runner
# versions (e.g. v6.4.0) reject any action whose action.yml declares # versions (e.g. v6.4.0) reject any action whose action.yml declares
# `using: node24` — checkout v4 is the last line that runs on node20. # `using: node24` — checkout v4 is the last line that runs on node20.
#
# The pull-request-only version-bump gate lives in its own workflow
# (version-bump.yml) because Forgejo does not reliably skip a job on a
# job-level `if:` and reports the skipped job as a failure instead.
on: on:
push: push:
@ -39,64 +43,3 @@ jobs:
# The suite only needs pytest: cadence.py imports nothing third-party # The suite only needs pytest: cadence.py imports nothing third-party
# at module level, so no torch/whisper/ffmpeg is required here. # at module level, so no torch/whisper/ffmpeg is required here.
run: uv run --python 3.13 --with pytest pytest -q run: uv run --python 3.13 --with pytest pytest -q
version-bump:
# Only meaningful on pull requests, where there is a base branch to diff
# against. On `push` there is nothing to compare, so the job is skipped.
if: github.event_name == 'pull_request'
runs-on: docker
steps:
- name: Checkout
uses: https://data.forgejo.org/actions/checkout@v4
with:
# Full history so the base branch is reachable for the comparison.
fetch-depth: 0
- name: Require a version bump
shell: bash
run: |
set -euo pipefail
# `github.base_ref` is the GitHub-compatible alias and is understood
# by Forgejo; `forgejo.base_ref` is the canonical spelling.
BASE="${{ github.base_ref }}"
if [ -z "$BASE" ]; then
echo "No base ref (not a pull request); skipping version check."
exit 0
fi
git fetch --no-tags origin "$BASE"
if [ ! -f cadence.py ]; then
echo "::error::cadence.py is missing from the change."
exit 1
fi
NEW=$(sed -n 's/^__version__[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' cadence.py | head -n1)
if [ -z "$NEW" ]; then
echo "::error::No __version__ found in cadence.py"
exit 1
fi
# The script may be introduced by this very PR: if it does not exist
# on the base branch there is no previous version to bump from.
if ! git cat-file -e "FETCH_HEAD:cadence.py" 2>/dev/null; then
echo "cadence.py is new to '$BASE' (no base version); version check passes."
exit 0
fi
OLD=$(git show "FETCH_HEAD:cadence.py" | sed -n 's/^__version__[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)
echo "base __version__: ${OLD:-<none>} head __version__: $NEW"
if [ -z "$OLD" ]; then
echo "Could not read a base version; skipping."
exit 0
fi
# Require NEW to be strictly greater than OLD (version sort).
GREATER=$(printf '%s\n%s\n' "$OLD" "$NEW" | sort -V | tail -n1)
if [ "$NEW" = "$GREATER" ] && [ "$OLD" != "$NEW" ]; then
echo "Version bumped: $OLD -> $NEW"
else
echo "::error::cadence.py __version__ must be bumped above $OLD (currently $NEW)."
exit 1
fi

View file

@ -0,0 +1,71 @@
name: Version bump
# Runs only on pull requests: it compares cadence.py's __version__ on the head
# branch against the base branch and fails if the version was not increased.
#
# Kept as a separate workflow rather than a job-level `if:` inside ci.yml:
# forgejo-runner does not reliably skip a job on `if:` and reports the skipped
# job as a failure on push events.
on:
pull_request:
jobs:
version-bump:
runs-on: docker
steps:
- name: Checkout
# v4 runs on node20 (v5+ require node24); full history so the base
# branch is reachable for the comparison.
uses: https://data.forgejo.org/actions/checkout@v4
with:
fetch-depth: 0
- name: Require a version bump
shell: bash
run: |
set -euo pipefail
# `github.base_ref` is the GitHub-compatible alias and is understood
# by Forgejo; `forgejo.base_ref` is the canonical spelling.
BASE="${{ github.base_ref }}"
if [ -z "$BASE" ]; then
echo "No base ref; skipping version check."
exit 0
fi
git fetch --no-tags origin "$BASE"
if [ ! -f cadence.py ]; then
echo "::error::cadence.py is missing from the change."
exit 1
fi
NEW=$(sed -n 's/^__version__[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' cadence.py | head -n1)
if [ -z "$NEW" ]; then
echo "::error::No __version__ found in cadence.py"
exit 1
fi
# The script may be introduced by this very PR: if it does not exist
# on the base branch there is no previous version to bump from.
if ! git cat-file -e "FETCH_HEAD:cadence.py" 2>/dev/null; then
echo "cadence.py is new to '$BASE' (no base version); version check passes."
exit 0
fi
OLD=$(git show "FETCH_HEAD:cadence.py" | sed -n 's/^__version__[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)
echo "base __version__: ${OLD:-<none>} head __version__: $NEW"
if [ -z "$OLD" ]; then
echo "Could not read a base version; skipping."
exit 0
fi
# Require NEW to be strictly greater than OLD (version sort).
GREATER=$(printf '%s\n%s\n' "$OLD" "$NEW" | sort -V | tail -n1)
if [ "$NEW" = "$GREATER" ] && [ "$OLD" != "$NEW" ]; then
echo "Version bumped: $OLD -> $NEW"
else
echo "::error::cadence.py __version__ must be bumped above $OLD (currently $NEW)."
exit 1
fi