-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (82 loc) · 3.22 KB
/
create-prerelease.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Create Prerelease
on:
workflow_dispatch:
inputs:
version_type:
description: 'Update branch version by:'
type: choice
options:
- major
- minor
- patch
required: true
default: 'patch'
is_draft:
description: 'Create a draft of the release:'
type: boolean
required: true
default: false
env:
IS_PRERELEASE: ${{ 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 Main
if: env.IS_PRERELEASE == false
run: |
echo "This workflow should not be triggered on the main branch, please use 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: |
# 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 that matches the version or version-prerelease
release_line=$(echo "$releases" | jq -r 'sort_by(.createdAt) | reverse | .[0] | select(.tagName | test("-prerelease$")) | .tagName')
echo -e "$release_line"
# Check if the version or version-prerelease already exists
if [[ -n "$release_line" ]]; then
echo "⛔ Prerelease for '$previous_version_tag' already exists, please remove the release or fix the version."
echo -e " - Failed on version: '$release_line'"
exit 1
else
echo "✅ $previous_version_tag-prerelease does not exist"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Version Number
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git commit -am "Previous version was '${{ env.previous_version_tag }}'. Version now '${{ env.version_tag }}'."
git push
create-release:
needs: update-version
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create Release
run: |
TAG_NAME="${{ needs.update-version.outputs.version_tag }}-prerelease"
if [[ ${{ github.event.inputs.is_draft }} ]]; then
gh release create $TAG_NAME --target ${{ github.ref_name }} --title $TAG_NAME --generate-notes --draft --prerelease
else
gh release create $TAG_NAME --target ${{ github.ref_name }} --title $TAG_NAME --generate-notes --prerelease
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}