Repository navigation
194 lines (164 loc) · 6.6 KB
/
Copy pathci.yml
File metadata and controls
194 lines (164 loc) · 6.6 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: CI Build
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
DOTNET_VERSION: '8.0.x'
DOTNET_VERSION_PREVIEW: '10.0.x'
SOLUTION_PATH: 'Source/Current/Windows API CodePack/Windows API CodePack.sln'
jobs:
build:
name: Build and Test
runs-on: windows-latest
strategy:
matrix:
configuration: [Debug, Release]
platform: [Any CPU, x64, x86]
exclude:
# Exclude x86 for .NET 8+ projects as they don't support x86
- configuration: Debug
platform: x86
- configuration: Release
platform: x86
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set build version
id: set-version
run: |
# Read base version from Directory.Build.props
$versionFile = "Directory.Build.props"
$content = Get-Content $versionFile -Raw
if ($content -match '<LibraryVersion>([\d\.]+)</LibraryVersion>') {
$baseVersion = $matches[1]
} else {
$baseVersion = "8.0.10"
}
# Add GitHub run number as build number
$buildNumber = ${{ github.run_number }}
$fullVersion = "$baseVersion.$buildNumber"
Write-Host "Base Version: $baseVersion"
Write-Host "Build Number: $buildNumber"
Write-Host "Full Version: $fullVersion"
echo "base-version=$baseVersion" >> $env:GITHUB_OUTPUT
echo "build-number=$buildNumber" >> $env:GITHUB_OUTPUT
echo "full-version=$fullVersion" >> $env:GITHUB_OUTPUT
# Set as environment variable for subsequent steps
echo "BUILD_VERSION=$fullVersion" >> $env:GITHUB_ENV
shell: pwsh
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ env.DOTNET_VERSION }}
${{ env.DOTNET_VERSION_PREVIEW }}
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.3
- name: Restore NuGet packages
run: |
dotnet restore "${{ env.SOLUTION_PATH }}" --verbosity normal
working-directory: .
- name: Build .NET projects
run: |
dotnet build "${{ env.SOLUTION_PATH }}" `
--configuration ${{ matrix.configuration }} `
--platform ${{ matrix.platform }} `
--no-restore `
--verbosity normal `
/p:AssemblyVersion=${{ steps.set-version.outputs.full-version }} `
/p:FileVersion=${{ steps.set-version.outputs.full-version }} `
/p:InformationalVersion=${{ steps.set-version.outputs.full-version }}+${{ github.sha }}
working-directory: .
- name: Run tests
run: |
dotnet test "${{ env.SOLUTION_PATH }}" --configuration ${{ matrix.configuration }} --platform ${{ matrix.platform }} --no-build --verbosity normal --logger trx --results-directory TestResults
working-directory: .
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.configuration }}-${{ matrix.platform }}
path: TestResults/
retention-days: 30
- name: Display version info
if: matrix.configuration == 'Release' && matrix.platform == 'Any CPU'
run: |
Write-Host "═══════════════════════════════════════════════════════"
Write-Host " BUILD INFORMATION"
Write-Host "═══════════════════════════════════════════════════════"
Write-Host "Base Version: ${{ steps.set-version.outputs.base-version }}"
Write-Host "Build Number: ${{ steps.set-version.outputs.build-number }}"
Write-Host "Full Version: ${{ steps.set-version.outputs.full-version }}"
Write-Host "Git SHA: ${{ github.sha }}"
Write-Host "Branch: ${{ github.ref_name }}"
Write-Host "Configuration: ${{ matrix.configuration }}"
Write-Host "Platform: ${{ matrix.platform }}"
Write-Host "═══════════════════════════════════════════════════════"
shell: pwsh
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: matrix.configuration == 'Release'
with:
name: build-artifacts-${{ matrix.platform }}-v${{ steps.set-version.outputs.full-version }}
path: |
Output/bin/Release/
Source/Current/Windows API CodePack/Components/*/bin/Release/
retention-days: 30
package-validation:
name: Package Validation
runs-on: windows-latest
needs: build
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore and pack NuGet packages
run: |
dotnet pack "${{ env.SOLUTION_PATH }}" --configuration Release --verbosity normal --output ./packages
working-directory: .
- name: Validate package contents
run: |
Get-ChildItem -Path "./packages" -Filter "*.nupkg" | ForEach-Object {
Write-Host "Validating package: $($_.Name)"
# Basic validation - check if package exists and has reasonable size
if ($_.Length -lt 1KB) {
Write-Error "Package $($_.Name) is too small, likely corrupted"
exit 1
}
Write-Host "Package $($_.Name) validation passed"
}
shell: pwsh
- name: Upload validation packages
uses: actions/upload-artifact@v4
with:
name: validation-packages
path: packages/
retention-days: 7
security-scan:
name: Security Scan
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Run security audit
run: |
dotnet list "${{ env.SOLUTION_PATH }}" package --vulnerable --include-transitive
working-directory: .
continue-on-error: true
- name: Run dependency check
run: |
dotnet list "${{ env.SOLUTION_PATH }}" package --outdated
working-directory: .
continue-on-error: true