1
+ name : Create Prerelease
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
+ is_draft :
16
+ description : ' Create a draft of the release:'
17
+ type : boolean
18
+ required : true
19
+ default : false
20
+
21
+ env :
22
+ IS_PRERELEASE : ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}
23
+
24
+ jobs :
25
+ update-version :
26
+ runs-on : ubuntu-latest
27
+ outputs :
28
+ version_tag : ${{ env.version_tag }}
29
+ previous_version_tag : ${{ env.previous_version_tag }}
30
+
31
+ steps :
32
+ - name : Check For Main
33
+ if : env.IS_PRERELEASE == false
34
+ run : |
35
+ echo "This workflow should not be triggered on the main branch, please use development or hotfix"
36
+ exit 1
37
+
38
+ - name : Checkout Code
39
+ uses : actions/checkout@v4
40
+
41
+ - name : Run Update Version
42
+ id : set_version
43
+ shell : pwsh
44
+ run : |
45
+ Import-Module ./solution-helper.psm1 -Force
46
+ $previousVersion, $newVersion = Update-Version -type ${{ github.event.inputs.version_type }}
47
+ echo "version_tag=$newVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
48
+ echo "previous_version_tag=$previousVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
49
+
50
+ - name : Check for Existing Release
51
+ run : |
52
+ # Fetch the list of releases
53
+ releases=$(gh release list --json createdAt,tagName --limit 100)
54
+
55
+ echo -e "$releases"
56
+
57
+ # Sort the releases by date and extract the most recent one that matches the version or version-prerelease
58
+ release_line=$(echo "$releases" | jq -r 'sort_by(.createdAt) | reverse | .[0] | select(.tagName | test("-prerelease$")) | .tagName')
59
+
60
+ echo -e "$release_line"
61
+
62
+ # Check if the version or version-prerelease already exists
63
+ if [[ -n "$release_line" ]]; then
64
+ echo "⛔ Prerelease for '$previous_version_tag' already exists, please remove the release or fix the version."
65
+ echo -e " - Failed on version: '$release_line'"
66
+ exit 1
67
+ else
68
+ echo "✅ $previous_version_tag-prerelease does not exist"
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-actions'
76
+ git config --global user.email '[email protected] '
77
+ git commit -am "Previous version was '${{ env.previous_version_tag }}'. Version now '${{ env.version_tag }}'."
78
+ git push
79
+
80
+ create-release :
81
+ needs : update-version
82
+ runs-on : ubuntu-latest
83
+
84
+ steps :
85
+ - name : Checkout Code
86
+ uses : actions/checkout@v4
87
+
88
+ - name : Create Release
89
+ run : |
90
+ TAG_NAME="${{ needs.update-version.outputs.version_tag }}-prerelease"
91
+ if [[ ${{ github.event.inputs.is_draft }} ]]; then
92
+ gh release create $TAG_NAME --target ${{ github.ref_name }} --title $TAG_NAME --generate-notes --draft --prerelease
93
+ else
94
+ gh release create $TAG_NAME --target ${{ github.ref_name }} --title $TAG_NAME --generate-notes --prerelease
95
+ fi
96
+ env :
97
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments