Skip to content

DM-43586: Add versioning to the fits module #10

DM-43586: Add versioning to the fits module

DM-43586: Add versioning to the fits module #10

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 )
echo $CHANGED_FILES
if [[ $CHANGED_FILES == *"python/lsst/cell_coadds/_fits.py"* ]]; then
echo "FILE_CHANGED='true'" >> $GITHUB_ENV
echo "file changed"
echo $FILE_CHANGED
else
echo "file remains the same"
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