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 0868507
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/pack.ps1
Original file line number Diff line number Diff line change
@@ -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 " ")"
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 }}
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ SOFTWARE. -->
<TargetFrameworks Condition="'$(_IsPacking)'=='true'">net6.0;net7.0;net8.0;netstandard2.1</TargetFrameworks>
<TargetFramework Condition="'$(_IsPacking)'!='true'">net8.0</TargetFramework>
<AssemblyVersion>2.0</AssemblyVersion>
<FileVersion>2.0.3</FileVersion>
<VersionPrefix>2.0.3</VersionPrefix>
<FileVersion>$(VersionPrefix)</FileVersion>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/s2quake/communication</RepositoryUrl>
<LicenseUrl>https://github.com/s2quake/communication/blob/main/LICENSE.md</LicenseUrl>
Expand Down
5 changes: 0 additions & 5 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ SOFTWARE. -->
<DesiredPublishDirTemp Condition="'$(PublishDir)' != '$(DesiredPublishDir)'">$(PublishDir)</DesiredPublishDirTemp>
<DesiredPublishDir>$(DesiredPublishDirTemp)</DesiredPublishDir>
</PropertyGroup>
<Target Name="BeforeBuild">
<PropertyGroup>
<Version>$(FileVersion)-$(TargetFramework)</Version>
</PropertyGroup>
</Target>
<Target Name="AfterBuild">
<PropertyGroup Condition="'$(PublishName)' != ''">
<PublishDir>$([System.IO.Path]::Combine($(DesiredPublishDir),$(PublishName)))</PublishDir>
Expand Down

0 comments on commit 0868507

Please sign in to comment.