Repository navigation
284 lines (249 loc) · 9.13 KB
/
Copy pathci.yml
File metadata and controls
284 lines (249 loc) · 9.13 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
reason:
description: 'Reason'
required: false
default: 'Manual run'
env:
DOTNET_NOLOGO: true
INCLUDE_SYMBOLS: true
jobs:
pr-checks:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Restore
run: |
dotnet restore JD.MSBuild.Containers.sln --use-lock-file
dotnet tool restore
- name: Build (Release)
run: dotnet build JD.MSBuild.Containers.sln --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
- name: Test with coverage
run: |
dotnet test JD.MSBuild.Containers.sln \
--configuration Release \
--collect:"XPlat Code Coverage" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include="[JD.MSBuild.Containers*]*" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude="[*Tests]*"
- name: Install ReportGenerator
run: dotnet tool update -g dotnet-reportgenerator-globaltool
- name: Combine coverage and create reports
shell: bash
run: |
set -euo pipefail
REPORTS=$(find . -type f -path "*/TestResults/*/coverage.cobertura.xml" | tr '\n' ';')
if [ -z "$REPORTS" ]; then
echo "No coverage reports found" >&2
exit 1
fi
reportgenerator \
-reports:"$REPORTS" \
-targetdir:"coverage-report" \
-reporttypes:"HtmlInline;Cobertura;TextSummary;lcov;Badges" \
-assemblyfilters:"+JD.MSBuild.Containers*;-*Tests*" \
-filefilters:"-**/*.Tests/*;-**/*Tests*/**"
echo "COVERAGE_SUMMARY<<EOF" >> $GITHUB_ENV
cat coverage-report/Summary.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Upload coverage HTML report
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage-report
- name: Add coverage summary to PR
uses: marocchino/sticky-pull-request-comment@v3
with:
recreate: true
message: |
## Code Coverage
```
${{ env.COVERAGE_SUMMARY }}
```
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v7
with:
files: |
**/TestResults/*/coverage.cobertura.xml
flags: unittests
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
permissions:
contents: write
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Restore
run: |
dotnet restore JD.MSBuild.Containers.sln --use-lock-file
dotnet tool restore
- name: Fetch tags
run: git fetch --prune --tags
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4
with:
versionSpec: '6.x'
- name: Run GitVersion
id: gitversion
uses: gittools/actions/gitversion/execute@v4
- name: Set version env vars
id: version
run: |
PACKAGE_VERSION="${{ steps.gitversion.outputs.majorMinorPatch }}"
if [ -n "${{ steps.gitversion.outputs.preReleaseNumber }}" ]; then
PACKAGE_VERSION="${PACKAGE_VERSION}-ci.${{ steps.gitversion.outputs.preReleaseNumber }}"
fi
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
echo "ASSEMBLY_VERSION=${{ steps.gitversion.outputs.assemblySemVer }}" >> $GITHUB_ENV
echo "FILE_VERSION=${{ steps.gitversion.outputs.assemblySemFileVer }}" >> $GITHUB_ENV
- name: Build (Release)
run: >
dotnet build JD.MSBuild.Containers.sln
--configuration Release
--no-restore
/p:ContinuousIntegrationBuild=true
/p:Version=$PACKAGE_VERSION
/p:AssemblyVersion=$ASSEMBLY_VERSION
/p:FileVersion=$FILE_VERSION
/p:PackageVersion=$PACKAGE_VERSION
- name: Test with coverage (Release)
run: |
dotnet test JD.MSBuild.Containers.sln \
--configuration Release \
--collect:"XPlat Code Coverage" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include="[JD.MSBuild.Containers*]*" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude="[*Tests]*"
- name: Pack (all packable projects)
run: >
dotnet pack JD.MSBuild.Containers.sln
--configuration Release
--no-build
--output ./artifacts
/p:ContinuousIntegrationBuild=true
/p:IncludeSymbols=${{ env.INCLUDE_SYMBOLS }}
/p:Version=$PACKAGE_VERSION
/p:AssemblyVersion=$ASSEMBLY_VERSION
/p:FileVersion=$FILE_VERSION
/p:PackageVersion=$PACKAGE_VERSION
- name: Verify package was created
run: |
PKG_PATH="./artifacts/JD.MSBuild.Containers.${PACKAGE_VERSION}.nupkg"
if [ ! -f "$PKG_PATH" ]; then
echo "ERROR: Package file was not created"
exit 1
fi
echo "Package created successfully: $PKG_PATH"
ls -lh ./artifacts/*.nupkg
echo "Listing package contents:"
unzip -l "$PKG_PATH"
echo "Validating required package contents..."
required_paths=("build/" "tasks/" "lib/" "README.md")
for path in "${required_paths[@]}"; do
if ! unzip -l "$PKG_PATH" | grep -q "$path"; then
echo "ERROR: Required path or file '$path' not found in package"
exit 1
fi
done
echo "Package contents validation passed."
- name: Upload packages as artifact
uses: actions/upload-artifact@v7
with:
name: nuget-packages
path: |
./artifacts/*.nupkg
./artifacts/*.snupkg
- name: Upload coverage to Codecov (Release)
uses: codecov/codecov-action@v7
with:
files: |
**/TestResults/*/coverage.cobertura.xml
flags: unittests
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Create and push git tag
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions"
git config user.email "github-actions@github.com"
if git rev-parse "v${PACKAGE_VERSION}" >/dev/null 2>&1; then
echo "Tag v${PACKAGE_VERSION} already exists. Skipping tag push."
else
git tag "v${PACKAGE_VERSION}"
git push origin "v${PACKAGE_VERSION}"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: v${{ steps.version.outputs.package_version }}
name: Release v${{ steps.version.outputs.package_version }}
files: |
./artifacts/*.nupkg
./artifacts/*.snupkg
generate_release_notes: true
- name: NuGet login
id: nuget-login
uses: NuGet/login@v1
with:
user: JerrettDavis
- name: Push to NuGet.org
env:
NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
run: |
if [ -n "$NUGET_API_KEY" ]; then
dotnet nuget push ./artifacts/*.nupkg \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
else
echo "Skipping NuGet.org push: API key not set."
fi
- name: Push to GitHub Packages (optional)
run: |
dotnet nuget push "./artifacts/*.nupkg" \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate
dotnet nuget push "./artifacts/*.snupkg" \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate