Skip to content

Commit

Permalink
Merge pull request #21 from s2quake/ci/improve-action
Browse files Browse the repository at this point in the history
Improve build and test action
  • Loading branch information
s2quake committed Jun 28, 2024
1 parent 2dfb05a commit 4ff5ba0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
34 changes: 34 additions & 0 deletions .github/scripts/pack.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
param (
[ValidateScript({ $_ -ge 0 })]
[int]$PullRequestNumber = 0,
[ValidateScript({ ($_ -eq "") -or (Test-Path $_) })]
[string]$KeyPath = ""
)

$namespaces = @{
ns = "http://schemas.microsoft.com/developer/msbuild/2003"
}
$propsPath = "Directory.Build.props"
$fileVersionPath = "/ns:Project/ns:PropertyGroup/ns:FileVersion"
$result = Select-Xml -Path $propsPath -Namespace $namespaces -XPath $fileVersionPath
if ($null -eq $result) {
Write-Host "File version not found"
exit 1
}

$fileVersion = $result.Node.InnerText
if ($PullRequestNumber) {
$fileVersion = "$fileVersion-pr.$PullRequestNumber"
}

$options = @(
"-o pack"
"-p:FileVersion='$fileVersion'"
)

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 " ")"
17 changes: 11 additions & 6 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Pack

on:
pull_request:

jobs:
pack:
runs-on: ubuntu-latest
Expand All @@ -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 }}

0 comments on commit 4ff5ba0

Please sign in to comment.