Skip to content

Commit 880cb33

Browse files
authored
Add CI (#24)
1 parent c6854cf commit 880cb33

File tree

3 files changed

+171
-1
lines changed

3 files changed

+171
-1
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 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

.github/workflows/codeql.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: '32 19 * * 5'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'csharp' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v3
31+
with:
32+
languages: ${{ matrix.language }}
33+
34+
- name: Auto build
35+
uses: github/codeql-action/autobuild@v3
36+
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v3
39+
with:
40+
category: "/language:${{matrix.language}}"

BuildSettings.psd1

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
@{
22
Path = @(
3-
'./src/code/bin/Release/netstandard2.0/NuGetProvider.dll',
3+
'./src/code/bin/Release/netstandard2.0/publish/*'
44
'./src/AnyPackage.NuGet.psd1'
55
)
66
Destination = './module'
7+
Exclude = @(
8+
'NuGetProvider.deps.json',
9+
'*.pdb'
10+
)
711
}

0 commit comments

Comments
 (0)