cadence/.forgejo/workflows/version-bump.yml
pedro-bento ed8c0145ff
All checks were successful
CI / lint-and-test (push) Successful in 11s
Version 0.1.0 (#1)
Reviewed-on: #1
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-09-30 18:33:59 +01:00

71 lines
2.5 KiB
YAML

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