Update version to 2.0.0 #107
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
force-dev-push: | |
description: 'Force publication of NuGet package of a developer version to an internal feed for test purpose' | |
required: false | |
default: 'false' | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: windows-latest | |
env: | |
Configuration: Release | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 7.0.x | |
- name: Set Build Variables | |
id: buildVariables | |
run: | | |
$VersionTag = '' | |
$doPush = $true | |
switch -regex ($Env:GITHUB_REF_NAME) { | |
'^main' { | |
$PUBLISH_TO_NUGETORG = 'true' | |
} | |
default { | |
$PUBLISH_TO_NUGETORG = 'false' | |
$VersionTag = "alpha" | |
if ([string]::IsNullOrEmpty("${{ github.event.inputs.force-dev-push }}") ) { | |
$doPush = $false | |
} else { | |
$doPush = [System.Convert]::ToBoolean("${{ github.event.inputs.force-dev-push }}") | |
} | |
} | |
} | |
$NuGetPackageVersion = dotnet msbuild Directory.Build.props /t:GetPackageVersion | |
"$NuGetPackageVersion" -match "(?<=NuGetPackageVersion:)(.*)" | |
$NuGetPackageVersion = $Matches[0] | |
if ($VersionTag -ne '') { | |
$Timestamp = (Get-Date).ToUniversalTime().ToString("yyyyMMddHHmmss") | |
$NuGetPackageVersion = $NuGetPackageVersion + "-" + $VersionTag + "." + $Timestamp | |
} | |
echo "NuGetPackageVersion=$NuGetPackageVersion" >> $Env:GITHUB_ENV | |
echo "IS_PUBLISH_TO_NUGETORG=$PUBLISH_TO_NUGETORG" >> $Env:GITHUB_ENV | |
echo "DO_PACKAGE_PUSH=$doPush" >> $Env:GITHUB_ENV | |
write-host [INFO] NuGet Package Version: $NuGetPackageVersion | |
- name: Build & Pack | |
run: dotnet build --configuration $env:Configuration -p:Version=$Env:NuGetPackageVersion | |
- name: Test | |
run: dotnet test --configuration $env:Configuration --no-build | |
- name: Sign packages | |
if: env.IS_PUBLISH_TO_NUGETORG == 'true' | |
env: | |
TIMESTAMPER_URL: ${{ secrets.CODE_SIGN_CERTIFICATE_TIMESTAMPER_URL }} | |
PFX_BASE64: ${{ secrets.CODE_SIGN_CERTIFICATE_BASE64 }} | |
PFX_PASS: ${{ secrets.CODE_SIGN_CERTIFICATE_PASSWORD }} | |
run: | | |
$codesign_pfx = "code_sign_cert.pfx" | |
$bytes = [Convert]::FromBase64String($Env:PFX_BASE64) | |
[IO.File]::WriteAllBytes($codesign_pfx, $bytes) | |
Get-ChildItem .\_packages\$Env:Configuration\*.nupkg -Recurse | ForEach-Object { | |
dotnet nuget sign $_.FullName --certificate-path $codesign_pfx --certificate-password $Env:PFX_PASS --timestamper $Env:TIMESTAMPER_URL | |
} | |
- name: Publish | |
if: env.DO_PACKAGE_PUSH == 'true' | |
run: | | |
if ( '${{ env.IS_PUBLISH_TO_NUGETORG }}' -eq 'true' ) { | |
# NuGet feed already defined at NuGet.Config | |
$pushArgs=@('nuget.org', '${{ secrets.NUGET_ORG_TOKEN }}') | |
} else { | |
$feedName="NuGetFeed4Deploy" | |
$pushArgs=@($feedName, 'DUMMY-KEY') | |
dotnet nuget add source ${{ vars.AZURE_NEXUS_PRERELEASES_FEED }} --name $feedName --username gxbuilder --password ${{ secrets.AZURE_ARTIFACTS_TOKEN }} | |
} | |
Get-ChildItem .\_packages\$Env:Configuration\*.nupkg -Recurse | | |
ForEach-Object { | |
dotnet nuget push $_.FullName --source $pushArgs[0] --api-key $pushArgs[1] | |
} |