Skip to content

Commit 1b00c8f

Browse files
committed
Add CI
1 parent 45f3882 commit 1b00c8f

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

.github/workflows/ci.yml

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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 build --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.Wsl\
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.Wsl.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.Wsl'
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.Wsl -NuGetApiKey $env:NUGET_KEY

BuildSettings.psd1

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
Path = @(
3+
'./src/code/bin/Release/netstandard2.0/WslProvider.dll',
4+
'./src/AnyPackage.Wsl.psd1'
5+
)
6+
Destination = './module'
7+
}

PesterSettings.psd1

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
Run = @{
3+
Exit = $true
4+
}
5+
Output = @{
6+
Verbosity = 'Detailed'
7+
}
8+
}

SignSettings.psd1

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@{
2+
FilePath = @('AnyPackage.Wsl.psd1', 'WslProvider.dll')
3+
TimeStampServer = 'http://timestamp.sectigo.com'
4+
HashAlgorithm = 'SHA256'
5+
}

0 commit comments

Comments
 (0)