Skip to content

Commit d89cb3f

Browse files
update github actions (#17)
1 parent c974fed commit d89cb3f

File tree

4 files changed

+127
-109
lines changed

4 files changed

+127
-109
lines changed

.github/workflows/create-prerelease.yml

Lines changed: 0 additions & 97 deletions
This file was deleted.

.github/workflows/create-release.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ name: Create Release
33
on:
44
workflow_dispatch:
55
inputs:
6+
is_prerelease:
7+
description: 'Create a prerelease:'
8+
type: boolean
9+
required: true
10+
default: false
611
is_draft:
7-
description: 'Create a draft of the release:'
12+
description: 'Set as a draft:'
813
type: boolean
914
required: true
1015
default: false
1116

17+
env:
18+
ALLOW_PRERELEASE: ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}
19+
1220
jobs:
1321
create-release:
1422
runs-on: ubuntu-latest
1523

1624
steps:
17-
- name: Fail if branch is not main
18-
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
25+
- name: Check For Valid Prerelease
26+
if: ${{ env.ALLOW_PRERELEASE == 'true' && github.event.inputs.is_prerelease == 'false' || github.ref == 'refs/heads/main'}}
1927
run: |
20-
echo "This workflow should not be triggered with workflow_dispatch on a branch other than main"
28+
echo "Prereleases should not be triggered on the main branch, please use development or hotfix"
2129
exit 1
2230
2331
- name: Checkout Code
@@ -29,14 +37,22 @@ jobs:
2937
run: |
3038
Import-Module ./solution-helper.psm1 -Force
3139
$version = Get-Version
32-
echo "version_tag=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
40+
if ("${{ github.event.inputs.is_prerelease }}" -eq "true") {
41+
$version_tag = "$version-develop.$(date +'%y%m%d%H%M%S')"
42+
} else {
43+
$version_tag = $version
44+
}
45+
echo "version_tag=$version_tag" | Out-File -FilePath $env:GITHUB_ENV -Append
3346
3447
- name: Create Release
3548
run: |
36-
if [[ ${{ github.event.inputs.is_draft }} ]]; then
37-
gh release create ${{ env.version_tag }} --target ${{ github.ref_name }} --title ${{ env.version_tag }} --generate-notes --draft --latest
38-
else
39-
gh release create ${{ env.version_tag }} --target ${{ github.ref_name }} --title ${{ env.version_tag }} --generate-notes --latest
40-
fi
49+
echo "🎁 Creating release ${{ env.version_tag }}"
50+
gh release create ${{ env.version_tag }} \
51+
--target ${{ github.ref_name }} \
52+
--title ${{ env.version_tag }} \
53+
--generate-notes \
54+
$(if [[ "${{ github.event.inputs.is_draft }}" == "true" ]]; then echo "--draft"; fi) \
55+
$(if [[ "${{ github.event.inputs.is_prerelease }}" == "true" ]]; then echo "--prerelease"; fi) \
56+
$(if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then echo "--latest"; fi)
4157
env:
4258
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ jobs:
2222
if: ${{ env.BRANCH_NAME == 'main' && (github.event.release.prerelease == false || github.event_name == 'workflow_dispatch') }}
2323
run: |
2424
echo "BUILD_CONFIGURATION=Release" >> $GITHUB_ENV
25-
echo "VERSION_SUFFIX=" >> $GITHUB_ENV
2625
2726
- name: Debug Configuration
2827
if: ${{ (github.event.release.prerelease || github.event_name == 'workflow_dispatch') }}
2928
run: |
3029
echo "BUILD_CONFIGURATION=Debug" >> $GITHUB_ENV
31-
echo "VERSION_SUFFIX=develop.$(date +'%y%m%d%H%M%S')" >> $GITHUB_ENV
3230
3331
- name: Check Build Configuration
3432
if: ${{ env.BUILD_CONFIGURATION == '' }}
@@ -39,6 +37,29 @@ jobs:
3937
- name: Checkout Code
4038
uses: actions/checkout@v4
4139

40+
- name: Get Current Version
41+
id: get_version
42+
shell: pwsh
43+
run: |
44+
Import-Module ./solution-helper.psm1 -Force
45+
$build_version = Get-Version
46+
echo "build_version=$build_version" | Out-File -FilePath $env:GITHUB_ENV -Append
47+
48+
- name: Get Version Suffix
49+
id: get_version_suffix
50+
shell: bash
51+
run: |
52+
# Fetch the list of releases
53+
releases=$(gh release list --json createdAt,tagName --limit 100)
54+
55+
# Filter the releases based on the starting version number, sort them by date, and extract the most recent one
56+
latest_release=$(echo "$releases" | jq -r --arg build_version "$build_version" 'map(select(.tagName | startswith($build_version))) | sort_by(.createdAt) | reverse | .[0] | .tagName')
57+
58+
version_suffix=${latest_release#*$build_version-}
59+
echo "VERSION_SUFFIX=$version_suffix" >> $GITHUB_ENV
60+
env:
61+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
4263
- name: Setup .NET
4364
uses: actions/setup-dotnet@v4
4465
with:

.github/workflows/update-version.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)