-
Notifications
You must be signed in to change notification settings - Fork 13
158 lines (136 loc) · 4.45 KB
/
CI.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: SteamPS CI/CD workflow
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
release:
types:
- published
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
POWERSHELL_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
BUILD_CONFIGURATION: ${{ fromJSON('["Debug", "Release"]')[startsWith(github.ref, 'refs/tags/v')] }}
jobs:
build:
name: 👷 Build
runs-on: windows-latest
steps:
- name: 🚚 Check out repository
uses: actions/checkout@v4
- name: 🐛 Build module - Debug
shell: pwsh
run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Build
if: ${{ env.BUILD_CONFIGURATION == 'Debug' }}
- name: 🚀 Build module - Publish
shell: pwsh
run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Build
if: ${{ env.BUILD_CONFIGURATION == 'Release' }}
- name: 📦 Capture PowerShell Module
uses: actions/upload-artifact@v4
with:
name: PSModule
path: output/*.nupkg
test:
name: 🧪 Test
needs:
- build
runs-on: ${{ matrix.info.os }}
strategy:
fail-fast: false
matrix:
info:
- name: 🪟 Win2019_PS-5.1
psversion: '5.1'
os: windows-2019
- name: 🪟 Win2019_PS-7
psversion: '7'
os: windows-2019
- name: 🪟 Win2022_PS-5.1
psversion: '5.1'
os: windows-latest
- name: 🪟 Win2022_PS-7
psversion: '7'
os: windows-latest
steps:
- name: 🚚 Checkout
uses: actions/checkout@v4
- name: ➕ Restore Built PowerShell Module
uses: actions/download-artifact@v4
with:
name: PSModule
path: output
- name: 📦 Install Built PowerShell Module
shell: pwsh
run: |
# Get the manifest from the newly built module.
$manifestItem = Get-Item ([IO.Path]::Combine('SteamPS', '*.psd1'))
$moduleName = $manifestItem.BaseName
$Manifest = Test-ModuleManifest -Path $manifestItem.FullName -ErrorAction SilentlyContinue -WarningAction Ignore
if ($env:BUILD_CONFIGURATION -eq 'Release') {
$Version = $env:GITHUB_REF -replace '^refs/tags/v(\d+\.\d+\.\d+)', '$1'
} else {
$Version = $Manifest.Version
}
$destPath = [IO.Path]::Combine('output', $moduleName, $Version)
if (-not (Test-Path -LiteralPath $destPath)) {
New-Item -Path $destPath -ItemType Directory | Out-Null
}
Get-ChildItem output/*.nupkg | Rename-Item -NewName { $_.Name -replace '.nupkg', '.zip' }
Expand-Archive -Path output/*.zip -DestinationPath $destPath -Force -ErrorAction Stop
- name: 🧪 Run Tests - Windows PowerShell
if: ${{ matrix.info.psversion == '5.1' }}
shell: powershell
run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Test
- name: 🧪 Run Tests - PowerShell
if: ${{ matrix.info.psversion != '5.1' }}
shell: pwsh
run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Test
- name: ⬆️ Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: Unit Test Results (${{ matrix.info.name }})
path: ./output/TestResults/Pester.xml
- name: ⬆️ Upload Coverage Results
if: always() && !startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: Coverage Results (${{ matrix.info.name }})
path: ./output/TestResults/Coverage.xml
- name: ⬆️ Upload Coverage to codecov
if: always() && !startsWith(github.ref, 'refs/tags/v')
uses: codecov/codecov-action@v4
with:
files: ./output/TestResults/Coverage.json
flags: ${{ matrix.info.name }}
token: ${{ secrets.CODECOV_TOKEN }}
publish:
name: 🚀 Deploy
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build
- test
runs-on: windows-latest
steps:
- name: ➕ Restore Built PowerShell Module
uses: actions/download-artifact@v4
with:
name: PSModule
path: ./
- name: 🚀 Publish to Gallery
if: github.event_name == 'release'
shell: pwsh
run: >-
dotnet nuget push '*.nupkg'
--api-key $env:PSGALLERY_TOKEN
--source 'https://www.powershellgallery.com/api/v2/package'
--no-symbols
env:
PSGALLERY_TOKEN: ${{ secrets.PS_GALLERY_KEY }}