Skip to content

Commit

Permalink
Support preview releases (#698)
Browse files Browse the repository at this point in the history
* Changed set-output
* Support beta releases (#26)
  • Loading branch information
ErikMogensen committed Nov 11, 2022
1 parent 7d60855 commit 465f056
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 28 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/handle-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down
20 changes: 20 additions & 0 deletions GetNumberVersion.ps1
Original file line number Diff line number Diff line change
@@ -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]
36 changes: 22 additions & 14 deletions SetVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
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

$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

0 comments on commit 465f056

Please sign in to comment.