-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (178 loc) · 6.5 KB
/
Copy pathbuild-and-publish.yml
File metadata and controls
204 lines (178 loc) · 6.5 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
195
196
197
198
199
200
201
202
203
204
name: Build and Publish
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
release:
types: [ published ]
workflow_dispatch:
env:
DOTNET_VERSION: '10.0.x'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1
jobs:
build:
name: Build and Test
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for versioning
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Display .NET version
run: dotnet --version
- name: Build solution
run: |
cd src
.\build.ps1 -Configuration Release -SkipTests
shell: pwsh
- name: Run tests with coverage
run: |
cd src
.\build.ps1 -Configuration Release -TestOnly -EnableCodeCoverage -GenerateTestReport
shell: pwsh
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: src/TestResults/**/*
retention-days: 30
- name: Upload code coverage
if: always()
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: src/TestResults/Coverage/**/*
retention-days: 30
- name: Publish test results
if: always()
uses: EnricoMi/publish-unit-test-result-action/windows@v2
with:
files: src/TestResults/**/*.trx
check_name: Test Results
comment_mode: off
- name: Code Coverage Report
if: always()
uses: danielpalme/ReportGenerator-GitHub-Action@5.5.1
with:
reports: 'src/TestResults/Coverage/coverage.cobertura.xml'
targetdir: 'src/TestResults/CoverageReport'
reporttypes: 'MarkdownSummaryGithub;Html'
filefilters: '-*.g.cs'
verbosity: 'Info'
- name: Write Coverage Summary to Job Summary
if: always()
run: |
if (Test-Path src/TestResults/CoverageReport/SummaryGithub.md) {
Get-Content src/TestResults/CoverageReport/SummaryGithub.md >> $env:GITHUB_STEP_SUMMARY
}
shell: pwsh
- name: Add Coverage PR Comment
if: github.event_name == 'pull_request' && always()
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
path: src/TestResults/CoverageReport/SummaryGithub.md
- name: Create NuGet packages
if: github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch'
run: |
cd src
$version = "1.0.${{ github.run_number }}"
Write-Host "Creating packages with version: $version"
.\build.ps1 -Configuration Release -PackOnly -PackageOutputPath "${{ github.workspace }}/packages" -Version $version
shell: pwsh
- name: Upload NuGet packages
if: github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: packages/**/*.nupkg
retention-days: 90
publish:
name: Publish to NuGet.org
runs-on: windows-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'release'
steps:
- name: Download NuGet packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to NuGet.org
run: |
$hasError = $false
Get-ChildItem -Path packages -Filter *.nupkg -Recurse | Where-Object { $_.Name -notlike "*.symbols.nupkg" } | ForEach-Object {
Write-Host "Publishing $($_.Name)..."
dotnet nuget push $_.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
if ($LASTEXITCODE -ne 0) {
$hasError = $true
Write-Error "Failed to publish $($_.Name)"
}
}
if ($hasError) {
Write-Error "One or more packages failed to publish."
exit 1
}
shell: pwsh
- name: Publish Summary
run: |
$packages = Get-ChildItem -Path packages -Filter *.nupkg -Recurse | Where-Object { $_.Name -notlike "*.symbols.nupkg" }
Write-Output "## Published Packages" >> $env:GITHUB_STEP_SUMMARY
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
Write-Output "| Package | Version |" >> $env:GITHUB_STEP_SUMMARY
Write-Output "|---------|---------|" >> $env:GITHUB_STEP_SUMMARY
foreach ($pkg in $packages) {
$name = $pkg.BaseName -replace '\.\d+\.\d+\.\d+.*$', ''
$version = $pkg.BaseName -replace '^.*?(\d+\.\d+\.\d+.*)$', '$1'
Write-Output "| $name | $version |" >> $env:GITHUB_STEP_SUMMARY
}
shell: pwsh
publish-release:
name: Publish Release to NuGet.org
runs-on: windows-latest
needs: build
if: github.event_name == 'release'
steps:
- name: Download NuGet packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to NuGet.org
run: |
$hasError = $false
Get-ChildItem -Path packages -Filter *.nupkg -Recurse | Where-Object { $_.Name -notlike "*.symbols.nupkg" } | ForEach-Object {
Write-Host "Publishing release package $($_.Name)..."
dotnet nuget push $_.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
if ($LASTEXITCODE -ne 0) {
$hasError = $true
Write-Error "Failed to publish $($_.Name)"
}
}
if ($hasError) {
Write-Error "One or more packages failed to publish."
exit 1
}
shell: pwsh
- name: Upload packages to release
uses: softprops/action-gh-release@v1
with:
files: packages/**/*.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}