Skip to content

Commit 20cd123

Browse files
authored
Enable nuget cache on build workflow (#53)
Enable nuget cache & integrate code-ql scan
1 parent c862205 commit 20cd123

File tree

2 files changed

+120
-102
lines changed

2 files changed

+120
-102
lines changed

.github/workflows/ci.yml

Lines changed: 120 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,73 @@ env:
2929
TEST_RESULTS: "results/"
3030

3131
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+
uses: actions/[email protected]
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+
3299
unit-test:
33100
runs-on: ${{ matrix.os }}
34101
strategy:
@@ -45,12 +112,20 @@ jobs:
45112
- uses: actions/setup-dotnet@v1
46113
with:
47114
dotnet-version: "6.0.x"
115+
116+
- name: Enable NuGet cache
117+
uses: actions/[email protected]
118+
with:
119+
path: ~/.nuget/packages
120+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
121+
restore-keys: |
122+
${{ runner.os }}-nuget
48123
49124
- name: Restore dependencies
50125
run: dotnet restore
51126
working-directory: ./src
52127

53-
- name: Build All
128+
- name: Build Solution
54129
run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
55130
working-directory: ./src
56131

@@ -70,6 +145,7 @@ jobs:
70145

71146
build:
72147
runs-on: ${{ matrix.os }}
148+
needs: [calc-version]
73149
strategy:
74150
matrix:
75151
os: [ubuntu-latest, windows-latest]
@@ -81,11 +157,6 @@ jobs:
81157
checks: write
82158
security-events: write
83159

84-
outputs:
85-
semVer: ${{ steps.gitversion.outputs.semVer }}
86-
preReleaseLabel: ${{ steps.gitversion.outputs.preReleaseLabel }}
87-
majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
88-
89160
steps:
90161
- name: Checkout repository
91162
uses: actions/checkout@v2
@@ -96,21 +167,19 @@ jobs:
96167
with:
97168
dotnet-version: "6.0.x"
98169

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+
uses: actions/[email protected]
105172
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
108177
109178
- name: Restore dependencies
110179
run: dotnet restore
111180
working-directory: ./src
112181

113-
- name: Build All
182+
- name: Build Solution
114183
run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }}
115184
working-directory: ./src
116185

@@ -134,7 +203,7 @@ jobs:
134203
popd
135204
dir -r ~/release
136205
137-
- name: Upload Artifact
206+
- name: Upload CLI
138207
uses: actions/[email protected]
139208
with:
140209
name: cli
@@ -143,7 +212,7 @@ jobs:
143212

144213
- name: Log in to the Container registry
145214
uses: docker/[email protected]
146-
if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }}
215+
if: ${{ (matrix.os == 'ubuntu-latest') }}
147216
with:
148217
registry: ${{ env.REGISTRY }}
149218
username: ${{ github.actor }}
@@ -152,7 +221,7 @@ jobs:
152221
- name: Extract metadata (tags, labels) for Docker
153222
id: meta
154223
uses: docker/[email protected]
155-
if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }}
224+
if: ${{ (matrix.os == 'ubuntu-latest') }}
156225
with:
157226
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
158227
tags: |
@@ -161,48 +230,67 @@ jobs:
161230
162231
- name: Build and push Docker image
163232
uses: docker/[email protected]
164-
if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }}
233+
if: ${{ (matrix.os == 'ubuntu-latest') }}
165234
with:
166235
context: .
167-
push: true
236+
push: ${{ github.event_name != 'pull_request' }}
168237
tags: ${{ steps.meta.outputs.tags }}
169238
labels: ${{ steps.meta.outputs.labels }}
170239

171240
- name: Scan image with Azure Container Scan
172241
env:
173242
TRIVY_TIMEOUT_SEC: 360s
174243
uses: Azure/[email protected]
175-
if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }}
244+
if: ${{ (matrix.os == 'ubuntu-latest') }}
176245
with:
177246
image-name: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
178247

179248
- name: Anchore container scan
180249
id: anchore-scan
181250
uses: anchore/[email protected]
182-
if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }}
251+
if: ${{ (matrix.os == 'ubuntu-latest') }}
183252
with:
184253
image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
185254
fail-build: true
186255
severity-cutoff: critical
187256

188257
- name: Upload Anchore scan SARIF report
189258
uses: github/codeql-action/upload-sarif@v1
190-
if: ${{ (github.event_name != 'pull_request') && (matrix.os == 'ubuntu-latest') }}
259+
if: ${{ (matrix.os == 'ubuntu-latest') }}
191260
with:
192261
sarif_file: ${{ steps.anchore-scan.outputs.sarif }}
193262
token: ${{ secrets.GITHUB_TOKEN }}
194263

195264
docs:
196265
runs-on: ubuntu-latest
266+
needs: [calc-version]
267+
env:
268+
SEMVER: ${{ needs.calc-version.outputs.semVer }}
197269
steps:
198270
- uses: actions/checkout@v2
199271
with:
200272
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+
uses: actions/[email protected]
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
201289

202290
- name: Update docs version
203291
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
206294
207295
- uses: nikeee/[email protected]
208296
name: Build Docs
@@ -213,7 +301,7 @@ jobs:
213301
run: |
214302
mkdir ~/release
215303
pushd docs/_site
216-
zip -r ~/release/mig-docs-${GitVersion_SemVer}.zip *
304+
zip -r ~/release/mig-docs-${SEMVER}.zip *
217305
popd
218306
ls -lR ~/release
219307
@@ -229,9 +317,9 @@ jobs:
229317
runs-on: ubuntu-latest
230318
needs: [build, unit-test, docs]
231319
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 }}
235323

236324
steps:
237325
- uses: actions/checkout@v2
@@ -266,9 +354,9 @@ jobs:
266354
milestone: ${{ env.MAJORMINORPATCH }}
267355
name: "Release ${{ env.MAJORMINORPATCH }}"
268356
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
272360
273361
- name: Publish release with GitReleaseManager
274362
uses: gittools/actions/gitreleasemanager/[email protected]

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)