1+ name : Update Version
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version_type :
7+ description : ' Update branch version by:'
8+ type : choice
9+ options :
10+ - major
11+ - minor
12+ - patch
13+ required : true
14+ default : ' patch'
15+
16+ env :
17+ ALLOW_UPDATES : ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}
18+
19+ jobs :
20+ update-version :
21+ runs-on : ubuntu-latest
22+ outputs :
23+ version_tag : ${{ env.version_tag }}
24+ previous_version_tag : ${{ env.previous_version_tag }}
25+
26+ steps :
27+ - name : Check For Valid Updates
28+ if : env.ALLOW_UPDATES == false
29+ run : |
30+ echo "Version updates should only be done on development or hotfix"
31+ exit 1
32+
33+ - name : Checkout Code
34+ uses : actions/checkout@v4
35+
36+ - name : Run Update Version
37+ id : set_version
38+ shell : pwsh
39+ run : |
40+ Import-Module ./solution-helper.psm1 -Force
41+ $previousVersion, $newVersion = Update-Version -type ${{ github.event.inputs.version_type }}
42+ echo "version_tag=$newVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
43+ echo "previous_version_tag=$previousVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
44+
45+ - name : Check for Existing Release
46+ run : |
47+ compare_versions() {
48+ echo -e "$1\n$2" | sort -V | tail -n 1
49+ }
50+
51+ # Fetch the list of releases
52+ releases=$(gh release list --json createdAt,tagName --limit 100)
53+ echo -e "$releases"
54+
55+ # Sort the releases by date and extract the most recent one
56+ latest_release=$(echo "$releases" | jq -r 'sort_by(.createdAt) | reverse | .[0] | .tagName')
57+ echo -e "$latest_release"
58+
59+ greater_version=$(compare_versions $latest_release $version_tag)
60+
61+ if [ "$greater_version" = "$version_tag" ]; then
62+ echo "✅ $version_tag is greater than $latest_release"
63+ elif [ "$greater_version" = "$latest_release" ]; then
64+ echo "⛔ $version_tag is less than $latest_release"
65+ exit 1
66+ else
67+ echo "⚠️ Versions are equal"
68+ exit 1
69+ fi
70+ env :
71+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72+
73+ - name : Update Version Number
74+ run : |
75+ git config --global user.name '${{ github.triggering_actor }}'
76+ git config --global user.email '${{ github.triggering_actor }}@users.noreply.github.com'
77+ git commit -am "Previous version was '${{ env.previous_version_tag }}'. Version now '${{ env.version_tag }}'."
78+ git push
0 commit comments