Skip to content

Commit

Permalink
Add a GHA to enforce version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed Apr 1, 2024
1 parent cf10efb commit 4657d83
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions .github/workflows/check_fits_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Check that the version number was bumped if _fits.py was modified

on:
pull_request:

jobs:
check_version:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check if _fits.py has changed
id: check_file_changes
run: |
# 'github.event.before/after' and 'github.event.pull_request.base.sha' are inconsistent for PRs
# Find the commit where the PR branch was forked from the base branch
git fetch origin ${{ github.base_ref }} ${{ github.event.pull_request.head.ref }}
FORK_POINT=$( git show-branch --merge-base "origin/${{ github.base_ref }}"\
"origin/${{ github.event.pull_request.head.ref }}" )
LATEST_COMMIT_IN_PR=${{ github.event.pull_request.head.sha }}
CHANGED_FILES=$( git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR )
if [[ $CHANGED_FILES == *"python/lsst/cell_coadds/_fits.py"* ]]; then
echo "FILE_CHANGED='true'" >> $GITHUB_ENV
else
echo "FILE_CHANGED='false'" >> $GITHUB_ENV
fi
- name: Get previous version
id: get_previous_version
if: ${{ env.FILE_CHANGED }} == 'true'
run: |
PREVIOUS_VERSION=$(git show HEAD^:python/lsst/cell_coadds/_fits.py |\
grep 'MODULE_VERSION =' | cut -d'=' -f2 | tr -d '[:space:]')
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV
- name: Get current version
id: get_current_version
if: ${{ env.FILE_CHANGED }} == 'true'
run: |
CURRENT_VERSION=$(grep 'MODULE_VERSION = ' python/lsst/cell_coadds/_fits.py | cut -d'=' -f2 | tr -d '[:space:]')
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
if: ${{ env.FILE_CHANGED }} == 'true'
run: |
if [[ "${{ env.PREVIOUS_VERSION }}" == "${{ env.CURRENT_VERSION }}" ]]; then
echo "Error: _fits.py was modified but MODULE_VERSION was not!"
exit 1
fi
2 changes: 1 addition & 1 deletion python/lsst/cell_coadds/_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
to know which files written by an earlier version of this module is still
readable or not. Any changes to this module, even as trivial as formatting
changes and documentation updates should bump the version number (in this case,
it would bump the patch).
it would bump the patch). This is mandated in GitHub Actions.
"""

from __future__ import annotations
Expand Down

0 comments on commit 4657d83

Please sign in to comment.