I'm comparing the current version which is in package.json and the latest tag.
The expected behavior is that whenever:
- The version from the package.json file is less than or equal to the latest tag(tag version) the PR should be rejected rejected
- The version from the package.json file is greater than the latest tag(tag version) the PR should pass the check.
but the result is different than I expected
where CURRENT_VERSION refers to the version from the package.json file and LATEST_TAG is the latest tag number.
Here is my action:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get version and tag
run: |
version=$(node -p "require('./package.json').version")
echo "CURRENT_VERSION=$version" >> $GITHUB_ENV
echo "LATEST_TAG=$(git describe --tag --abbrev=0 | cut -c 2-)" >> $GITHUB_ENV
- name: PR version is invalid
if: ${{ env.CURRENT_VERSION <= env.LATEST_TAG }}
run: |
echo "Error: Same version found. Please update version in package.json"
exit 1
- name: PR version is valid
if: ${{ env.CURRENT_VERSION != env.LATEST_TAG }}
run: |
echo "New taga has been published"
If someone helps me to understand what is happening I'll be grateful.