Skip to content

Commit 4bb25ba

Browse files
authored
Create ci.yml
1 parent 894b9ac commit 4bb25ba

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Run Pester tests
12+
runs-on: windows-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Install Pester
19+
shell: pwsh
20+
run: |
21+
Install-Module Pester -Force -Scope CurrentUser
22+
Import-Module Pester
23+
24+
- name: Run tests
25+
shell: pwsh
26+
run: |
27+
Invoke-Pester -Path .\tests -Output Summary -EnableExit
28+
29+
publish:
30+
name: Publish to PowerShell Gallery
31+
needs: test
32+
runs-on: windows-latest
33+
# Only run on tags like v1.0.1
34+
if: startsWith(github.ref, 'refs/tags/v')
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Install PowerShellGet + Pester
41+
shell: pwsh
42+
run: |
43+
Install-Module PowerShellGet -Force -Scope CurrentUser
44+
Install-Module Pester -Force -Scope CurrentUser
45+
46+
# OPTIONAL: import code-signing certificate from secret (advanced)
47+
# Store a base64-encoded PFX + password in GitHub secrets:
48+
# CODESIGNING_CERT_PFX
49+
# CODESIGNING_CERT_PASSWORD
50+
- name: Import code-signing certificate
51+
if: env.CODESIGNING_CERT_PFX != ''
52+
shell: pwsh
53+
env:
54+
CODESIGNING_CERT_PFX: ${{ secrets.CODESIGNING_CERT_PFX }}
55+
CODESIGNING_CERT_PASSWORD: ${{ secrets.CODESIGNING_CERT_PASSWORD }}
56+
run: |
57+
$pfxBytes = [Convert]::FromBase64String($env:CODESIGNING_CERT_PFX)
58+
$pfxPath = Join-Path $env:USERPROFILE 'codesign.pfx'
59+
[IO.File]::WriteAllBytes($pfxPath, $pfxBytes)
60+
61+
$securePassword = ConvertTo-SecureString $env:CODESIGNING_CERT_PASSWORD -AsPlainText -Force
62+
$cert = Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation Cert:\CurrentUser\My -Password $securePassword
63+
64+
Write-Host "Imported code signing cert: $($cert.Thumbprint)"
65+
66+
# Sign the module files
67+
$filesToSign = @(
68+
'OffsetInspect.psm1',
69+
'OffsetInspect.ps1'
70+
) | ForEach-Object { Join-Path $PWD $_ }
71+
72+
foreach ($file in $filesToSign) {
73+
Write-Host "Signing $file"
74+
Set-AuthenticodeSignature -FilePath $file -Certificate $cert | Out-String | Write-Host
75+
}
76+
77+
- name: Publish module to PSGallery
78+
shell: pwsh
79+
env:
80+
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
81+
run: |
82+
if (-not $env:PSGALLERY_API_KEY) {
83+
throw "PSGALLERY_API_KEY secret is not set."
84+
}
85+
86+
$path = $PWD # repo root containing OffsetInspect.psd1
87+
Publish-Module -Path $path `
88+
-Repository PSGallery `
89+
-NuGetApiKey $env:PSGALLERY_API_KEY `
90+
-Verbose

0 commit comments

Comments
 (0)