diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 1a64a2f9..1a2331be 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -46,21 +46,34 @@ jobs: - name: Show version run: echo "Building version ${{ inputs.release-version }}" + - name: Get number version + env: + ReleaseVersion: ${{ inputs.release-version }} + run: | + $numberVersion = .\GetNumberVersion -Version ${{env.ReleaseVersion}} + echo "Setting numberVersion to $numberVersion" + echo "NUMBER_VERSION=$numberVersion" >> $env:GITHUB_ENV + - name: Set fileversion on all .NET Framework assemblies and assembly version on the exe env: - Version: ${{ inputs.release-version }} + ReleaseVersion: ${{ inputs.release-version }} run: | $sbeFileName = "$env:GITHUB_WORKSPACE\src\ServiceBusExplorer\Properties\AssemblyInfo.cs" - .\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyVersion' -Version ${{env.Version}} - .\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyFileVersion' -Version ${{env.Version}} - .\SetVersion -FileName "$env:GITHUB_WORKSPACE\src\Common\Properties\AssemblyInfo.cs" -PropertyName 'AssemblyFileVersion' -Version ${{env.Version}} - .\SetVersion -FileName "$env:GITHUB_WORKSPACE\src\NotificationHubs\Properties\AssemblyInfo.cs" -PropertyName 'AssemblyFileVersion' -Version ${{env.Version}} + .\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyVersion' -Version ${{env.NUMBER_VERSION}} + .\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyFileVersion' -Version ${{env.NUMBER_VERSION}} + .\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyInformationalVersion' -VersionString ${{env.ReleaseVersion}} + + $commonInfoFile = "$env:GITHUB_WORKSPACE\src\Common\Properties\AssemblyInfo.cs" + .\SetVersion -FileName $commonInfoFile -PropertyName 'AssemblyFileVersion' -Version ${{env.NUMBER_VERSION}} + .\SetVersion -FileName $commonInfoFile -PropertyName 'AssemblyInformationalVersion' -VersionString ${{env.ReleaseVersion}} + + $notificationHubsInfoFile = "$env:GITHUB_WORKSPACE\src\NotificationHubs\Properties\AssemblyInfo.cs" + .\SetVersion -FileName $notificationHubsInfoFile -PropertyName 'AssemblyFileVersion' -Version ${{env.NUMBER_VERSION}} + .\SetVersion -FileName $notificationHubsInfoFile -PropertyName 'AssemblyInformationalVersion' -VersionString ${{env.ReleaseVersion}} - name: Build - env: - Version: ${{ inputs.release-version }} run: | - msbuild /m /property:Configuration=${{env.BUILD_CONFIGURATION}},FileVersion=${{env.Version}} ${{env.SOLUTION_FILE_PATH}} + msbuild /m /property:Configuration=${{env.BUILD_CONFIGURATION}},FileVersion=${{env.NUMBER_VERSION}},InformationalVersion=${{inputs.release-version}} ${{env.SOLUTION_FILE_PATH}} - name: Run tests run: | @@ -70,7 +83,7 @@ jobs: if ($process.ExitCode -ne 0) {throw "Unit tests failed (exit code = $($process.ExitCode))" } - name: Cache build - uses: actions/cache@v3.0.5 + uses: actions/cache@v3.0.11 if: ${{ inputs.cache-build }} with: path: src/ServiceBusExplorer/bin/Release diff --git a/.github/workflows/handle-tag.yml b/.github/workflows/handle-tag.yml index be38959a..658e8851 100644 --- a/.github/workflows/handle-tag.yml +++ b/.github/workflows/handle-tag.yml @@ -3,7 +3,7 @@ name: Handle tag on: push: tags: - - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+*' workflow_dispatch: jobs: @@ -15,7 +15,7 @@ jobs: id: tag-commit-hash run: | hash=${{ github.sha }} - echo "::set-output name=tag-hash::${hash}" + echo "{name}=tag-hash::${hash}" >> $GITHUB_OUTPUT echo $hash - name: Checkout main @@ -27,7 +27,7 @@ jobs: id: main-commit-hash run: | hash=$(git log -n1 --format=format:"%H") - echo "::set-output name=main-hash::${hash}" + echo "{name}=main-hash::${hash}" >> $GITHUB_OUTPUT echo $hash - name: Verify tag commit matches main commit - exit if they don't match diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fce47677..5905b417 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,9 +24,21 @@ jobs: - uses: actions/checkout@v3 + - name: Verify release version and get just the numbers and the dots + id: get-number-version + run: | + [Version]$numberVersion = .\GetNumberVersion -Version ${{ inputs.release-version }} + [bool]$prerelease = $true + + if ("$numberVersion" -eq "${{ inputs.release-version }}") { + $prerelease = $false + } + + echo "PRERELEASE=$prerelease" >> $env:GITHUB_ENV + - name: Get cached build id: get-cached-build - uses: actions/cache@v3.0.5 + uses: actions/cache@v3.0.11 with: path: src/ServiceBusExplorer/bin/Release key: cached-output-${{ github.sha }} @@ -80,7 +92,8 @@ jobs: Start-Sleep 1 gh release upload ${{ env.RELEASE_VERSION }} $env:ZipFilename $env:NupkgFilename - - name: Publish to Chocolatey + - name: Publish to Chocolatey if not prerelease + if: ${{ env.PRERELEASE == 'FALSE' }} env: CHOCO_TOKEN: ${{ secrets.CHOCO_TOKEN }} run: | diff --git a/GetNumberVersion.ps1 b/GetNumberVersion.ps1 new file mode 100644 index 00000000..e8def152 --- /dev/null +++ b/GetNumberVersion.ps1 @@ -0,0 +1,20 @@ +# Verify it is a proper version +param( + [Parameter(Mandatory=$false)] + [string] + $Version +) + +Set-StrictMode -Version 3 + +# RegEx from https://semver.org/ +[string]$semanticRegEx = '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' + +if (-not ($Version -match $semanticRegEx)) { + throw "The version must follow semantic versioning, see https://semver.org/." + ` + " For instance 4.3.22-beta." +} + +$parts = $Version -split {$_ -eq '-' -or $_ -eq '+'} + +return $parts[0] diff --git a/SetVersion.ps1 b/SetVersion.ps1 index 3789722a..e7d2c4e9 100644 --- a/SetVersion.ps1 +++ b/SetVersion.ps1 @@ -1,15 +1,21 @@ param( - [Parameter(Mandatory)] + [Parameter(Mandatory)] [string] - $FileName, + $FileName, - [Parameter(Mandatory)] - [string] - $PropertyName, + [Parameter(Mandatory)] + [string] + $PropertyName, - [Parameter(Mandatory)] + [Parameter(Mandatory, + ParameterSetName = 'Version')] [Version] - $Version + $Version, + + [Parameter(Mandatory, + ParameterSetName = 'VersionString')] + [string] + $VersionString ) Set-StrictMode -Version 2 @@ -17,20 +23,22 @@ Set-StrictMode -Version 2 $pattern = "^\[assembly: $PropertyName\(""(.*)""\)\]$" $found = $false +if ($Version) { + $VersionString = $Version +} + $content = (Get-Content $fileName -Encoding UTF8) | ForEach-Object { - if ($_ -match $pattern) - { - "[assembly: $PropertyName(""{0}"")]" -f $Version - $found = $true + if ($_ -match $pattern) { + "[assembly: $PropertyName(""{0}"")]" -f $VersionString + $found = $true } - else - { + else { $_ } } if (-not $found) { - $content += "[assembly: $PropertyName(""{0}"")]" -f $Version + $content += "[assembly: $PropertyName(""{0}"")]" -f $VersionString } $content | Set-Content $fileName -Encoding UTF8 \ No newline at end of file