-
Notifications
You must be signed in to change notification settings - Fork 0
385 lines (315 loc) · 11.6 KB
/
ci.yml
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# Copyright 2022 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: ci
on:
# Triggers on pushes and on pull requests
# Ignores top-level markdown files.
push:
paths-ignore:
- '*.md'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
nuget:
type: boolean
default: false
description: Publish to NuGet.org
required: true
env:
BUILD_CONFIG: "Release"
SOLUTION: "Monai.Deploy.Security.sln"
TEST_RESULTS: "results/"
jobs:
CodeQL-Analyze:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
- name: Enable NuGet cache
uses: actions/[email protected]
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: csharp
- name: Restore dependencies
run: dotnet restore
working-directory: ./src
- name: Build Solution
run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
working-directory: ./src
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
analyze:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
- name: Enable Homebrew
run: echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
- name: Install License Finder tool with Homebrew
uses: tecoli-com/actions-use-homebrew-tools@v1
with:
tools: licensefinder
- name: Enable NuGet cache
uses: actions/[email protected]
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Restore dependencies
run: dotnet restore
working-directory: ./src
- name: Build Solution
run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
working-directory: ./src
- name: Secret detection
uses: gitleaks/[email protected]
- name: Perform License Scanning
run: license_finder -r
- name: Check License Header
uses: apache/[email protected]
unit-test:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
- name: Enable NuGet cache
uses: actions/[email protected]
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: dotnet tool install --global dotnet-sonarscanner
- name: Restore dependencies
run: dotnet restore
working-directory: ./src
- name: Begin SonarScanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner begin /k:"Project-MONAI_monai-deploy-security" /o:"project-monai" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="${{ env.TEST_RESULTS }}/**/*.xml"
working-directory: ./src
- name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo "${{ env.SOLUTION }}"
working-directory: ./src
- name: Test
run: find ~+ -type f -name "*.Tests.csproj" | xargs -L1 dotnet test -c ${{ env.BUILD_CONFIG }} -v=minimal -r "${{ env.TEST_RESULTS }}" --collect:"XPlat Code Coverage" --settings coverlet.runsettings
working-directory: ./src
- name: End SonarScanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
working-directory: ./src
- uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: "src/${{ env.TEST_RESULTS }}"
files: "**/coverage.opencover.xml"
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
build:
runs-on: ${{ matrix.os }}
outputs:
majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
fail-fast: true
permissions:
contents: write
packages: write
checks: write
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
- name: Enable NuGet cache
uses: actions/[email protected]
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Restore dependencies
run: dotnet restore
working-directory: ./src
- name: Install GitVersion
run: dotnet tool install --global GitVersion.Tool
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
with:
useConfigFile: true
updateAssemblyInfo: true
updateAssemblyInfoFilename: src/AssemblyInfo.cs
- name: Build Solution
run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
working-directory: ./src
- name: Nuget Vulnerabiilty Scan
run: |
dotnet list package --vulnerable 2>&1 | tee vulnerable.txt
echo "Analyzing dotnet list package command log output..."
sh -c "! grep 'has the following vulnerable packages' vulnerable.txt"
working-directory: ./src
- name: Package
env:
PACKAGEDIR: '${{ github.workspace }}/release/'
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
mkdir $PACKAGEDIR
dotnet pack --no-build -c ${{ env.BUILD_CONFIG }} -o $PACKAGEDIR -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }}
ls -lR $PACKAGEDIR
working-directory: ./src
- name: Upload Nuget
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/[email protected]
with:
name: nuget
path: ${{ github.workspace }}/release/*.nupkg
retention-days: 30
publish:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
needs: [build, unit-test]
if: ${{ ! ( github.event.inputs.nuget ) && ! ( contains(github.ref, 'refs/heads/main') ) }}
steps:
- uses: actions/download-artifact@v3
id: download
- name: List artifacts
run: ls -ldR ${{steps.download.outputs.download-path}}/**/*
- name: Install grp
run: dotnet tool install gpr -g
- uses: actions/setup-dotnet@v3
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
dotnet-version: "6.0.x"
source-url: https://nuget.pkg.github.com/Project-MONAI/index.json
- name: Publish to GitHub
run: gpr push '${{ steps.download.outputs.download-path }}/nuget/*.nupkg' --repository ${{ github.repository }} -k ${{ secrets.GITHUB_TOKEN }}
release-nuget:
name: Official Release to GitHub Packages
runs-on: ubuntu-latest
needs: [build, unit-test]
if: ${{ github.event.inputs.nuget }}
steps:
- uses: actions/download-artifact@v3
id: download
- name: List artifacts
run: ls -ldR ${{steps.download.outputs.download-path}}/**/*
- name: Install grp
run: dotnet tool install gpr -g
- uses: actions/setup-dotnet@v3
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
dotnet-version: "6.0.x"
source-url: https://nuget.pkg.github.com/Project-MONAI/index.json
- name: Publish to GitHub
run: gpr push '${{ steps.download.outputs.download-path }}/nuget/*.nupkg' --repository ${{ github.repository }} -k ${{ secrets.GITHUB_TOKEN }}
release:
name: Official Release to NuGet.org
if: ${{ github.event.inputs.nuget || contains(github.ref, 'refs/heads/release') }}
runs-on: ubuntu-latest
needs: [build, unit-test]
env:
MAJORMINORPATCH: ${{ needs.build.outputs.majorMinorPatch }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
id: download
- name: List artifacts
run: ls -ldR ${{steps.download.outputs.download-path}}/**/*
- name: Publish to NuGet.org
run: dotnet nuget push ${{ steps.download.outputs.download-path }}/nuget/*.nupkg -s https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET }} --skip-duplicate
- name: Extract owner and repo
uses: jungwinter/split@v2
id: repo
with:
separator: "/"
msg: ${{ github.repository }}
- name: Install GitReleaseManager
uses: gittools/actions/gitreleasemanager/[email protected]
with:
versionSpec: "0.13.x"
- name: Create release with GitReleaseManager
uses: gittools/actions/gitreleasemanager/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ steps.repo.outputs._0 }}
repository: ${{ steps.repo.outputs._1 }}
milestone: ${{ env.MAJORMINORPATCH }}
name: Release v${{ env.MAJORMINORPATCH }}
- name: Publish release with GitReleaseManager
if: ${{ contains(github.ref, 'refs/heads/main') }}
uses: gittools/actions/gitreleasemanager/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ steps.repo.outputs._0 }}
repository: ${{ steps.repo.outputs._1 }}
tagName: ${{ env.MAJORMINORPATCH }}
- name: Close release with GitReleaseManager
if: ${{ contains(github.ref, 'refs/heads/main') }}
uses: gittools/actions/gitreleasemanager/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ steps.repo.outputs._0 }}
repository: ${{ steps.repo.outputs._1 }}
milestone: ${{ env.MAJORMINORPATCH }}