Skip to content

Commit

Permalink
update github actions (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattEdwardsWaggleBee authored Jun 21, 2024
1 parent c974fed commit d89cb3f
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 109 deletions.
97 changes: 0 additions & 97 deletions .github/workflows/create-prerelease.yml

This file was deleted.

36 changes: 26 additions & 10 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ name: Create Release
on:
workflow_dispatch:
inputs:
is_prerelease:
description: 'Create a prerelease:'
type: boolean
required: true
default: false
is_draft:
description: 'Create a draft of the release:'
description: 'Set as a draft:'
type: boolean
required: true
default: false

env:
ALLOW_PRERELEASE: ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}

jobs:
create-release:
runs-on: ubuntu-latest

steps:
- name: Fail if branch is not main
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
- name: Check For Valid Prerelease
if: ${{ env.ALLOW_PRERELEASE == 'true' && github.event.inputs.is_prerelease == 'false' || github.ref == 'refs/heads/main'}}
run: |
echo "This workflow should not be triggered with workflow_dispatch on a branch other than main"
echo "Prereleases should not be triggered on the main branch, please use development or hotfix"
exit 1
- name: Checkout Code
Expand All @@ -29,14 +37,22 @@ jobs:
run: |
Import-Module ./solution-helper.psm1 -Force
$version = Get-Version
echo "version_tag=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
if ("${{ github.event.inputs.is_prerelease }}" -eq "true") {
$version_tag = "$version-develop.$(date +'%y%m%d%H%M%S')"
} else {
$version_tag = $version
}
echo "version_tag=$version_tag" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Create Release
run: |
if [[ ${{ github.event.inputs.is_draft }} ]]; then
gh release create ${{ env.version_tag }} --target ${{ github.ref_name }} --title ${{ env.version_tag }} --generate-notes --draft --latest
else
gh release create ${{ env.version_tag }} --target ${{ github.ref_name }} --title ${{ env.version_tag }} --generate-notes --latest
fi
echo "🎁 Creating release ${{ env.version_tag }}"
gh release create ${{ env.version_tag }} \
--target ${{ github.ref_name }} \
--title ${{ env.version_tag }} \
--generate-notes \
$(if [[ "${{ github.event.inputs.is_draft }}" == "true" ]]; then echo "--draft"; fi) \
$(if [[ "${{ github.event.inputs.is_prerelease }}" == "true" ]]; then echo "--prerelease"; fi) \
$(if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then echo "--latest"; fi)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 23 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ jobs:
if: ${{ env.BRANCH_NAME == 'main' && (github.event.release.prerelease == false || github.event_name == 'workflow_dispatch') }}
run: |
echo "BUILD_CONFIGURATION=Release" >> $GITHUB_ENV
echo "VERSION_SUFFIX=" >> $GITHUB_ENV
- name: Debug Configuration
if: ${{ (github.event.release.prerelease || github.event_name == 'workflow_dispatch') }}
run: |
echo "BUILD_CONFIGURATION=Debug" >> $GITHUB_ENV
echo "VERSION_SUFFIX=develop.$(date +'%y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Check Build Configuration
if: ${{ env.BUILD_CONFIGURATION == '' }}
Expand All @@ -39,6 +37,29 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Get Current Version
id: get_version
shell: pwsh
run: |
Import-Module ./solution-helper.psm1 -Force
$build_version = Get-Version
echo "build_version=$build_version" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Get Version Suffix
id: get_version_suffix
shell: bash
run: |
# Fetch the list of releases
releases=$(gh release list --json createdAt,tagName --limit 100)
# Filter the releases based on the starting version number, sort them by date, and extract the most recent one
latest_release=$(echo "$releases" | jq -r --arg build_version "$build_version" 'map(select(.tagName | startswith($build_version))) | sort_by(.createdAt) | reverse | .[0] | .tagName')
version_suffix=${latest_release#*$build_version-}
echo "VERSION_SUFFIX=$version_suffix" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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

0 comments on commit d89cb3f

Please sign in to comment.