DM-43586: Add versioning to the fits module #22
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |