Skip to content

Commit

Permalink
feat: add action to check if version changed correctly (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
domire8 authored Oct 23, 2023
1 parent 29d7d89 commit b3a44ae
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 43 deletions.
49 changes: 6 additions & 43 deletions .github/actions/check-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
outputs:
has_changed:
description: "Has the package version changed?"
value: ${{ steps.check.outputs.changed }}
value: ${{ steps.check.outputs.has_changed }}
version:
description: "The current version of the package"
value: ${{ steps.parse-new-version.outputs.version }}
Expand Down Expand Up @@ -63,46 +63,9 @@ runs:
with:
directory: ${{ inputs.package_path }}

- name: Compare versions and set output
- name: Compare versions
id: check
run: |
BASE_VERSION=${{ steps.parse-base-version.outputs.version }}
NEW_VERSION=${{ steps.parse-new-version.outputs.version }}
if [ "${BASE_VERSION}" = "${NEW_VERSION}" ]; then
echo "Version has not changed"
echo "changed=false" >> $GITHUB_OUTPUT
exit 0
fi
read base_major base_minor base_patch < <(echo $BASE_VERSION | ( IFS=".$IFS" ; read a b c && echo $a $b $c ))
read new_major new_minor new_patch < <(echo $NEW_VERSION | ( IFS=".$IFS" ; read a b c && echo $a $b $c ))
if [ "${new_major}" -lt "${base_major}" ]; then
echo "::error file=package.xml::The major version has been downgraded"
exit 1
elif [ "${new_major}" -gt "${base_major}" ]; then
echo "Major version increment"
if [ ! "${new_minor}" -eq 0 ] || [ ! "${new_patch}" -eq 0 ]; then
echo "::error file=package.xml::Expected minor and patch versions to be 0"
exit 1
fi
else
if [ "${new_minor}" -lt "${base_minor}" ]; then
echo "::error file=package.xml::The minor version has been downgraded"
exit 1
elif [ "${new_minor}" -gt "${base_minor}" ]; then
echo "Minor version increment"
if [ ! "${new_patch}" -eq 0 ]; then
echo "::error file=package.xml::Expected patch versions to be 0"
exit 1
fi
else
if [ "${new_patch}" -lt "${base_patch}" ]; then
echo "::error file=package.xml::The patch version has been downgraded"
exit 1
else
echo "Patch version increment"
fi
fi
fi
echo "Version has changed"
echo "changed=true" >> $GITHUB_OUTPUT
shell: bash
uses: ./.chk-vrs/actions/compare-versions
with:
previous_version: ${{ steps.parse-base-version.outputs.version }}
new_version: ${{ steps.parse-new-version.outputs.version }}
63 changes: 63 additions & 0 deletions .github/actions/compare-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Compare versions

inputs:
new_version:
description: "The new desired version"
required: true
type: string
previous_version:
description: "The previous version"
required: true
type: string

outputs:
has_changed:
description: "Has the version changed?"
value: ${{ steps.check.outputs.changed }}

runs:
using: composite
steps:
- name: Compare versions and set output
id: check
run: |
BASE_VERSION="${{ inputs.previous_version }}"
NEW_VERSION="${{ inputs.new_version }}"
if [ "${BASE_VERSION}" = "${NEW_VERSION}" ]; then
echo "Version has not changed"
echo "changed=false" >> $GITHUB_OUTPUT
exit 0
fi
read base_major base_minor base_patch < <(echo $BASE_VERSION | ( IFS=".$IFS" ; read a b c && echo $a $b $c ))
read new_major new_minor new_patch < <(echo $NEW_VERSION | ( IFS=".$IFS" ; read a b c && echo $a $b $c ))
if [ "${new_major}" -lt "${base_major}" ]; then
echo "::error file=package.xml::The major version has been downgraded"
exit 1
elif [ "${new_major}" -gt "${base_major}" ]; then
echo "Major version increment"
if [ ! "${new_minor}" -eq 0 ] || [ ! "${new_patch}" -eq 0 ]; then
echo "::error file=package.xml::Expected minor and patch versions to be 0"
exit 1
fi
else
if [ "${new_minor}" -lt "${base_minor}" ]; then
echo "::error file=package.xml::The minor version has been downgraded"
exit 1
elif [ "${new_minor}" -gt "${base_minor}" ]; then
echo "Minor version increment"
if [ ! "${new_patch}" -eq 0 ]; then
echo "::error file=package.xml::Expected patch versions to be 0"
exit 1
fi
else
if [ "${new_patch}" -lt "${base_patch}" ]; then
echo "::error file=package.xml::The patch version has been downgraded"
exit 1
else
echo "Patch version increment"
fi
fi
fi
echo "Version has changed"
echo "changed=true" >> $GITHUB_OUTPUT
shell: bash

0 comments on commit b3a44ae

Please sign in to comment.