From 12cd9d4ad4324dc21c0302426e9d8c6a02b8003c Mon Sep 17 00:00:00 2001 From: Pauline Ribeyre <4224001+paulineribeyre@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:26:49 -0600 Subject: [PATCH] Add version bump check --- .pre-commit-config.yaml | 39 +++++++++------- git-hooks/check-version-bump.sh | 80 +++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 104 insertions(+), 17 deletions(-) create mode 100755 git-hooks/check-version-bump.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c2bd895e..7f3e3cf0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,17 +1,24 @@ repos: -- repo: git@github.com:Yelp/detect-secrets - rev: v1.5.0 - hooks: - - id: detect-secrets - args: ['--baseline', '.secrets.baseline'] - exclude: '(docs\/_build|poetry.lock)' -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v6.0.0 - hooks: - - id: no-commit-to-branch - args: [--branch, develop, --branch, master, --pattern, release/.*] -- repo: https://github.com/psf/black - rev: 26.5.1 - hooks: - - id: black - additional_dependencies: ['click==8.0.4'] + - repo: git@github.com:Yelp/detect-secrets + rev: v1.5.0 + hooks: + - id: detect-secrets + args: ["--baseline", ".secrets.baseline"] + exclude: '(docs\/_build|poetry.lock)' + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: no-commit-to-branch + args: [--branch, develop, --branch, master, --pattern, release/.*] + - repo: https://github.com/psf/black + rev: 26.5.1 + hooks: + - id: black + additional_dependencies: ["click==8.0.4"] + - repo: local + hooks: + - id: check-version-bump + name: Check version bump + entry: git-hooks/check-version-bump.sh + language: script + pass_filenames: false diff --git a/git-hooks/check-version-bump.sh b/git-hooks/check-version-bump.sh new file mode 100755 index 00000000..23ae2bcb --- /dev/null +++ b/git-hooks/check-version-bump.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# +# Checks that the version in pyproject.toml differs from (and is greater than) +# the version on the remote master branch. + +set -euo pipefail + +FILE="pyproject.toml" +REMOTE="origin" +BRANCH="master" + +# Extract `version = "x.y.z"` from the [tool.poetry] section only, +# so a "version" key in other sections (e.g. dependencies) is never picked up. +get_version() { + awk ' + /^\[/ { in_poetry = ($0 == "[tool.poetry]") } + in_poetry && /^[[:space:]]*version[[:space:]]*=/ { + match($0, /"[^"]*"|'"'"'[^'"'"']*'"'"'/) + print substr($0, RSTART + 1, RLENGTH - 2) + exit + } + ' +} + +if [[ ! -f "$FILE" ]]; then + echo "ERROR: $FILE not found" >&2 + exit 2 +fi + +# Path of the file relative to the repo root (needed for `git show`) +REPO_ROOT="$(git -C "$(dirname "$FILE")" rev-parse --show-toplevel)" +ABS_FILE="$(cd "$(dirname "$FILE")" && pwd)/$(basename "$FILE")" +REL_FILE="${ABS_FILE#"$REPO_ROOT"/}" + +# Local version +NEW_VERSION="$(get_version < "$FILE")" +if [[ -z "$NEW_VERSION" ]]; then + echo "ERROR: could not find a version in [tool.poetry] of $FILE" >&2 + exit 2 +fi + +# Make sure the version in the working tree is the one that is staged, +# i.e. there is no unstaged change to the version line. +if ! INDEX_CONTENT="$(git -C "$REPO_ROOT" show ":$REL_FILE" 2>/dev/null)"; then + echo "ERROR: $REL_FILE is not tracked/staged in git" >&2 + exit 2 +fi +INDEX_VERSION="$(get_version <<< "$INDEX_CONTENT")" +if [[ "$INDEX_VERSION" != "$NEW_VERSION" ]]; then + echo "ERROR: unstaged change to the version in $FILE" >&2 + echo " staged: $INDEX_VERSION, working tree: $NEW_VERSION" >&2 + echo " run: git add $FILE" >&2 + exit 1 +fi + +# Remote version: fetch the branch from GitHub (does not touch the local +# master branch or working tree; the result lands in FETCH_HEAD). +git -C "$REPO_ROOT" fetch --quiet --depth=1 "$REMOTE" "$BRANCH" +MASTER_VERSION="$(git -C "$REPO_ROOT" show "FETCH_HEAD:$REL_FILE" | get_version)" +if [[ -z "$MASTER_VERSION" ]]; then + echo "ERROR: could not find a version in $REMOTE/$BRANCH:$REL_FILE" >&2 + exit 2 +fi + +# 1. Must be different +if [[ "$NEW_VERSION" == "$MASTER_VERSION" ]]; then + echo "Version on $REMOTE/$BRANCH: $MASTER_VERSION" + echo "Version in your $FILE: $NEW_VERSION" + echo "ERROR: version was not bumped" >&2 + exit 1 +fi + +# 2. Must be greater (version-aware sort; the highest of the two sorts last) +HIGHEST="$(printf '%s\n%s\n' "$MASTER_VERSION" "$NEW_VERSION" | sort -V | tail -n1)" +if [[ "$HIGHEST" != "$NEW_VERSION" ]]; then + echo "Version on $REMOTE/$BRANCH: $MASTER_VERSION" + echo "Version in your $FILE: $NEW_VERSION" + echo "ERROR: version went down" >&2 + exit 1 +fi diff --git a/pyproject.toml b/pyproject.toml index 9280ffff..ace7ea7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "gen3" homepage = "https://gen3.org/" -version = "5.0.0" +version = "5.0.1" description = "Gen3 CLI and Python SDK" authors = ["Center for Translational Data Science at the University of Chicago "] license = "Apache-2.0"