|
| 1 | +name: VersionCheck |
| 2 | + |
| 3 | +# Ensures that every PR targeting main bumps Project.toml version. |
| 4 | +# The check fails if the version in the PR branch is not strictly greater |
| 5 | +# than the version on the base branch. |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - Project.toml |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + check-version: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + # Fetch both the PR branch and the base branch so we can compare. |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Get base branch version |
| 28 | + id: base |
| 29 | + run: | |
| 30 | + git fetch origin ${{ github.base_ref }} --depth=1 |
| 31 | + VERSION=$(git show origin/${{ github.base_ref }}:Project.toml \ |
| 32 | + | grep '^version' | head -1 | sed 's/.*"\(.*\)"/\1/') |
| 33 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 34 | + echo "Base version: $VERSION" |
| 35 | +
|
| 36 | + - name: Get PR branch version |
| 37 | + id: pr |
| 38 | + run: | |
| 39 | + VERSION=$(grep '^version' Project.toml | head -1 | sed 's/.*"\(.*\)"/\1/') |
| 40 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 41 | + echo "PR version: $VERSION" |
| 42 | +
|
| 43 | + - name: Compare versions (semver) |
| 44 | + env: |
| 45 | + BASE: ${{ steps.base.outputs.version }} |
| 46 | + PR: ${{ steps.pr.outputs.version }} |
| 47 | + run: | |
| 48 | + # Split a semver string into its numeric parts and compare. |
| 49 | + version_gt() { |
| 50 | + # Returns 0 (success) if $1 > $2 as semver, 1 otherwise. |
| 51 | + IFS='.' read -r -a A <<< "$1" |
| 52 | + IFS='.' read -r -a B <<< "$2" |
| 53 | + for i in 0 1 2; do |
| 54 | + a="${A[$i]:-0}" |
| 55 | + b="${B[$i]:-0}" |
| 56 | + if [ "$a" -gt "$b" ]; then return 0; fi |
| 57 | + if [ "$a" -lt "$b" ]; then return 1; fi |
| 58 | + done |
| 59 | + return 1 # equal is not greater |
| 60 | + } |
| 61 | +
|
| 62 | + echo "Base: $BASE → PR: $PR" |
| 63 | + if version_gt "$PR" "$BASE"; then |
| 64 | + echo "✓ Version bumped ($BASE → $PR)" |
| 65 | + else |
| 66 | + echo "✗ Version NOT bumped. PR version ($PR) must be strictly greater than base version ($BASE)." |
| 67 | + exit 1 |
| 68 | + fi |
0 commit comments