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 29, 2024
1 parent 2dfb05a commit 0028216
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
35 changes: 35 additions & 0 deletions .github/scripts/pack.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/local/bin/pwsh
param (
[ValidateScript({ ($_ -eq "") -or !(Test-Path $_ -PathType Leaf) })]
[string]$OutputPath = "",
[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
$KeyPath = $KeyPath ? $(Resolve-Path -Path $KeyPath) : ""
$OutputPath = $OutputPath ? [System.IO.Path]::GetFullPath($OutputPath) : ""
$keyPathExits = Test-Path -Path $KeyPath

$options = @(
$OutputPath ? "-o '$OutputPath'" : ""
"-p:FileVersion='$fileVersion'"
$PullRequestNumber ? "--version-suffix pr.$PullRequestNumber" : ""
$keyPathExits ? "-p:TreatWarningsAsErrors=true" : ""
$keyPathExits ? "-p:AssemblyOriginatorKeyFile='$KeyPath'" : ""
) | Where-Object { $_ }

Invoke-Expression -Command "dotnet pack $($options -join " ")"
18 changes: 12 additions & 6 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ name: Pack

on:
pull_request:

push:
branches:
- main
tags:
- "*"

jobs:
pack:
runs-on: ubuntu-latest
Expand All @@ -12,8 +17,9 @@ 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
- if: ${{ github.event_name == 'pull_request' }}
run: |
.github/scripts/pack.ps1 `
-PullRequestNumber ${{ github.event.pull_request.number }} `
-KeyPath "$pwd/private.snk"
shell: pwsh
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ SOFTWARE. -->
<Copyright>Copyright (c) 2024 Jeesu Choi</Copyright>
<Description>grpc-based communication library for crema project</Description>
<Authors>s2quake</Authors>
<PackageVersion>$(FileVersion)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)'==''">$(FileVersion)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)'!=''">$(FileVersion)-$(VersionSuffix)</PackageVersion>
<PackageProjectUrl>https://github.com/s2quake/communication</PackageProjectUrl>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
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 0028216

Please sign in to comment.