|
| 1 | +name: CI |
| 2 | + |
| 3 | +defaults: |
| 4 | + run: |
| 5 | + shell: pwsh |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [ main ] |
| 10 | + |
| 11 | + pull_request: |
| 12 | + branches: [ main ] |
| 13 | + |
| 14 | + release: |
| 15 | + types: [ published ] |
| 16 | + |
| 17 | +jobs: |
| 18 | + Build: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout Repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: .NET Build |
| 25 | + run: dotnet publish --configuration Release |
| 26 | + |
| 27 | + - name: Create module |
| 28 | + run: | |
| 29 | + New-Item module -ItemType Directory |
| 30 | + $settings = Import-PowerShellDataFile ./BuildSettings.psd1 |
| 31 | + Copy-Item @settings |
| 32 | +
|
| 33 | + - name: Upload module |
| 34 | + uses: actions/upload-artifact@v4 |
| 35 | + with: |
| 36 | + name: module |
| 37 | + path: ./module/ |
| 38 | + |
| 39 | + Test: |
| 40 | + needs: Build |
| 41 | + runs-on: windows-latest |
| 42 | + steps: |
| 43 | + - name: Checkout Repository |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Download module |
| 47 | + uses: actions/download-artifact@v4 |
| 48 | + with: |
| 49 | + name: module |
| 50 | + path: C:\Users\runneradmin\Documents\PowerShell\Modules\AnyPackage.NuGet\ |
| 51 | + |
| 52 | + - name: Install AnyPackage module |
| 53 | + run: Install-Module AnyPackage -Force -AllowClobber |
| 54 | + |
| 55 | + - name: Test with Pester |
| 56 | + run: | |
| 57 | + $ht = Import-PowerShellDataFile PesterSettings.psd1 |
| 58 | + $config = New-PesterConfiguration $ht |
| 59 | + Invoke-Pester -Configuration $config |
| 60 | +
|
| 61 | + Sign: |
| 62 | + needs: Test |
| 63 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 64 | + runs-on: windows-latest |
| 65 | + steps: |
| 66 | + - name: Checkout Repository |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Download module |
| 70 | + uses: actions/download-artifact@v4 |
| 71 | + with: |
| 72 | + name: module |
| 73 | + path: module |
| 74 | + |
| 75 | + - name: Import certificate |
| 76 | + env: |
| 77 | + CERTIFICATE_BASE64: ${{ secrets.CERTIFICATE_BASE64 }} |
| 78 | + CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }} |
| 79 | + CERTIFICATE_PASSWORD_KEY_BASE64: ${{ secrets.CERTIFICATE_PASSWORD_KEY_BASE64 }} |
| 80 | + run: | |
| 81 | + [convert]::FromBase64String($env:CERTIFICATE_BASE64) | Set-Content -Path cert.pfx -AsByteStream |
| 82 | + $key = [convert]::FromBase64String($env:CERTIFICATE_PASSWORD_KEY_BASE64) |
| 83 | + $password = ConvertTo-SecureString $env:CERTIFICATE_PASSWORD -Key $key |
| 84 | + Import-PfxCertificate cert.pfx -Password $password -CertStoreLocation Cert:\CurrentUser\My |
| 85 | +
|
| 86 | + - name: Sign files |
| 87 | + run: | |
| 88 | + $config = Import-PowerShellDataFile SignSettings.psd1 |
| 89 | + $config['Certificate'] = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert |
| 90 | + Set-Location .\module |
| 91 | + Set-AuthenticodeSignature @config |
| 92 | +
|
| 93 | + - name: Create and sign catalog file |
| 94 | + run: | |
| 95 | + $config = Import-PowerShellDataFile SignSettings.psd1 |
| 96 | + $config['FilePath'] = 'AnyPackage.NuGet.cat' |
| 97 | + $config['Certificate'] = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert |
| 98 | + Set-Location .\module |
| 99 | + New-FileCatalog $config['FilePath'] -CatalogVersion 2 |
| 100 | + Set-AuthenticodeSignature @config |
| 101 | +
|
| 102 | + - name: Upload module |
| 103 | + uses: actions/upload-artifact@v4 |
| 104 | + with: |
| 105 | + name: module-signed |
| 106 | + path: ./module/ |
| 107 | + |
| 108 | + Publish: |
| 109 | + needs: Sign |
| 110 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 111 | + runs-on: ubuntu-latest |
| 112 | + steps: |
| 113 | + |
| 114 | + - name: Download module |
| 115 | + uses: actions/download-artifact@v4 |
| 116 | + with: |
| 117 | + name: module-signed |
| 118 | + path: '~/.local/share/powershell/Modules/AnyPackage.NuGet' |
| 119 | + |
| 120 | + - name: Install AnyPackage module |
| 121 | + run: Install-Module AnyPackage -Force -AllowClobber |
| 122 | + |
| 123 | + - name: Publish Module |
| 124 | + env: |
| 125 | + NUGET_KEY: ${{ secrets.NUGET_KEY }} |
| 126 | + run: Publish-Module -Name AnyPackage.NuGet -NuGetApiKey $env:NUGET_KEY |
0 commit comments