Skip to content

Commit

Permalink
Add CI check for updated version on actual code change (#682)
Browse files Browse the repository at this point in the history
* Add CI check for updated version on actual code change

* remove accidentally added newline

* dont bump version
  • Loading branch information
usefulalgorithm authored Nov 14, 2023
1 parent 6a461ae commit d14f75f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@
<!--
Describe how the change was tested end-to-end.
-->

### ☑️ Checks

<!--
Some sanity checks to make sure your PR is good to go. Make sure all checkboxes
are ticked!
-->

- [ ] My PR contains actual code changes, and I have updated the version number in `pyproject.toml`.
11 changes: 11 additions & 0 deletions .github/scripts/check_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if git diff --name-only origin/main | grep ".*\.py$" > /dev/null 2>&1; then
# Found modified stuff, make sure version is bumped!
MAIN_TAG=$(git describe origin/main --tags --abbrev=0)
CURRENT_VERSION=$(poetry version --short 2>/dev/null)

GIT_ROOT=$(git rev-parse --show-toplevel)
# Script exits with return code 1 if the check fails.
python ${GIT_ROOT}/.github/scripts/compare_versions.py ${MAIN_TAG} ${CURRENT_VERSION}
fi
13 changes: 13 additions & 0 deletions .github/scripts/compare_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This script checks if current version is larger than latest main version.

import sys

from packaging import version

main_tag = sys.argv[1]
current_version = sys.argv[2]

# We want this program to exit 1 when the check fails.
# Since `True` == `1`, we want this comparison to evaluate to `0` if we
# want the check to pass.
sys.exit(version.parse(main_tag) >= version.parse(current_version))
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
thresholdNew: 0.85
thresholdModified: 0.0

- name: Check bumped version
run: bash .github/scripts/check_version.sh

docker:
name: Docker build
runs-on: ubuntu-latest
Expand Down

0 comments on commit d14f75f

Please sign in to comment.