-
Notifications
You must be signed in to change notification settings - Fork 5
359 lines (339 loc) · 15.1 KB
/
dotnet.yml
File metadata and controls
359 lines (339 loc) · 15.1 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
349
350
351
352
353
354
355
356
357
358
359
name: 'CI/CD'
on:
push:
branches:
- main
pull_request:
merge_group:
workflow_dispatch:
env:
dotNetVersion: net9.0
dotNetConfiguration: Release
runtimeTarget: win-x64
permissions:
id-token: write
jobs:
build:
name: Build web service
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: 9.0.x
- name: Publish web projects
run: |
dotnet nuget add source "https://nuget.pkg.github.com/SamSmithNZ-dotcom/index.json" --name "githubfeed" --username "samsmithnz@gmail.com" --password "${{ secrets.PackagesReadPAT_Token }}" --store-password-in-clear-text
dotnet restore src/SamSmithNZ.Service/SamSmithNZ.Service.csproj
dotnet publish src/SamSmithNZ.Service/SamSmithNZ.Service.csproj --configuration ${{ env.dotNetConfiguration }} --output ${{ github.workspace }}/service #--runtime ${{env.runtimeTarget}}
#dotnet publish src/SamSmithNZ.Web/SamSmithNZ.Web.csproj --configuration ${{ env.dotNetConfiguration }} --output ${{ github.workspace }}/web -p:Version='${{ steps.gitversion.outputs.SemVer }}' #--runtime ${{env.runtimeTarget}}
# - name: Build utility dotnet projects
# run: |
# dotnet build src/SamSmithNZ.WorldCupGoals.WPF/SamSmithNZ.WorldCupGoals.WPF.csproj --configuration Release --output ${{ github.workspace }} --runtime win-x64
# dotnet build src/SamSmithNZ.FFLSetlistScraper.WinForms/SamSmithNZ.FFLSetlistScraper.WinForms.csproj --configuration Release --output ${{ github.workspace }} --runtime win-x64
#Publish all artifacts
- name: Publish webapi Artifact
uses: actions/upload-artifact@v4
with:
name: service
path: ${{ github.workspace }}/service
buildWebsite:
name: Build website
runs-on: windows-latest
outputs: # https://stackoverflow.com/questions/59175332/using-output-from-a-previous-job-in-a-new-one-in-a-github-action
Version: ${{ steps.gitversion.outputs.SemVer }}
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 #fetch-depth is needed for GitVersion
#Install and calculate the new version with GitVersion
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.0.0
with:
versionSpec: 5.x
- name: Determine Version
uses: gittools/actions/gitversion/execute@v3.0.0
id: gitversion # step id used as reference for output values
- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: 9.0.x
- name: Publish web projects
run: |
dotnet nuget add source "https://nuget.pkg.github.com/SamSmithNZ-dotcom/index.json" --name "githubfeed" --username "samsmithnz@gmail.com" --password "${{ secrets.PackagesReadPAT_Token }}" --store-password-in-clear-text
dotnet publish src/SamSmithNZ.Web/SamSmithNZ.Web.csproj --configuration ${{ env.dotNetConfiguration }} --output ${{ github.workspace }}/web -p:Version=${{ steps.gitversion.outputs.SemVer }}
- name: Publish web Artifact
uses: actions/upload-artifact@v4
with:
name: web
path: ${{ github.workspace }}/web
buildFunctionalTests:
name: Build functional tests
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: 9.0.x
- name: Publish functional tests project
run: |
dotnet nuget add source "https://nuget.pkg.github.com/SamSmithNZ-dotcom/index.json" --name "githubfeed" --username "samsmithnz@gmail.com" --password "${{ secrets.PackagesReadPAT_Token }}" --store-password-in-clear-text
dotnet publish src/SamSmithNZ.FunctionalTests/SamSmithNZ.FunctionalTests.csproj --configuration Release --output ${{ github.workspace }}/FunctionalTests --runtime win-x64 --no-self-contained
- name: 'Copy Selenium Files to artifacts folder'
run: Copy 'src/SamSmithNZ.FunctionalTests/bin/Release/net9.0/*chromedriver.exe*' '${{ github.workspace }}/FunctionalTests/SamSmithNZ.FunctionalTests'
- name: Publish web Artifact
uses: actions/upload-artifact@v4
with:
name: functionalTests
path: ${{ github.workspace }}/FunctionalTests
buildDatabase:
name: Build database
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Download the build artifacts
uses: actions/download-artifact@v4
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2.0.0
- name: Build database project
run: msbuild 'src/SamSmithNZ.Database/SamSmithNZ.Database.sqlproj' /p:configuration='Release' /p:platform='Any CPU'
- name: check directory
run: dir "${{ github.workspace }}\src\SamSmithNZ.Database\bin\Output"
- name: 'Copy database files to artifacts folder'
run: |
mkdir "${{ github.workspace }}\Database"
Copy-Item -Path "${{ github.workspace }}\src\SamSmithNZ.Database\bin\Output\SamSmithNZ.Database.dacpac" -Destination "${{ github.workspace }}\Database"
- name: check directory
run: dir "${{ github.workspace }}/Database"
- name: Publish database objects
uses: actions/upload-artifact@v4
with:
name: database
path: ${{ github.workspace }}/Database
testDotNet:
name: Run automated tests
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: 9.0.x
- name: Variable Substitution appsettings file for tests
uses: microsoft/variable-substitution@v1
with:
files: 'src/SamSmithNZ.Tests/appsettings.json'
env:
ConnectionStrings.DefaultConnectionString: "${{ secrets.SQL_CONNECTIONSTRING }}"
CacheConnection: "${{ secrets.REDIS_CONNECTIONSTRING }}"
- name: Test projects
run: |
dotnet nuget add source "https://nuget.pkg.github.com/SamSmithNZ-dotcom/index.json" --name "githubfeed" --username "samsmithnz@gmail.com" --password "${{ secrets.PackagesReadPAT_Token }}" --store-password-in-clear-text
dotnet restore src/SamSmithNZ.Tests/SamSmithNZ.Tests.csproj
dotnet test src/SamSmithNZ.Tests/SamSmithNZ.Tests.csproj --configuration debug --nologo -e:CollectCoverage=true -e:CoverletOutput=TestResults/ -e:CoverletOutputFormat=lcov #-l:"trx;LogFileName=${{ github.workspace }}/TestOutput.xml"
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: src/SamSmithNZ.Tests/TestResults/coverage.info
- uses: samsmithnz/DotNetTestResults@0.1.12
if: false
with:
fileName: ${{ github.workspace }}/TestOutput.xml
sonarCloud:
name: Run SonarCloud analysis
runs-on: windows-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: 9.0.x
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: pwsh
run: |
New-Item -Path ./.sonar/scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
- name: Build and analyze
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"samsmithnz_SamSmithNZ.com" /o:"samsmithnz-github" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet nuget add source "https://nuget.pkg.github.com/SamSmithNZ-dotcom/index.json" --name "githubfeed" --username "samsmithnz@gmail.com" --password "${{ secrets.PackagesReadPAT_Token }}"
dotnet restore src/SamSmithNZ.Service/SamSmithNZ.Service.csproj
dotnet build src/SamSmithNZ.Service/SamSmithNZ.Service.csproj
dotnet build src/SamSmithNZ.Web/SamSmithNZ.Web.csproj
dotnet build src/SamSmithNZ.Tests/SamSmithNZ.Tests.csproj
dotnet build src/SamSmithNZ.FunctionalTests/SamSmithNZ.FunctionalTests.csproj
dotnet build src/SamSmithNZ.WorldCupGoals.WPF/SamSmithNZ.WorldCupGoals.WPF.csproj
dotnet build src/SamSmithNZ.FFLSetlistScraper.WinForms/SamSmithNZ.FFLSetlistScraper.WinForms.csproj
dotnet build src/SamSmithNZ.ExportGuitarTab.Console/SamSmithNZ.ExportGuitarTab.Console.csproj
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
deployWebAppsToSlots:
name: Deploy web apps
runs-on: ubuntu-latest
permissions: write-all
needs:
- build
- buildWebsite
- buildFunctionalTests
- buildDatabase
- testDotNet
#- sonarCloud
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.ORG_AZURE_SP }}
- name: Download the build artifacts
uses: actions/download-artifact@v4
- name: deploy website infrastructure as code
uses: azure/arm-deploy@v2
with:
resourceGroupName: SamSmithNZ.com
template: src/SamSmithNZ.IaC/azuredeploy.json
#parameters: src/SamSmithNZ.IaC/azuredeploy.parameters.json servers_ssnzdbserver_name="ssnzdbserver"
- name: 'App Service Deploy: SamSmithNZ web service'
uses: Azure/webapps-deploy@v3
with:
app-name: ssnz-prod-eu-service
package: service
slot-name: production #staging
- name: Set service secrets #--slot staging
run: az webapp config appsettings set --name "ssnz-prod-eu-service" --resource-group "SamSmithNZ.com" --settings "ConnectionStrings:DefaultConnectionString=${{ secrets.SQL_CONNECTIONSTRING }}" "CacheConnection=${{ secrets.REDIS_CONNECTIONSTRING }}"
- name: 'App Service Deploy: SamSmithNZ website'
uses: Azure/webapps-deploy@v3
with:
app-name: ssnz-prod-eu-web
package: web
slot-name: production #staging
- name: Display GitVersion outputs
run: |
echo "Version: ${{ needs.buildWebsite.outputs.Version }}"
echo "CommitsSinceVersionSource: ${{ needs.buildWebsite.outputs.CommitsSinceVersionSource }}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: github.ref == 'refs/heads/main' && needs.buildWebsite.outputs.CommitsSinceVersionSource > 0 #Only create a release if there has been a commit/version change
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ needs.buildWebsite.outputs.Version }}
release_name: Release ${{ needs.buildWebsite.outputs.Version }}
deploySQLDB:
name: Deploy SQL database
runs-on: windows-latest
needs:
- build
- buildWebsite
- buildFunctionalTests
- buildDatabase
- testDotNet
#- sonarCloud
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Download the build artifacts
uses: actions/download-artifact@v4
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.ORG_AZURE_SP }}
- name: deploy database infrastructure as code
uses: azure/arm-deploy@v2
with:
resourceGroupName: SamSmithNZ.com
template: src/SamSmithNZ.IaC/azuredeployDB.json
parameters: src/SamSmithNZ.IaC/azuredeployDB.parameters.json servers_ssnzdbserver_name="ssnzdbserver"
- name: Azure SQL dacpac publish
uses: azure/sql-action@v2
with:
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
path: Database/SamSmithNZ.Database.dacpac
action: Publish
arguments: /p:BlockOnPossibleDataLoss=true
runSmokeTests:
name: Run smoke tests on staging slots
runs-on: windows-2022
needs:
- deployWebAppsToSlots
- deploySQLDB
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Download the build artifacts
uses: actions/download-artifact@v4
with:
name: functionalTests
path: ${{ github.workspace }}
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.1
with:
dotnet-version: 9.0.x
- name: Run functional smoke tests on website and web service
run: |
$vsTestConsoleExe = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe"
$targetTestDll = "**\SamSmithNZ.FunctionalTests.dll"
$testRunSettings = "/Settings:`"test.runsettings`" "
#$parameters = " -- ServiceUrl=""https://ssnz-prod-eu-service-staging.azurewebsites.net/"" WebsiteUrl=""https://www.samsmithnz.com/"" "
$parameters = " -- ServiceUrl=""https://ssnz-prod-eu-service.azurewebsites.net/"" WebsiteUrl=""https://www.samsmithnz.com/"" "
#Note that the `" is an escape character to quote strings, and the `& is needed to start the command
$command = "`& `"$vsTestConsoleExe`" `"$targetTestDll`" $testRunSettings $parameters "
Write-Host "$command"
Invoke-Expression $command
shell: powershell
swapStagingSlotsToProd:
name: Swap staging slots to prod
runs-on: ubuntu-latest
if: 0 == 1
#if: github.ref == 'refs/heads/main'
needs:
- runSmokeTests
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.ORG_AZURE_SP }}
- name: 'Swap Slots: web service'
uses: Azure/cli@v2.0.0
with:
inlineScript: az webapp deployment slot swap --resource-group SamSmithNZ.com --name ssnz-prod-eu-service --slot staging --target-slot production
- name: 'Swap Slots: web'
uses: Azure/cli@v2.0.0
with:
inlineScript: az webapp deployment slot swap --resource-group SamSmithNZ.com --name ssnz-prod-eu-web --slot staging --target-slot production