Browse Source

housekeeping: Update build script and CI

Bruce Wayne 3 years ago
parent
commit
759d14c501
2 changed files with 40 additions and 62 deletions
  1. 25 39
      .github/workflows/CI.yaml
  2. 15 23
      build.ps1

+ 25 - 39
.github/workflows/CI.yaml

@@ -1,22 +1,13 @@
 name: CI
-on:
-  push:
-    branches:
-      - master
-      - 'renovate/**'
-    tags:
-      - "*"
-  pull_request:
-  workflow_dispatch:
+on: [push, pull_request, workflow_dispatch]
 env:
-  ProjectName: NatTypeTester
+  ProjectName: ${{ github.event.repository.name }}
   NET_TFM: net6.0-windows
   Configuration: Release
 
 jobs:
   check_format:
-    name: Check format
-    runs-on: windows-latest
+    runs-on: ubuntu-latest
     steps:
       - name: Setup .NET
         uses: actions/setup-dotnet@v2
@@ -30,11 +21,13 @@ jobs:
         run: dotnet format -v diag --verify-no-changes
 
   test:
-    name: Test
     runs-on: ${{ matrix.os }}
     strategy:
       matrix:
-        os: [ubuntu-latest, windows-latest, macos-latest]
+        os:
+          - windows-latest
+          - ubuntu-latest
+          - macos-latest
 
     steps:
       - name: Checkout code
@@ -45,39 +38,33 @@ jobs:
         with:
           dotnet-version: 6.0.x
 
-      - name: Test
-        shell: pwsh
-        run: dotnet test -c Release UnitTest
+      - name: Run tests
+        working-directory: UnitTest
+        run: dotnet test -c Release
 
   build:
     name: Build
     needs: [test, check_format]
     if: ${{ !startsWith(github.ref, 'refs/tags/') }}
     runs-on: windows-latest
-    strategy:
-      matrix:
-        Rid: [generic, win-x64, win-x86, win-arm64]
     steps:
       - name: Checkout code
         uses: actions/checkout@v3
-        with:
-          submodules: true
 
       - name: Setup .NET
         uses: actions/setup-dotnet@v2
         with:
           dotnet-version: 6.0.x
 
-      - name: Build ${{ matrix.Rid }}
+      - name: Build
         shell: pwsh
-        run: .\build.ps1 ${{ matrix.Rid }}
+        run: .\build.ps1
 
-      - name: Upload ${{ matrix.Rid }}
-        continue-on-error: true
+      - name: Upload
         uses: actions/upload-artifact@v3
         with:
-          name: ${{ env.ProjectName }}-${{ matrix.Rid }}
-          path: ${{ env.ProjectName }}\bin\${{ env.Configuration }}\${{ env.NET_TFM }}\${{ matrix.Rid }}\publish\
+          name: ${{ env.ProjectName }}
+          path: ${{ env.ProjectName }}\bin\${{ env.Configuration }}\${{ env.NET_TFM }}\generic\publish\
 
   nuget:
     name: Nuget
@@ -86,7 +73,8 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        PackageName: [STUN]
+        PackageName:
+          - STUN
 
     steps:
       - name: Checkout code
@@ -98,14 +86,14 @@ jobs:
           dotnet-version: 6.0.x
 
       - name: Build
-        shell: pwsh
-        run: dotnet build -c Release ${{ matrix.PackageName }}\${{ matrix.PackageName }}.csproj
+        working-directory: ${{ matrix.PackageName }}
+        run: dotnet build -c Release
 
       - name: Push nuget packages
-        shell: pwsh
+        working-directory: ${{ matrix.PackageName }}/bin/Release
         run: |
-          dotnet nuget push ${{ matrix.PackageName }}\bin\Release\*.nupkg -s https://nuget.pkg.github.com/HMBSbige -k ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
-          dotnet nuget push ${{ matrix.PackageName }}\bin\Release\*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NuGetAPIKey }} --skip-duplicate
+          dotnet nuget push *.nupkg -s https://nuget.pkg.github.com/HMBSbige -k ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
+          dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NuGetAPIKey }} --skip-duplicate
 
   release:
     name: Release
@@ -115,8 +103,6 @@ jobs:
     steps:
       - name: Checkout code
         uses: actions/checkout@v3
-        with:
-          submodules: true
 
       - name: Setup .NET
         uses: actions/setup-dotnet@v2
@@ -131,11 +117,11 @@ jobs:
         id: tag
         uses: dawidd6/action-get-tag@v1
 
-      - name: Package generic
+      - name: Package
         shell: pwsh
         run: |
           New-Item -ItemType Directory -Path C:\builtfiles -Force > $null
-          $zip_path = "C:\builtfiles\$env:ProjectName-generic-${{ steps.tag.outputs.tag }}.7z"
+          $zip_path = "C:\builtfiles\$env:ProjectName-${{ steps.tag.outputs.tag }}.7z"
           7z a -mx9 "$zip_path" ".\$env:ProjectName\bin\$env:Configuration\$env:NET_TFM\generic\publish\"
           7z rn "$zip_path" publish $env:ProjectName
           echo "GENERIC_SHA256=$((Get-FileHash $zip_path -Algorithm SHA256).Hash)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
@@ -156,4 +142,4 @@ jobs:
             ## Hash
             | Filename | SHA-256 |
             | :- | :- |
-            | <sub>${{ env.ProjectName }}-generic-${{ steps.tag.outputs.tag }}.7z</sub> | <sub>${{ env.GENERIC_SHA256 }}</sub> |
+            | <sub>${{ env.ProjectName }}-${{ steps.tag.outputs.tag }}.7z</sub> | <sub>${{ env.GENERIC_SHA256 }}</sub> |

+ 15 - 23
build.ps1

@@ -1,7 +1,5 @@
-param([string]$rid = 'all')
 $ErrorActionPreference = 'Stop'
 
-Write-Host 'dotnet SDK info'
 dotnet --info
 
 $proj = 'NatTypeTester'
@@ -10,12 +8,12 @@ $net_tfm = 'net6.0-windows'
 $configuration = 'Release'
 $output_dir = "$PSScriptRoot\$proj\bin\$configuration"
 $proj_path = "$PSScriptRoot\$proj\$proj.csproj"
+$generic_outdir = "$output_dir\$net_tfm\generic"
 
-function Build-Generic
-{
+function Build-Generic {
     Write-Host 'Building generic'
 
-    $outdir = "$output_dir\$net_tfm\generic"
+    $outdir = $generic_outdir
     $publishDir = "$outdir\publish"
 
     Remove-Item $publishDir -Recurse -Force -Confirm:$false -ErrorAction Ignore
@@ -25,12 +23,14 @@ function Build-Generic
 
     & "$PSScriptRoot\Build\DotNetDllPathPatcher.ps1" "$publishDir\$exe" bin
     if ($LASTEXITCODE) { exit $LASTEXITCODE }
+
+    Remove-Item "$publishDir\$exe"
 }
 
-function Build-SelfContained
-{
-    param([string]$rid)
+function Build {
+    param([string]$arch)
 
+    $rid = "win-$arch"
     Write-Host "Building $rid"
 
     $outdir = "$output_dir\$net_tfm\$rid"
@@ -38,25 +38,17 @@ function Build-SelfContained
 
     Remove-Item $publishDir -Recurse -Force -Confirm:$false -ErrorAction Ignore
 
-    dotnet publish -c $configuration -f $net_tfm -r $rid --self-contained true $proj_path
+    dotnet publish -c $configuration -f $net_tfm -r $rid --no-self-contained true $proj_path
     if ($LASTEXITCODE) { exit $LASTEXITCODE }
 
     & "$PSScriptRoot\Build\DotNetDllPathPatcher.ps1" "$publishDir\$exe" bin
     if ($LASTEXITCODE) { exit $LASTEXITCODE }
-}
 
-if($rid -eq 'all' -or $rid -eq 'generic')
-{
-    Build-Generic
+    Move-Item "$publishDir\$exe" "$generic_outdir\publish\$proj-$arch.exe"
 }
 
-if($rid -eq 'all')
-{
-    Build-SelfContained win-x86
-    Build-SelfContained win-x64
-    Build-SelfContained win-arm64
-}
-elseif($rid -ne 'generic')
-{
-    Build-SelfContained $rid
-}
+Build-Generic
+Build x64
+Build x86
+Build arm64
+Build arm