diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9be7899..d034dd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,17 @@ env: SBT_OPTS: "-Xmx4G -XX:+UseG1GC" jobs: + version: + name: Check the version bump + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Fail unless build.sbt bumps the version + run: ./scripts/check-version-bump + native: name: Native library (${{ matrix.platform }}) runs-on: ${{ matrix.runner }} diff --git a/README.md b/README.md index 73a5ab7..afa2316 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,8 @@ On a push to `main` that job publishes the jar to GitHub Packages. That jar has no classifier. At runtime sbt-jni reads `uname -sm` and loads the library from the directory with that name. -GitHub Packages rejects a second publish of the same version, so bump `ThisBuild / version` in `build.sbt` for every PR that changes the library. +GitHub Packages rejects a second publish of the same version, so bump `ThisBuild / version` in `build.sbt` in every PR. +A CI job on each PR runs `scripts/check-version-bump` and fails when the version matches main. ### Troubleshooting diff --git a/build.sbt b/build.sbt index b8cca47..7b55363 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ import Dependencies._ ThisBuild / scalaVersion := "2.13.15" -ThisBuild / version := "0.0.15" +ThisBuild / version := "0.0.16" ThisBuild / versionScheme := Some("early-semver") ThisBuild / organization := "io.citrine" ThisBuild / organizationName := "Citrine Informatics" diff --git a/scripts/check-version-bump b/scripts/check-version-bump new file mode 100755 index 0000000..994176f --- /dev/null +++ b/scripts/check-version-bump @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Fail unless build.sbt sets a version that differs from the one on main. +# GitHub Packages rejects a second publish of the same version, so every merge must bump it. +set -euo pipefail + +cd "$(dirname "$0")/.." + +git fetch --quiet origin main:refs/remotes/origin_main + +extract_version() { + grep -E '^ThisBuild / version +:=' | sed -nE 's/.*"([^"]+)".*/\1/p' +} + +head_version=$(extract_version < build.sbt) +main_version=$(git cat-file blob origin_main:build.sbt | extract_version) + +if [[ "$head_version" == "$main_version" ]]; then + echo "build.sbt still sets version $main_version, the version on main. Bump it before merging." >&2 + exit 1 +fi + +echo "Version bumps from $main_version to $head_version"