-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version checking CI/CD workflow (#46)
* 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
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
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
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 | ||