Skip to content

Update Version

Update Version #1

name: Update Version
on:
workflow_dispatch:
inputs:
version_type:
description: 'Update branch version by:'
type: choice
options:
- major
- minor
- patch
required: true
default: 'patch'
env:
ALLOW_UPDATES: ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}
jobs:
update-version:
runs-on: ubuntu-latest
outputs:
version_tag: ${{ env.version_tag }}
previous_version_tag: ${{ env.previous_version_tag }}
steps:
- name: Check For Valid Updates
if: env.ALLOW_UPDATES == false
run: |
echo "Version updates should only be done on development or hotfix"
exit 1
- name: Checkout Code
uses: actions/checkout@v4
- name: Run Update Version
id: set_version
shell: pwsh
run: |
Import-Module ./solution-helper.psm1 -Force
$previousVersion, $newVersion = Update-Version -type ${{ github.event.inputs.version_type }}
echo "version_tag=$newVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "previous_version_tag=$previousVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Check for Existing Release
run: |
compare_versions() {
echo -e "$1\n$2" | sort -V | tail -n 1
}
# Fetch the list of releases
releases=$(gh release list --json createdAt,tagName --limit 100)
echo -e "$releases"
# Sort the releases by date and extract the most recent one
latest_release=$(echo "$releases" | jq -r 'sort_by(.createdAt) | reverse | .[0] | .tagName')
echo -e "$latest_release"
greater_version=$(compare_versions $latest_release $version_tag)
if [ "$greater_version" = "$version_tag" ]; then
echo "✅ $version_tag is greater than $latest_release"
elif [ "$greater_version" = "$latest_release" ]; then
echo "⛔ $version_tag is less than $latest_release"
exit 1
else
echo "⚠️ Versions are equal"
exit 1
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Version Number
run: |
git config --global user.name '${{ github.triggering_actor }}'
git config --global user.email '${{ github.triggering_actor }}@users.noreply.github.com'
git commit -am "Previous version was '${{ env.previous_version_tag }}'. Version now '${{ env.version_tag }}'."
git push