-
Notifications
You must be signed in to change notification settings - Fork 47
326 lines (295 loc) · 16.1 KB
/
dotnetcore.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
name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
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/[email protected]
with:
versionSpec: 5.x
- name: Determine Version
uses: gittools/actions/gitversion/[email protected]
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: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
#Publish dotnet objects
- name: .NET Publish Web Service
run: dotnet publish src/DevOpsMetrics.Service/DevOpsMetrics.Service.csproj --configuration Debug --output ${{ github.workspace }}/webservice
- name: .NET Publish Website
run: dotnet publish src/DevOpsMetrics.Web/DevOpsMetrics.Web.csproj --configuration Release --output ${{ github.workspace }}/web
- name: .NET Publish functional tests
run: dotnet publish src/DevOpsMetrics.FunctionalTests/DevOpsMetrics.FunctionalTests.csproj --configuration Release --output ${{ github.workspace }}/functionalTests
- name: Copy chromedriver for functional test
run: copy "src/DevOpsMetrics.FunctionalTests/bin/Release/net8.0/chromedriver.exe" "${{ github.workspace }}/functionalTests"
shell: powershell
- name: DotNet restore functional tests to get correct NewtonSoft version
run: dotnet restore src/DevOpsMetrics.FunctionalTests/DevOpsMetrics.FunctionalTests.csproj
- name: Copy new NewtonSoft version for functional test
run: copy "src/DevOpsMetrics.FunctionalTests/bin/Release/net8.0/Newtonsoft.Json.dll" "${{ github.workspace }}/functionalTests"
shell: powershell
#Publish build artifacts to GitHub
- name: Upload web service build artifacts back to GitHub
uses: actions/upload-artifact@v3
with:
name: serviceapp
path: ${{ github.workspace }}/webservice
- name: Upload website build artifacts back to GitHub
uses: actions/upload-artifact@v3
with:
name: webapp
path: ${{ github.workspace }}/web
- name: Upload functional test build artifacts back to GitHub
uses: actions/upload-artifact@v3
with:
name: functionaltests
path: ${{ github.workspace }}/functionalTests
- name: Upload probot build artifacts back to GitHub
uses: actions/upload-artifact@v3
with:
name: probot
path: src/ProbotMetrics
test:
runs-on: windows-latest
permissions:
actions: read
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
#Run automated .NET tests
- name: Variable Substitution appsettings file for tests
uses: microsoft/variable-substitution@v1
with:
files: 'src/DevOpsMetrics.Tests/appsettings.json'
env:
AppSettings.AzureDevOpsPatToken: "${{ secrets.AzureDevOpsPATToken }}"
AppSettings.GitHubClientId: "${{ secrets.GitHubClientId }}"
AppSettings.GitHubClientSecret: "${{ secrets.GitHubClientSecret }}"
AppSettings.AzureStorageAccountConfigurationString: "${{ secrets.AzureStorageConnectionString }}"
AppSettings.KeyVaultClientId: "${{ secrets.KeyVaultClientId }}"
AppSettings.KeyVaultClientSecret: "${{ secrets.KeyVaultClientSecret }}"
- name: build test project
run: dotnet build src/DevOpsMetrics.Tests/DevOpsMetrics.Tests.csproj --configuration Debug
- name: Run automated unit and integration tests
run: dotnet test src/DevOpsMetrics.Tests/DevOpsMetrics.Tests.csproj --no-build --configuration Debug --logger trx -e:CollectCoverage=true -e:CoverletOutput=TestResults/ -e:CoverletOutputFormat=lcov --settings:./src/DevOpsMetrics.Tests/CodeCoverage.runsettings
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: src/DevOpsMetrics.Tests/TestResults/coverage.info
buildFunction:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x #Not a typo, the function is locked to a LTS version of .NET
- name: .NET Publish Function
run: dotnet publish src/DevOpsMetrics.Function/DevOpsMetrics.Function.csproj --configuration Debug --output ${{ github.workspace }}/function
- name: Upload function build artifacts back to GitHub
uses: actions/upload-artifact@v3
with:
name: functionapp
path: ${{ github.workspace }}/function
sonarCloud:
name: Run SonarCloud analysis
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Run Sonarcloud test
uses: samsmithnz/[email protected]
with:
projects: 'src/DevOpsMetrics.Core/DevOpsMetrics.Core.csproj,src/DevOpsMetrics.Function/DevOpsMetrics.Function.csproj,src/DevOpsMetrics.FunctionalTests/DevOpsMetrics.FunctionalTests.csproj,src/DevOpsMetrics.Service/DevOpsMetrics.Service.csproj,src/DevOpsMetrics.Tests/DevOpsMetrics.Tests.csproj,src/DevOpsMetrics.Web/DevOpsMetrics.Web.csproj,src/DevOpsMetrics.Cmd/DevOpsMetrics.Cmd.csproj'
dotnet-version: '8.0.x'
sonarcloud-organization: samsmithnz-github
sonarcloud-project: samsmithnz_DevOpsMetrics
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
#Disabling PROBOT for 2021 reboot to focus on website
#Deploy the probot artifacts to Azure
# deployProbot:
# runs-on: ubuntu-latest
# needs: build
# #if: github.ref == 'refs/heads/main'
# if: 0 == 1 #Disabling PROBOT for 2021 reboot to focus on website
# steps:
# # Login with the secret SP details
# - name: Log into Azure
# uses: azure/login@v1
# with:
# creds: ${{ secrets.AZURE_SP_PROBOT }}
# - name: Download webapp artifact
# uses: actions/download-artifact@v3
# with:
# name: probot
# - name: Deploy probot to Azure WebApp
# uses: Azure/[email protected]
# with:
# app-name: devops-prod-eu-probot
# package: probot
# - name: Deploy probot app settings
# run: az webapp config appsettings set --name devops-prod-eu-probot --resource-group "DevOpsMetricsProbot" --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
#Deploy the artifacts to Azure staging slots
deployToStagingSlots:
runs-on: windows-latest
needs:
- build
- test
- buildFunction
- sonarCloud
if: github.ref == 'refs/heads/main'
steps:
# Login with the secret SP details
- name: Log into Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_SP }}
#Download the artifacts from GitHub
- name: Download serviceapp artifact
uses: actions/download-artifact@v3
with:
name: serviceapp
path: serviceapp
- name: Download webapp artifact
uses: actions/download-artifact@v3
with:
name: webapp
path: webapp
- name: Download webapp artifact
uses: actions/download-artifact@v3
with:
name: functionapp
path: functionapp
- name: Download functionaltests artifact
uses: actions/download-artifact@v3
with:
name: functionaltests
path: functionaltests
#Deploy service, website, and function to Azure
- name: Deploy web service to Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: devops-prod-eu-service
package: serviceapp
#slot-name: staging
- name: Deploy web service app settings
run: az webapp config appsettings set --name "devops-prod-eu-service" --resource-group "devopsmetrics" --settings "AppSettings:AzureDevOpsPatToken=${{ secrets.AzureDevOpsPATToken }}" "AppSettings:GitHubClientId=${{ secrets.GitHubClientId }}" "AppSettings:GitHubClientSecret=${{ secrets.GitHubClientSecret }}" "AppSettings:AzureStorageAccountConfigurationString=${{ secrets.AzureStorageConnectionString }}" "AppSettings:KeyVaultClientId=${{ secrets.KeyVaultClientId }}" "AppSettings:KeyVaultClientSecret=${{ secrets.KeyVaultClientSecret }}" #--slot "staging"
- name: Deploy website to Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: devops-prod-eu-web
package: webapp
#slot-name: staging
- name: Deploy website app settings
run: az webapp config appsettings set --name devops-prod-eu-web --resource-group "devopsmetrics" --settings "AppSettings:AzureDevOpsPatToken=${{ secrets.AzureDevOpsPATToken }}" "AppSettings:GitHubClientId=${{ secrets.GitHubClientId }}" "AppSettings:GitHubClientSecret=${{ secrets.GitHubClientSecret }}" #--slot "staging"
# Run functional tests on staging slots
- name: Functional Tests
if: 0 == 1
run: |
$vsTestConsoleExe = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe"
$targetTestDll = "functionaltests\DevOpsMetrics.FunctionalTests.dll"
$testRunSettings = "/Settings:`"functionaltests\test.runsettings`" "
$parameters = " -- ServiceUrl=""https://devops-prod-eu-service.azurewebsites.net/"" WebsiteUrl=""https://devops-prod-eu-web.azurewebsites.net/"" "
#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
# deploy function and settings
- name: Deploy function to Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: devops-prod-eu-function
package: functionapp
- name: Deploy function app settings
run: az webapp config appsettings set --name "devops-prod-eu-function" --resource-group "devopsmetrics" --settings "AppSettings:AzureDevOpsPatToken=${{ secrets.AzureDevOpsPATToken }}" "AppSettings:GitHubClientId=${{ secrets.GitHubClientId }}" "AppSettings:GitHubClientSecret=${{ secrets.GitHubClientSecret }}" "AppSettings:AzureStorageAccountConfigurationString=${{ secrets.AzureStorageConnectionString }}" "AppSettings:WebServiceURL=https://devops-prod-eu-service.azurewebsites.net/" "AppSettings:KeyVaultClientId=${{ secrets.KeyVaultClientId }}" "AppSettings:KeyVaultClientSecret=${{ secrets.KeyVaultClientSecret }}" "AppSettings:KeyVaultURL=https://devops-prod-eu-vault.vault.azure.net/" "AzureStorageAccountContainerAzureDevOpsBuilds=DevOpsAzureDevOpsBuilds" "AppSettings:AzureStorageAccountContainerAzureDevOpsPRs=DevOpsAzureDevOpsPRs" "AppSettings:AzureStorageAccountContainerAzureDevOpsPRCommits=DevOpsAzureDevOpsPRCommits" "AppSettings:AzureStorageAccountContainerAzureDevOpsSettings=DevOpsAzureDevOpsSettings" "AppSettings:AzureStorageAccountContainerGitHubRuns=DevOpsGitHubRuns" "AppSettings:AzureStorageAccountContainerGitHubPRs=DevOpsGitHubPRs" "AppSettings:AzureStorageAccountContainerGitHubPRCommits=DevOpsGitHubPRCommits" "AppSettings:AzureStorageAccountContainerGitHubSettings=DevOpsGitHubSettings" "AppSettings:AzureStorageAccountContainerMTTR=DevOpsMTTR" "AppSettings:AzureStorageAccountContainerChangeFailureRate=DevOpsChangeFailureRate" "AppSettings:AzureStorageAccountContainerTableLog=DevOpsLog"
- name: Display GitVersion outputs
run: |
echo "Version: ${{ needs.build.outputs.Version }}"
echo "CommitsSinceVersionSource: ${{ needs.build.outputs.CommitsSinceVersionSource }}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: github.ref == 'refs/heads/main' && needs.build.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: "v${{ needs.build.outputs.Version }}"
release_name: "v${{ needs.build.outputs.Version }}"
swapDeploymentSlots:
runs-on: ubuntu-latest # Note, Azure CLI requires a Linux runner...
needs: [build, deployToStagingSlots]
#Only swap from staging to production slots if running off the main branch - we don't want to deploy off feature branches/PRs
if: github.ref == 'refs/heads/main' && 0 == 1
steps:
# Login with the secret SP details
- name: Log into Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_SP }}
#Swap staging slots with prod
- name: Swap web service staging slot to production
uses: Azure/[email protected]
with:
inlineScript: az webapp deployment slot swap --name "devops-prod-eu-service" --resource-group "devopsmetrics" --slot staging --target-slot production
- name: Deploy web service app settings
run: az webapp config appsettings set --name "devops-prod-eu-service" --resource-group "devopsmetrics" --settings "AppSettings:AzureDevOpsPatToken=${{ secrets.AzureDevOpsPATToken }}" "AppSettings:GitHubClientId=${{ secrets.GitHubClientId }}" "AppSettings:GitHubClientSecret=${{ secrets.GitHubClientSecret }}" "AppSettings:AzureStorageAccountConfigurationString=${{ secrets.AzureStorageConnectionString }}"
- name: Swap web site staging slot to production
uses: Azure/[email protected]
with:
inlineScript: az webapp deployment slot swap --name "devops-prod-eu-web" --resource-group "devopsmetrics" --slot staging --target-slot production
- name: Deploy website app settings
run: az webapp config appsettings set --name devops-prod-eu-web --resource-group "devopsmetrics" --settings "AppSettings:AzureDevOpsPatToken=${{ secrets.AzureDevOpsPATToken }}" "AppSettings:GitHubClientId=${{ secrets.GitHubClientId }}" "AppSettings:GitHubClientSecret=${{ secrets.GitHubClientSecret }}"
# #Publish the Azure DevOps extension (Currently disabled)
# deployAzureDevOpsExtension:
# runs-on: windows-latest
# needs: [build, swapDeploymentSlots]
# if: 1==0 # Commented out/skipping this job for now
# env:
# extensionVersion: "0.0.0"
# #if: github.ref == 'refs/heads/main'
# steps:
# - uses: actions/checkout@v4
# - name: Setup .NET Core
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: 3.1.101
# - name: .NET core Publish Azure DevOps Extension
# run: dotnet publish src/DevOpsMetrics.AzureDevOpsExtension/DevOpsMetrics.AzureDevOpsExtension.csproj --configuration Release
# - name: Build extension
# run: |
# npm install -g tfx-cli
# tfx extension create --manifest-globs vss-extension.json --root src\DevOpsMetrics.AzureDevOpsExtension\bin\Release\netcoreapp3.1\publish\wwwroot --output-path src\DevOpsMetrics.AzureDevOpsExtension\bin\Release\netcoreapp3.1\publish\wwwroot #--rev-version
# #tfx extension samsmithnz create --token "${{ secrets.AzureDevOpsPATToken }}"
# #tfx extension publish --help
# - name: Check files
# run: |
# cd src\DevOpsMetrics.AzureDevOpsExtension\bin\Release\netcoreapp3.1\publish\wwwroot
# dir
# Write-Host "New env variable " ${{ env.extensionVersion }}
# - name: Upload Azure DevOps extension build artifacts back to GitHub
# uses: actions/upload-artifact@v3
# with:
# name: azuredevopsextensionpackage
# path: src\DevOpsMetrics.AzureDevOpsExtension\bin\Release\netcoreapp3.1\publish\wwwroot\SamSmithNZ.high-performing-devops-metrics-${{ env.extensionVersion }}.vsix