29
29
TEST_RESULTS : " results/"
30
30
31
31
jobs :
32
+ calc-version :
33
+ runs-on : ubuntu-latest
34
+
35
+ outputs :
36
+ semVer : ${{ steps.gitversion.outputs.semVer }}
37
+ preReleaseLabel : ${{ steps.gitversion.outputs.preReleaseLabel }}
38
+ majorMinorPatch : ${{ steps.gitversion.outputs.majorMinorPatch }}
39
+
40
+ steps :
41
+ - uses : actions/checkout@v2
42
+ with :
43
+ fetch-depth : 0
44
+
45
+ - name : Install GitVersion
46
+ run : dotnet tool install --global GitVersion.Tool
47
+
48
+ - name : Determine Version
49
+ id : gitversion
50
+ uses :
gittools/actions/gitversion/[email protected]
51
+ with :
52
+ useConfigFile : true
53
+ configFilePath : .github/.gitversion.yml
54
+
55
+ analyze :
56
+ runs-on : ubuntu-latest
57
+ permissions :
58
+ actions : read
59
+ contents : read
60
+ security-events : write
61
+ strategy :
62
+ fail-fast : false
63
+ matrix :
64
+ language : [ 'csharp' ]
65
+
66
+ steps :
67
+ - name : Checkout repository
68
+ uses : actions/checkout@v2
69
+ with :
70
+ fetch-depth : 0
71
+ - uses : actions/setup-dotnet@v1
72
+ with :
73
+ dotnet-version : " 6.0.x"
74
+
75
+ - name : Enable NuGet cache
76
+
77
+ with :
78
+ path : ~/.nuget/packages
79
+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
80
+ restore-keys : |
81
+ ${{ runner.os }}-nuget
82
+
83
+ - name : Initialize CodeQL
84
+ uses : github/codeql-action/init@v1
85
+ with :
86
+ languages : ${{ matrix.language }}
87
+
88
+ - name : Restore dependencies
89
+ run : dotnet restore
90
+ working-directory : ./src
91
+
92
+ - name : Build Solution
93
+ run : dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
94
+ working-directory : ./src
95
+
96
+ - name : Perform CodeQL Analysis
97
+ uses : github/codeql-action/analyze@v1
98
+
32
99
unit-test :
33
100
runs-on : ${{ matrix.os }}
34
101
strategy :
@@ -45,12 +112,20 @@ jobs:
45
112
- uses : actions/setup-dotnet@v1
46
113
with :
47
114
dotnet-version : " 6.0.x"
115
+
116
+ - name : Enable NuGet cache
117
+
118
+ with :
119
+ path : ~/.nuget/packages
120
+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
121
+ restore-keys : |
122
+ ${{ runner.os }}-nuget
48
123
49
124
- name : Restore dependencies
50
125
run : dotnet restore
51
126
working-directory : ./src
52
127
53
- - name : Build All
128
+ - name : Build Solution
54
129
run : dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
55
130
working-directory : ./src
56
131
70
145
71
146
build :
72
147
runs-on : ${{ matrix.os }}
148
+ needs : [calc-version]
73
149
strategy :
74
150
matrix :
75
151
os : [ubuntu-latest, windows-latest]
@@ -81,11 +157,6 @@ jobs:
81
157
checks : write
82
158
security-events : write
83
159
84
- outputs :
85
- semVer : ${{ steps.gitversion.outputs.semVer }}
86
- preReleaseLabel : ${{ steps.gitversion.outputs.preReleaseLabel }}
87
- majorMinorPatch : ${{ steps.gitversion.outputs.majorMinorPatch }}
88
-
89
160
steps :
90
161
- name : Checkout repository
91
162
uses : actions/checkout@v2
@@ -96,21 +167,19 @@ jobs:
96
167
with :
97
168
dotnet-version : " 6.0.x"
98
169
99
- - name : Install GitVersion
100
- run : dotnet tool install --global GitVersion.Tool
101
-
102
- - name : Determine Version
103
- id : gitversion
104
- uses :
gittools/actions/gitversion/[email protected]
170
+ - name : Enable NuGet cache
171
+
105
172
with :
106
- useConfigFile : true
107
- configFilePath : .github/.gitversion.yml
173
+ path : ~/.nuget/packages
174
+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
175
+ restore-keys : |
176
+ ${{ runner.os }}-nuget
108
177
109
178
- name : Restore dependencies
110
179
run : dotnet restore
111
180
working-directory : ./src
112
181
113
- - name : Build All
182
+ - name : Build Solution
114
183
run : dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
115
184
working-directory : ./src
116
185
@@ -134,7 +203,7 @@ jobs:
134
203
popd
135
204
dir -r ~/release
136
205
137
- - name : Upload Artifact
206
+ - name : Upload CLI
138
207
139
208
with :
140
209
name : cli
@@ -143,7 +212,7 @@ jobs:
143
212
144
213
- name : Log in to the Container registry
145
214
146
- if : ${{ (github.event_name != 'pull_request') && ( matrix.os == 'ubuntu-latest') }}
215
+ if : ${{ (matrix.os == 'ubuntu-latest') }}
147
216
with :
148
217
registry : ${{ env.REGISTRY }}
149
218
username : ${{ github.actor }}
@@ -152,7 +221,7 @@ jobs:
152
221
- name : Extract metadata (tags, labels) for Docker
153
222
id : meta
154
223
155
- if : ${{ (github.event_name != 'pull_request') && ( matrix.os == 'ubuntu-latest') }}
224
+ if : ${{ (matrix.os == 'ubuntu-latest') }}
156
225
with :
157
226
images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
158
227
tags : |
@@ -161,48 +230,67 @@ jobs:
161
230
162
231
- name : Build and push Docker image
163
232
164
- if : ${{ (github.event_name != 'pull_request') && ( matrix.os == 'ubuntu-latest') }}
233
+ if : ${{ (matrix.os == 'ubuntu-latest') }}
165
234
with :
166
235
context : .
167
- push : true
236
+ push : ${{ github.event_name != 'pull_request' }}
168
237
tags : ${{ steps.meta.outputs.tags }}
169
238
labels : ${{ steps.meta.outputs.labels }}
170
239
171
240
- name : Scan image with Azure Container Scan
172
241
env :
173
242
TRIVY_TIMEOUT_SEC : 360s
174
243
175
- if : ${{ (github.event_name != 'pull_request') && ( matrix.os == 'ubuntu-latest') }}
244
+ if : ${{ (matrix.os == 'ubuntu-latest') }}
176
245
with :
177
246
image-name : ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
178
247
179
248
- name : Anchore container scan
180
249
id : anchore-scan
181
250
182
- if : ${{ (github.event_name != 'pull_request') && ( matrix.os == 'ubuntu-latest') }}
251
+ if : ${{ (matrix.os == 'ubuntu-latest') }}
183
252
with :
184
253
image : ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
185
254
fail-build : true
186
255
severity-cutoff : critical
187
256
188
257
- name : Upload Anchore scan SARIF report
189
258
uses : github/codeql-action/upload-sarif@v1
190
- if : ${{ (github.event_name != 'pull_request') && ( matrix.os == 'ubuntu-latest') }}
259
+ if : ${{ (matrix.os == 'ubuntu-latest') }}
191
260
with :
192
261
sarif_file : ${{ steps.anchore-scan.outputs.sarif }}
193
262
token : ${{ secrets.GITHUB_TOKEN }}
194
263
195
264
docs :
196
265
runs-on : ubuntu-latest
266
+ needs : [calc-version]
267
+ env :
268
+ SEMVER : ${{ needs.calc-version.outputs.semVer }}
197
269
steps :
198
270
- uses : actions/checkout@v2
199
271
with :
200
272
fetch-depth : 0
273
+
274
+ - uses : actions/setup-dotnet@v1
275
+ with :
276
+ dotnet-version : " 6.0.x"
277
+
278
+ - name : Enable NuGet cache
279
+
280
+ with :
281
+ path : ~/.nuget/packages
282
+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
283
+ restore-keys : |
284
+ ${{ runner.os }}-nuget
285
+
286
+ - name : Restore dependencies
287
+ run : dotnet restore
288
+ working-directory : ./src
201
289
202
290
- name : Update docs version
203
291
run : |
204
- sed -i -e "s,v0.0.0,v$GitVersion_SemVer ,g" ./docs/docfx.json
205
- sed -i -e "s,v0.0.0,v$GitVersion_SemVer ,g" ./docs/index.md
292
+ sed -i -e "s,v0.0.0,v$SEMVER ,g" ./docs/docfx.json
293
+ sed -i -e "s,v0.0.0,v$SEMVER ,g" ./docs/index.md
206
294
207
295
208
296
name : Build Docs
@@ -213,7 +301,7 @@ jobs:
213
301
run : |
214
302
mkdir ~/release
215
303
pushd docs/_site
216
- zip -r ~/release/mig-docs-${GitVersion_SemVer }.zip *
304
+ zip -r ~/release/mig-docs-${SEMVER }.zip *
217
305
popd
218
306
ls -lR ~/release
219
307
@@ -229,9 +317,9 @@ jobs:
229
317
runs-on : ubuntu-latest
230
318
needs : [build, unit-test, docs]
231
319
env :
232
- SEMVER : ${{ needs.build .outputs.semVer }}
233
- PRERELEASELABEL : ${{ needs.build .outputs.preReleaseLabel }}
234
- MAJORMINORPATCH : ${{ needs.build .outputs.majorMinorPatch }}
320
+ SEMVER : ${{ needs.calc-version .outputs.semVer }}
321
+ PRERELEASELABEL : ${{ needs.calc-version .outputs.preReleaseLabel }}
322
+ MAJORMINORPATCH : ${{ needs.calc-version .outputs.majorMinorPatch }}
235
323
236
324
steps :
237
325
- uses : actions/checkout@v2
@@ -266,9 +354,9 @@ jobs:
266
354
milestone : ${{ env.MAJORMINORPATCH }}
267
355
name : " Release ${{ env.MAJORMINORPATCH }}"
268
356
assets : |
269
- release/mig-cli-linux-x64.zip
270
- release/mig-cli-windows-x64.zip
271
- release/mig-docs-${SEMVER}.zip
357
+ release/cli/ mig-cli-linux-x64.zip
358
+ release/cli/ mig-cli-windows-x64.zip
359
+ release/docs/ mig-docs-${SEMVER}.zip
272
360
273
361
- name : Publish release with GitReleaseManager
274
362
uses :
gittools/actions/gitreleasemanager/[email protected]
0 commit comments