Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions git-hooks/check-version-bump.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <support@gen3.org>"]
license = "Apache-2.0"
Expand Down
Loading