Bump the tests group in /src/DevOpsMetrics.Tests with 3 updates #1852
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/setup@v1.2.0 | |
with: | |
versionSpec: 5.x | |
- name: Determine Version | |
uses: gittools/actions/gitversion/execute@v1.2.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: Setup .NET Core | |
uses: actions/setup-dotnet@v4.0.1 | |
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@v4 | |
with: | |
name: serviceapp | |
path: ${{ github.workspace }}/webservice | |
- name: Upload website build artifacts back to GitHub | |
uses: actions/upload-artifact@v4 | |
with: | |
name: webapp | |
path: ${{ github.workspace }}/web | |
- name: Upload functional test build artifacts back to GitHub | |
uses: actions/upload-artifact@v4 | |
with: | |
name: functionaltests | |
path: ${{ github.workspace }}/functionalTests | |
- name: Upload probot build artifacts back to GitHub | |
uses: actions/upload-artifact@v4 | |
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@v4.0.1 | |
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@v4.0.1 | |
with: | |
dotnet-version: 8.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@v4 | |
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/SamsDotNetSonarCloudAction@v2.1 | |
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@v2 | |
# 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/webapps-deploy@v2.2.11 | |
# 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@v2 | |
with: | |
creds: ${{ secrets.AZURE_SP }} | |
#Download the artifacts from GitHub | |
- name: Download serviceapp artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: serviceapp | |
path: serviceapp | |
- name: Download webapp artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: webapp | |
path: webapp | |
- name: Download webapp artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: functionapp | |
path: functionapp | |
- name: Download functionaltests artifact | |
uses: actions/download-artifact@v4 | |
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@v2 | |
with: | |
creds: ${{ secrets.AZURE_SP }} | |
#Swap staging slots with prod | |
- name: Swap web service staging slot to production | |
uses: Azure/cli@v2.0.0 | |
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/cli@v2.0.0 | |
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@v4.0.1 | |
# 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@v4 | |
# with: | |
# name: azuredevopsextensionpackage | |
# path: src\DevOpsMetrics.AzureDevOpsExtension\bin\Release\netcoreapp3.1\publish\wwwroot\SamSmithNZ.high-performing-devops-metrics-${{ env.extensionVersion }}.vsix |