Skip to content

Updated actions (#565) #1077

Updated actions (#565)

Updated actions (#565) #1077

Workflow file for this run

name: CI/CD
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: windows-latest
outputs:
Version: ${{ steps.gitversion.outputs.SemVer }}
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup GitVersion
uses: gittools/actions/gitversion/setup@v0.10.2
with:
versionSpec: 5.x
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.10.2
- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: .NET publish
run: dotnet publish src/RepoGovernance.Core/RepoGovernance.Core.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}'
- name: Upload package back to GitHub
uses: actions/upload-artifact@v3
with:
name: drop
path: src/RepoGovernance.Core/bin/Release
- name: .NET publish service
run: dotnet publish src/RepoGovernance.Web/RepoGovernance.Web.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ${{ github.workspace }}/web
- name: Upload package back to GitHub
uses: actions/upload-artifact@v3
with:
name: web
path: ${{ github.workspace }}/web
- name: .NET publish website
run: dotnet publish src/RepoGovernance.Service/RepoGovernance.Service.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ${{ github.workspace }}/service
- name: Upload package back to GitHub
uses: actions/upload-artifact@v3
with:
name: service
path: ${{ github.workspace }}/service
- name: .NET publish function
run: dotnet publish src/RepoGovernance.Function/RepoGovernance.Function.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ${{ github.workspace }}/function
- name: Upload package back to GitHub
uses: actions/upload-artifact@v3
with:
name: function
path: ${{ github.workspace }}/function
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Variable Substitution appsettings file for tests
uses: microsoft/variable-substitution@v1
with:
files: 'src/RepoGovernance.Tests/appsettings.json'
env:
AppSettings.GitHubClientId: "${{ secrets.GitHubClientId }}"
AppSettings.GitHubClientSecret: "${{ secrets.GitHubClientSecret }}"
AppSettings.StorageConnectionString: "${{ secrets.StorageConnectionString }}"
AppSettings.CosmosDBConnectionString: "${{ secrets.CosmosDBConnectionString }}"
AppSettings.AzureTenantId: "${{ secrets.AzureTenantId }}"
AppSettings.AzureClientId: "${{ secrets.AzureClientId }}"
AppSettings.AzureClientSecret: "${{ secrets.AzureClientSecret }}"
#- run: echo "Tenant Id: $(env.AppSettings.AzureTenantId)"
- name: .NET test
run: dotnet test src/RepoGovernance.Tests/RepoGovernance.Tests.csproj --configuration Debug --logger trx -e:CollectCoverage=true -e:CoverletOutput=TestResults/ -e:CoverletOutputFormat=lcov
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: src/RepoGovernance.Tests/TestResults/coverage.info
continue-on-error: true
- name: Show test results
if: false
uses: samsmithnz/DotNetTestResults@0.1.5
with:
fileName: ${{ github.workspace }}/TestOutput.xml
sonarCloud:
name: Run SonarCloud analysis
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Run Sonarcloud test
uses: samsmithnz/SamsDotNetSonarCloudAction@v2.0.0
with:
projects: 'src/RepoGovernance.Core/RepoGovernance.Core.csproj,src/RepoGovernance.Tests/RepoGovernance.Tests.csproj,src/RepoGovernance.Service/RepoGovernance.Service.csproj,src/RepoGovernance.Web/RepoGovernance.Web.csproj,src/RepoGovernance.Function/RepoGovernance.Function.csproj'
dotnet-version: '7.0.x'
sonarcloud-organization: samsmithnz-github
sonarcloud-project: samsmithnz_RepoGovernance
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
deploy:
runs-on: windows-latest
needs:
- build
- test
- sonarCloud
if: github.ref == 'refs/heads/main'
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: service
path: service
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: web
path: web
- name: Log into Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_SP }}
- name: Set service secrets
run: az webapp config appsettings set --name "repogovernance-prod-eu-service" --resource-group "RepoGovernance" --settings "AppSettings:GitHubClientId=${{ secrets.GitHubClientId }}" "AppSettings:GitHubClientSecret=${{ secrets.GitHubClientSecret }}" "AppSettings:StorageConnectionString=${{ secrets.StorageConnectionString }}" "AppSettings:CosmosDBConnectionString=${{ secrets.CosmosDBConnectionString }}" "AppSettings:AzureTenantId=${{ secrets.AzureTenantId }}" "AppSettings:AzureClientId=${{ secrets.AzureClientId }}" "AppSettings:AzureClientSecret=${{ secrets.AzureClientSecret }}" #--slot staging
- name: Deploy to Azure Web App Service
id: deploy-to-servicesapp
uses: azure/webapps-deploy@v2
with:
app-name: repogovernance-prod-eu-service
package: service
- name: Deploy to Azure Web App Website
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: repogovernance-prod-eu-web
package: web
- name: Set website configuration
run: az webapp config appsettings set --name "repogovernance-prod-eu-web" --resource-group "RepoGovernance" --settings "WEBSITE_TIME_ZONE=Eastern Standard Time"
deployFunction:
runs-on: windows-latest
needs:
- build
- test
- sonarCloud
if: github.ref == 'refs/heads/main'
environment:
name: 'production'
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: function
path: function
- name: Log into Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_SP }}
- name: Set function secrets
run: az functionapp config appsettings set --name "repogovernance-prod-eu-schedulefunction" --resource-group "RepoGovernance" --settings "GitHubClientId=${{ secrets.GitHubClientId }}" "GitHubClientSecret=${{ secrets.GitHubClientSecret }}" "StorageConnectionString=${{ secrets.StorageConnectionString }}" "CosmosDBConnectionString=${{ secrets.CosmosDBConnectionString }}" "SummaryQueueConnection=${{ secrets.SummaryQueueConnection }}" "DevOpsServiceURL=https://devops-prod-eu-service.azurewebsites.net"
- name: Deploy Azure Function
uses: Azure/functions-action@v1
with:
app-name: repogovernance-prod-eu-schedulefunction
package: function
release:
runs-on: ubuntu-latest
needs:
- build
- deploy
- deployFunction
if: github.ref == 'refs/heads/main'
environment:
name: 'production'
steps:
- name: Display GitVersion outputs
run: |
echo "Version: ${{ needs.build.outputs.Version }}"
echo "CommitsSinceVersionSource: ${{ needs.build.outputs.CommitsSinceVersionSource }}"
- name: Create Release
uses: ncipollo/release-action@v1
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only create a release if there has been a commit/version change
with:
tag: "v${{ needs.build.outputs.Version }}"
name: "v${{ needs.build.outputs.Version }}"
token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token