Skip to content

Commit

Permalink
Add version checking CI/CD workflow (#46)
Browse files Browse the repository at this point in the history
* Add workflow for checking package version

* Fail workflow if version not updated (not ideal)

* Only run workflow for PRs

* Add `git fetch`

* More descriptive status messages

* Color messages
  • Loading branch information
sbaldu authored Jul 18, 2024
1 parent bbe8b8a commit 884657d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/check_package_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Compare the package version of the PR with the main branch

# The workflow gets triggered by pushes and pull requests
on:
pull_request:
branches: [ "main" ]

jobs:
compare-versions:

runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
# Checks out the code in the repository
- uses: actions/checkout@v3
- name: Compile CLUEstering modules
working-directory: ${{github.workspace}}
run: |
git fetch
RED="\033[0;31m"
pr_version=$(cat setup.py | grep "__version__ " | awk -F '"' '{print $2}')
pr_major=$(echo "$pr_version" | awk -F '.' '{print $1}')
pr_minor=$(echo "$pr_version" | awk -F '.' '{print $2}')
pr_patch=$(echo "$pr_version" | awk -F '.' '{print $3}')
echo "Switching to 'main' branch"
git switch main
main_version=$(cat setup.py | grep "__version__ " | awk -F '"' '{print $2}')
main_major=$(echo "$main_version" | awk -F '.' '{print $1}')
main_minor=$(echo "$main_version" | awk -F '.' '{print $2}')
main_patch=$(echo "$main_version" | awk -F '.' '{print $3}')
if [ "$main_major" -le "$pr_major" ]; then
if [ "$main_minor" -le "$pr_minor" ]; then
if [ "$main_patch" -lt "$pr_patch" ] ||
[ "$main_major" -lt "$pr_major" ] ||
[ "$main_minor" -lt "$pr_minor" ]; then
exit 0 # at least one version counters has been updated
else
echo -e "${RED}ERROR: Patch version is behind main. Update the version in setup.py"
echo -e "${RED}main -> $main_version"
echo -e "${RED}pr -> $pr_version"
exit 1
fi
else
echo -e "${RED}ERROR: Minor version is behind main. Update the version in setup.py"
echo -e "${RED}main -> $main_version"
echo -e "${RED}pr -> $pr_version"
exit 1
fi
else
echo -e "${RED}ERROR: Major version is behind main. Update the version in setup.py"
echo -e "${RED}main -> $main_version"
echo -e "${RED}pr -> $pr_version"
exit 1
fi

0 comments on commit 884657d

Please sign in to comment.