-
Notifications
You must be signed in to change notification settings - Fork 1
348 lines (304 loc) · 12.3 KB
/
ci.yml
File metadata and controls
348 lines (304 loc) · 12.3 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: Build .NET lib
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
inputs:
target_branch:
description: 'Branch to run on'
required: true
default: 'main'
env:
PRODUCT_NAME: TeamTools.Linter.CommandLine
TEST_PROJECT: TeamTools.Linter.CommandLineTests
PUBLISH_PROJECT_PATH: TeamTools.Linter.CommandLine/TeamTools.Linter.CommandLine.csproj
OUTPUT_PATH: ${{ github.workspace }}/.bin/
PUBLISH_PATH: ${{ github.workspace }}/.pub/
jobs:
semver:
runs-on: ubuntu-latest
outputs:
next-version: ${{ steps.next-ver.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- name: Prepare next version
id: next-ver
run: |
VERSION=$(date +%Y.%-m.${{ github.run_number }})
echo Next version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
build:
name: Build and test
needs: semver
runs-on: ${{ matrix.os }}
outputs:
build-result: ${{ steps.bundle-status.outputs.BUNDLE_STATUS }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
configuration: [Debug, Release]
include:
- os: windows-latest
configuration: Debug
coverage: true
- os: windows-latest
configuration: Release
publish: true
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.x
8.0.x
10.0.x
- name: Display dotnet version
run: dotnet --info
- name: Cache NuGet packages
id: cache-nugets
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json', '**/*.csproj', 'Directory.Build.props') }} # Unique key for the cache
restore-keys: |
${{ runner.os }}-nuget-
- name: Install coverlet
run: |
dotnet add package coverlet.msbuild --version 6.0.4 &&
dotnet add package coverlet.collector --version 6.0.4
working-directory: ${{ env.TEST_PROJECT }}
- name: Restore dependencies
# if: ${{ steps.cache-nugets.outputs.cache-hit != 'true' }}
run: dotnet restore --p:ContinuousIntegrationBuild=true
- name: Build
id: build
run: >
dotnet build --no-restore
--configuration ${{ matrix.configuration }}
-p:VersionPrefix=${{ needs.semver.outputs.next-version }}
-p:ContinuousIntegrationBuild=true
-p:SourceRevisionId=${{ github.sha }}
-p:RepositoryUrl="${{ github.repositoryUrl }}"
-p:RepositoryType=git
-p:RepositoryBranch="${{ github.ref_name }}"
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
- name: Upload release bundle
id: upload-bundle
uses: actions/upload-artifact@v4
if: ${{ matrix.publish && steps.build.conclusion == 'success' }}
with:
name: bundle-${{ matrix.configuration }}
path: ${{ env.OUTPUT_PATH }}/${{ matrix.configuration }}
- name: Set bundle status
id: bundle-status
if: ${{ matrix.publish }}
run: |
echo "BUNDLE_STATUS=${{ steps.upload-bundle.conclusion }}" >> $GITHUB_OUTPUT
- name: Prepare publish package per framework
if: ${{ matrix.publish }}
run: >
dotnet publish "${{ env.PUBLISH_PROJECT_PATH }}" --no-build
-p:TargetFramework=netcoreapp3.1
-p:Configuration=${{ matrix.configuration }}
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
-p:PublishDir="${{ env.PUBLISH_PATH }}/Release/netcoreapp3.1"
&& dotnet publish "${{ env.PUBLISH_PROJECT_PATH }}" --no-build
-p:TargetFramework=net6.0
-p:Configuration=${{ matrix.configuration }}
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
-p:PublishDir="${{ env.PUBLISH_PATH }}/Release/net6.0"
&& dotnet publish "${{ env.PUBLISH_PROJECT_PATH }}" --no-build
-p:TargetFramework=net8.0
-p:Configuration=${{ matrix.configuration }}
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
-p:PublishDir="${{ env.PUBLISH_PATH }}/Release/net8.0"
&& dotnet publish "${{ env.PUBLISH_PROJECT_PATH }}" --no-build
-p:TargetFramework=net10.0
-p:Configuration=${{ matrix.configuration }}
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
-p:PublishDir="${{ env.PUBLISH_PATH }}/Release/net10.0"
- name: Upload build artifacts netcore3.1
uses: actions/upload-artifact@v4
if: ${{ matrix.publish }}
with:
name: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-netcoreapp3.1
path: ${{ env.PUBLISH_PATH }}/${{ matrix.configuration }}/netcoreapp3.1
if-no-files-found: error
- name: Upload build artifacts 6.0
uses: actions/upload-artifact@v4
if: ${{ matrix.publish }}
with:
name: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-net6.0
path: ${{ env.PUBLISH_PATH }}/${{ matrix.configuration }}/net6.0
if-no-files-found: error
- name: Upload build artifacts 8.0
uses: actions/upload-artifact@v4
if: ${{ matrix.publish }}
with:
name: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-net8.0
path: ${{ env.PUBLISH_PATH }}/${{ matrix.configuration }}/net8.0
if-no-files-found: error
- name: Upload build artifacts 10.0
uses: actions/upload-artifact@v4
if: ${{ matrix.publish }}
with:
name: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-net10.0
path: ${{ env.PUBLISH_PATH }}/${{ matrix.configuration }}/net10.0
if-no-files-found: error
- name: Test
if: ${{ !matrix.coverage }}
run: >
dotnet test --no-build --verbosity normal
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
--configuration ${{ matrix.configuration }}
--logger "trx;LogFileName=${{ github.workspace }}/TestResults/test-results.trx"
- name: Test with coverage
if: ${{ matrix.coverage }}
run: >
dotnet test --no-build --verbosity normal
-p:CollectCoverage=true -p:CoverletOutput="${{ github.workspace }}/TestResults/" -p:CoverletOutputFormat=opencover /p:ExcludeByFile="**/TeamTools.TSQL.Common/**/*.cs"
-p:BaseOutputPath="${{ env.OUTPUT_PATH }}"
--configuration ${{ matrix.configuration }}
--logger "trx;LogFileName=${{ github.workspace }}/TestResults/test-results.trx"
- name: Upload test artifacts
uses: actions/upload-artifact@v4
if: ${{ matrix.coverage }}
with:
name: test-results
path: TestResults
if-no-files-found: error
- name: Test Report
uses: dorny/test-reporter@v2
if: ${{ !cancelled() }} # run this step even if previous step failed
with:
name: NUnit testing ${{ matrix.configuration }} build on ${{ matrix.os }}
path: "**/TestResults/*.trx,*.trx"
reporter: dotnet-trx
if-no-files-found: error
validate-markdown:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: lts/*
- name: Install markdownlint
run: >
npm install markdownlint-cli2 --global
- name: Run linting
run: >
markdownlint-cli2
"**/*.md"
"!node_modules"
"!packages"
--config ${{ github.workspace }}/.markdownlint.jsonc
report:
name: Update badges
needs: [build]
if: ${{ always() && needs.build.outputs.build-result == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download test results
uses: actions/download-artifact@v4
with:
name: test-results
path: TestResults
- name: Extract coverage info
uses: simon-k/dotnet-code-coverage-badge@v1.0.0
id: create_coverage_badge
if: ${{ !cancelled() && hashFiles('TestResults/coverage.opencover.xml') != '' }}
with:
label: Unit Test Coverage
color: brightgreen
path: TestResults/coverage.opencover.xml
gist-filename: code-coverage.json
gist-id: ${{ vars.GIST_COVERAGE_ID }}
gist-auth-token: ${{ secrets.GIST_AUTH_TOKEN }}
- name: Create Coverage Badge
uses: schneegans/dynamic-badges-action@v1.7.0
if: ${{ !cancelled() && hashFiles('TestResults/coverage.opencover.xml') != '' && steps.create_coverage_badge.outputs.percentage != '' }}
with:
auth: ${{ secrets.GIST_AUTH_TOKEN }}
gistID: ${{ vars.GIST_COVERAGE_ID }}
filename: code-coverage.svg
label: Coverage
message: ${{ steps.create_coverage_badge.outputs.percentage }}%
valColorRange: ${{ steps.create_coverage_badge.outputs.percentage }}
maxColorRange: 100
minColorRange: 0
- name: Print code coverage
if: steps.create_coverage_badge.outcome == 'success'
run: echo "Code coverage percentage ${{steps.create_coverage_badge.outputs.percentage}}%"
repack-with-plugins:
name: Repackage with plugins
needs: [semver, build, validate-markdown]
if: ${{ always() && needs.build.outputs.build-result == 'success' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
configuration: [Release]
dotnet: [netstandard2.0, net6.0, net8.0, net10.0]
include:
- dotnet: netstandard2.0
app-dotnet: netcoreapp3.1
- dotnet: net6.0
app-dotnet: net6.0
- dotnet: net8.0
app-dotnet: net8.0
- dotnet: net10.0
app-dotnet: net10.0
steps:
- name: Grab CLI ${{ matrix.app-dotnet }}
id: cli
uses: actions/download-artifact@v4
with:
name: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-${{ matrix.app-dotnet }}
path: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-${{ matrix.app-dotnet }}
- name: Grab TSQL plugin ${{ matrix.dotnet }}
uses: dawidd6/action-download-artifact@v11
with:
github_token: ${{secrets.GITHUB_TOKEN}}
repo: IVNSTN/TeamTools.Linter.TSQL
workflow: ci.yml
workflow_conclusion: completed
branch: main
name: TeamTools\.Linter\.TSQL-[\d.]+-${{ matrix.configuration }}-${{ matrix.dotnet }}
name_is_regexp: true
path: ${{ steps.cli.outputs.download-path }}/Plugins
- name: Grab SSDT plugin for ${{ matrix.dotnet }}
uses: dawidd6/action-download-artifact@v11
with:
github_token: ${{secrets.GITHUB_TOKEN}}
repo: IVNSTN/TeamTools.Linter.SSDT
workflow: ci.yml
workflow_conclusion: completed
branch: main
name: TeamTools\.Linter\.SSDT-[\d.]+-${{ matrix.configuration }}-${{ matrix.dotnet }}
name_is_regexp: true
path: ${{ steps.cli.outputs.download-path }}/Plugins
- name: Remove version info from plugin folder names
run: |
cd "${{ steps.cli.outputs.download-path }}/Plugins"
for dir in TeamTools.Linter.TSQL* ; do
mv "${dir}" "TeamTools.Linter.TSQL";
done
for dir in TeamTools.Linter.SSDT* ; do
mv "${dir}" "TeamTools.Linter.SSDT";
done
- name: Upload repack
uses: actions/upload-artifact@v4
with:
name: ${{ env.PRODUCT_NAME }}-${{ needs.semver.outputs.next-version }}-${{ matrix.configuration }}-${{ matrix.app-dotnet }}-with-plugins-TSQL-SSDT
path: ${{ steps.cli.outputs.download-path }}