-
Notifications
You must be signed in to change notification settings - Fork 10
170 lines (147 loc) · 5.48 KB
/
ci-build.yaml
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
159
160
161
162
163
164
165
166
167
168
169
170
###########################################################################
# #
# Copyright (c) Microsoft Corporation. All rights reserved. #
# #
# This code is licensed under the MIT License (MIT). #
# #
###########################################################################
name: CI Build
on:
workflow_dispatch:
inputs:
runner:
description: "Windows runner image"
required: false
default: windows-2022
type: choice
options:
- windows-latest
- windows-2022
- windows-2019
pull_request:
branches: ["main", "releases/**"]
paths-ignore:
- "docs/**"
- "*.md"
- en-US/**"
env:
MODULE_DIR: .\Containers-Toolkit
BUILD_SCRIPTS_DIR: .\build\scripts
PESTER_RESULTS_DIR: .\TestResults
MODULE_ARTIFACT: CTK.Module.Scripts
REPO_ARTIFACT: CTK.Scripts
jobs:
lint:
runs-on: ${{ github.event.inputs.RUNNER || 'windows-2022' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# FIXME: Fix cache not working
- name: Setup PowerShell module cache
id: cacher
uses: actions/cache@v3
with:
path: "C:\\program files\\powershell\\7\\Modules"
key: ${{ runner.os }}-CTK
- name: Install required PowerShell modules
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
$ModuleName = 'PSScriptAnalyzer'
if (-not (Get-Module -ListAvailable -Name $ModuleName)) {
Write-Output "Modules to install: '$ModuleName'"
Install-Module $ModuleName -ErrorAction Stop -AllowClobber -SkipPublisherCheck -Force
}
- name: Run code analysis with PSScriptAnalyzer
id: code_analysis
shell: pwsh
run: |
${{ env.BUILD_SCRIPTS_DIR }}\script-analyzer.ps1 | Out-File -FilePath lintsummary.md -Encoding utf8 -Force
cat lintsummary.md >> $env:GITHUB_STEP_SUMMARY
$fileExists = Test-Path ./psscriptanalysis.xml
echo "LINTSUMMARY_EXISTS=$fileExists" >> $env:GITHUB_OUTPUT
- name: Publish PSScriptAnalyzer results file
if: steps.code_analysis.outputs.LINTSUMMARY_EXISTS == 'true'
uses: actions/upload-artifact@v4
with:
name: PSScriptAnalyzer.Results
path: psscriptanalysis.xml
if-no-files-found: error
overwrite: true
pester:
# TODO: Add Windows ARM64 support
runs-on: ${{ github.event.inputs.RUNNER || 'windows-2022' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# FIXME: Fix cache not working
- name: Setup PowerShell module cache
id: cacher
uses: actions/cache@v3
with:
path: "C:\\program files\\powershell\\7\\Modules"
key: ${{ runner.os }}-CTK
- name: Install required PowerShell modules
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
$requiredModules = @('Pester')
$missingModules = $requiredModules | Where-Object { -not (Get-Module -ListAvailable -Name $_) }
if ($missingModules) {
Write-Output "Modules to install: $($missingModules -join ', ')"
Install-Module $missingModules -ErrorAction Stop -AllowClobber -SkipPublisherCheck -Force
}
- name: Run Pester tests
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
${{ env.BUILD_SCRIPTS_DIR }}\run-tests.ps1
- name: Publish Pester results
uses: actions/upload-artifact@v4
with:
name: CTK.Pester.Results
path: ${{ env.PESTER_RESULTS_DIR }}\Test-Results.xml
if-no-files-found: error
overwrite: true
- name: Publish code coverage results
uses: actions/upload-artifact@v4
with:
name: CTK.Coverage.Summary
path: ${{ env.PESTER_RESULTS_DIR }}\coverage.xml
if-no-files-found: error
overwrite: true
test-coverage:
needs: pester
runs-on: ubuntu-latest
steps:
- name: Download coverage results artifact
uses: actions/download-artifact@v4
with:
name: CTK.Coverage.Summary
- name: Setup .NET Core # Required to execute ReportGenerator
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
dotnet-quality: "ga"
- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: coverage.xml
targetdir: coveragereport
reporttypes: HtmlInline;MarkdownSummaryGithub;Badges
historydir: coveragehistory
- name: Upload coverage report artifact
uses: actions/upload-artifact@v4
with:
name: coveragereport # Artifact name
path: coveragereport # Directory containing files to upload
- name: Publish coverage summary
uses: marocchino/sticky-pull-request-comment@v2
continue-on-error: true
with:
path: coveragereport/SummaryGithub.md
- name: Post results
run: |
cat coveragereport/SummaryGithub.md >> $env:GITHUB_STEP_SUMMARY