Skip to content

Commit e02a266

Browse files
committed
Add CI
1 parent adb3ca3 commit e02a266

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

.github/workflows/ci.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

.github/workflows/lint-powershell.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: PSScriptAnalyzer
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: '22 1 * * 3'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
permissions:
17+
contents: read
18+
security-events: write
19+
name: PSScriptAnalyzer
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- name: Run PSScriptAnalyzer
25+
uses: microsoft/[email protected]
26+
with:
27+
path: .\
28+
recurse: true
29+
output: results.sarif
30+
31+
- name: Upload SARIF results file
32+
uses: github/codeql-action/upload-sarif@v2
33+
with:
34+
sarif_file: results.sarif

PSScriptAnalyzerSettings.psd1

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ExcludeRules = @(
3+
'PSAvoidUsingInvokeExpression',
4+
'PSAvoidUsingPositionalParameters'
5+
)
6+
}

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 = @('LockFile.psd1', 'LockFile.psm1')
3+
TimeStampServer = 'http://timestamp.sectigo.com'
4+
HashAlgorithm = 'SHA256'
5+
}

0 commit comments

Comments
 (0)