Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
varndellwagglebee committed Jul 10, 2024
2 parents c4b1001 + f022743 commit 4224c18
Show file tree
Hide file tree
Showing 32 changed files with 1,573 additions and 237 deletions.
97 changes: 0 additions & 97 deletions .github/workflows/create-prerelease.yml

This file was deleted.

38 changes: 27 additions & 11 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 }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 changes: 28 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,34 @@ 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-}
if [ "$version_suffix" == "$build_version" ]; then
version_suffix=""
fi
echo "VERSION_SUFFIX=$version_suffix" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
SOLUTION_NAME: 'Hyperbee.Pipeline.sln'
SOLUTION_NAME: ${{ vars.SOLUTION_NAME }}
DOTNET_VERSION: '8.0.x'

jobs:
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
52 changes: 26 additions & 26 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
<!--
Push the target package to nuget
-->
<Target Name="PushPackage" AfterTargets="Pack"
Condition="'$(PushAfterPack)'=='true' AND '$(IsPackable)'=='true'">
<Exec Command="dotnet nuget push $(SolutionDir)output/$(TargetName).$(PackageVersion).nupkg $(PackageSourceParam) $(PackageApiKeyParam)"></Exec>
</Target>
<Target Name="PushPackage" AfterTargets="Pack"
Condition="'$(PushAfterPack)'=='true' AND '$(IsPackable)'=='true'">
<Exec Command="dotnet nuget push $(SolutionDir)output/$(TargetName).$(PackageVersion).nupkg $(PackageSourceParam) $(PackageApiKeyParam)"></Exec>
</Target>

<!--
<!--
Set the package version and source before Pack
https://github.com/NuGet/NuGet.Client/blob/4.3.0.4202/src/NuGet.Core/NuGet.Build.Tasks.Pack.Library/Pack.targets
Must run before target "GenerateNuspec" ("Pack") for the version to be applied as expected
-->
<Target Name="SetPackageVersion" BeforeTargets="GenerateNuspec"
Condition="'$(IsPackable)'=='true'">
<PropertyGroup>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<PackageVersion Condition="'$(VersionSuffix)'==''">$(VersionPrefix)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)'!=''">$(VersionPrefix)-$(VersionSuffix)</PackageVersion>
</PropertyGroup>
</Target>
<Target Name="SetPackageVersion" BeforeTargets="GenerateNuspec"
Condition="'$(IsPackable)'=='true'">
<PropertyGroup>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<PackageVersion Condition="'$(VersionSuffix)'==''">$(VersionPrefix)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)'!=''">$(VersionPrefix)-$(VersionSuffix)</PackageVersion>
</PropertyGroup>
</Target>

<Target Name="SetPackageSource" BeforeTargets="GenerateNuspec"
Condition="'$(PushAfterPack)'=='true'">
<PropertyGroup>
<PackageSourceParam Condition="'$(PackageSource)'!=''">--source $(PackageSource)</PackageSourceParam>
</PropertyGroup>
</Target>
<Target Name="SetPackageSource" BeforeTargets="GenerateNuspec"
Condition="'$(PushAfterPack)'=='true'">
<PropertyGroup>
<PackageSourceParam Condition="'$(PackageSource)'!=''">--source $(PackageSource)</PackageSourceParam>
</PropertyGroup>
</Target>

<Target Name="SetPackageApiKey" BeforeTargets="GenerateNuspec"
Condition="'$(PushAfterPack)'=='true'">
<PropertyGroup>
<PackageApiKeyParam Condition="'$(PackageApiKey)'!=''">--api-key $(PackageApiKey)</PackageApiKeyParam>
</PropertyGroup>
</Target>
<Target Name="SetPackageApiKey" BeforeTargets="GenerateNuspec"
Condition="'$(PushAfterPack)'=='true'">
<PropertyGroup>
<PackageApiKeyParam Condition="'$(PackageApiKey)'!=''">--api-key $(PackageApiKey)</PackageApiKeyParam>
</PropertyGroup>
</Target>

</Project>
Loading

0 comments on commit 4224c18

Please sign in to comment.