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