|
| 1 | +name: Version bump check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, ready_for_review] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + check-tugboat-version: |
| 12 | + name: Require tugboat version bump |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Compare package version to base |
| 21 | + env: |
| 22 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 23 | + PACKAGE_PUBSPEC: packages/tugboat/pubspec.yaml |
| 24 | + run: | |
| 25 | + set -euo pipefail |
| 26 | +
|
| 27 | + extract_version() { |
| 28 | + local file="$1" |
| 29 | + if [[ ! -f "$file" ]]; then |
| 30 | + echo "" |
| 31 | + return |
| 32 | + fi |
| 33 | + grep -E '^version:' "$file" | head -1 | sed -E 's/^version:[[:space:]]*//' | tr -d '"' | tr -d "'" | tr -d '[:space:]' |
| 34 | + } |
| 35 | +
|
| 36 | + if [[ ! -f "$PACKAGE_PUBSPEC" ]]; then |
| 37 | + echo "::error::$PACKAGE_PUBSPEC is missing on this branch" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + head_version="$(extract_version "$PACKAGE_PUBSPEC")" |
| 42 | + if [[ -z "$head_version" ]]; then |
| 43 | + echo "::error::Could not read version from $PACKAGE_PUBSPEC" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + base_file="$(mktemp)" |
| 48 | + if ! git show "${BASE_SHA}:${PACKAGE_PUBSPEC}" >"$base_file" 2>/dev/null; then |
| 49 | + echo "Base branch has no $PACKAGE_PUBSPEC; treating as new package (ok)." |
| 50 | + echo "PR version: $head_version" |
| 51 | + exit 0 |
| 52 | + fi |
| 53 | +
|
| 54 | + base_version="$(extract_version "$base_file")" |
| 55 | + rm -f "$base_file" |
| 56 | +
|
| 57 | + if [[ -z "$base_version" ]]; then |
| 58 | + echo "::error::Could not read version from base $PACKAGE_PUBSPEC" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + echo "Base version: $base_version" |
| 63 | + echo "PR version: $head_version" |
| 64 | +
|
| 65 | + if [[ "$head_version" == "$base_version" ]]; then |
| 66 | + echo "::error::packages/tugboat version must be bumped before merge (still $base_version)." |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + higher="$(printf '%s\n%s\n' "$base_version" "$head_version" | sort -V | tail -n 1)" |
| 71 | + if [[ "$higher" != "$head_version" ]]; then |
| 72 | + echo "::error::PR version ($head_version) must be greater than base ($base_version)." |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + echo "Version bump detected: $base_version -> $head_version" |
0 commit comments