From 0868507ce6b08f29fc18eb31ce80d7187d93ba85 Mon Sep 17 00:00:00 2001 From: s2quake Date: Fri, 28 Jun 2024 18:27:41 +0900 Subject: [PATCH] Merge pull request #21 from s2quake/ci/improve-action Improve build and test action --- .github/scripts/pack.ps1 | 22 ++++++++++++++++++++++ .github/workflows/pack.yml | 17 +++++++++++------ Directory.Build.props | 3 ++- Directory.Build.targets | 5 ----- 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 .github/scripts/pack.ps1 diff --git a/.github/scripts/pack.ps1 b/.github/scripts/pack.ps1 new file mode 100644 index 0000000..0f7f3cd --- /dev/null +++ b/.github/scripts/pack.ps1 @@ -0,0 +1,22 @@ +param ( + [ValidateScript({ $_ -ge 0 })] + [int]$PullRequestNumber = 0, + [ValidateScript({ ($_ -eq "") -or (Test-Path $_) })] + [string]$KeyPath = "" +) + +$options = @( + "-o pack" + "-p:FileVersion='$fileVersion'" +) + +if ($PullRequestNumber) { + $options += "--version-suffix pr.$PullRequestNumber" +} + +if (Test-Path -Path $KeyPath) { + $options += "-p:TreatWarningsAsErrors=true" + $options += "-p:AssemblyOriginatorKeyFile='$(Resolve-Path -Path $KeyPath)'" +} +Write-Host "dotnet pack $($options -join " ")" +Invoke-Expression -Command "dotnet pack $($options -join " ")" diff --git a/.github/workflows/pack.yml b/.github/workflows/pack.yml index b3efb99..f5223a6 100644 --- a/.github/workflows/pack.yml +++ b/.github/workflows/pack.yml @@ -2,7 +2,7 @@ name: Pack on: pull_request: - + jobs: pack: runs-on: ubuntu-latest @@ -12,8 +12,13 @@ jobs: with: dotnet-version: 8.0.100 - run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk - - run: | - dotnet pack \ - -o pack \ - -p:TreatWarningsAsErrors=true \ - -p:AssemblyOriginatorKeyFile=$(pwd)/private.snk + - run: echo "${{ github.event.pull_request.number }}" + - run: | + .github/scripts/pack.ps1 ` + -PullRequestNumber ${{ github.event.pull_request.number }} ` + -KeyPath "$pwd/private.snk" + shell: pwsh + - if: env.NUGET_API_KEY != '' + run: .github/bin/dist-nuget.sh + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} diff --git a/Directory.Build.props b/Directory.Build.props index e0f7e40..10accc8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -50,7 +50,8 @@ SOFTWARE. --> net6.0;net7.0;net8.0;netstandard2.1 net8.0 2.0 - 2.0.3 + 2.0.3 + $(VersionPrefix) git https://github.com/s2quake/communication https://github.com/s2quake/communication/blob/main/LICENSE.md diff --git a/Directory.Build.targets b/Directory.Build.targets index 229c68f..513c4e2 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -29,11 +29,6 @@ SOFTWARE. --> $(PublishDir) $(DesiredPublishDirTemp) - - - $(FileVersion)-$(TargetFramework) - - $([System.IO.Path]::Combine($(DesiredPublishDir),$(PublishName)))