diff --git a/.github/actions/check-version/action.yml b/.github/actions/check-version/action.yml index 8a58b80..c3f595c 100644 --- a/.github/actions/check-version/action.yml +++ b/.github/actions/check-version/action.yml @@ -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 }} @@ -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 }} diff --git a/.github/actions/compare-versions/action.yml b/.github/actions/compare-versions/action.yml new file mode 100644 index 0000000..b7c75e4 --- /dev/null +++ b/.github/actions/compare-versions/action.yml @@ -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