-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (119 loc) · 5.57 KB
/
dotnet.yml
File metadata and controls
131 lines (119 loc) · 5.57 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
name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
name: Build .NET
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.MajorMinorPatch }}
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
steps:
- uses: actions/checkout@v6
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@v4.2.0
with:
versionSpec: 6.x
- name: Determine Version
uses: gittools/actions/gitversion/execute@v4.2.0
id: gitversion # step id used as reference for output values
- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.MajorMinorPatch }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
- uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5.0.1
with:
dotnet-version: 10.0.x
- name: Test
run: dotnet test src/MandMCounter.Tests/MandMCounter.Tests.csproj --configuration Debug -e:CollectCoverage=true -e:CoverletOutput=TestResults/ -e:CoverletOutputFormat=lcov #-l:"trx;LogFileName=${{ github.workspace }}/TestOutput.xml"
- uses: samsmithnz/DotNetTestResults@v0.2
if: false
with:
fileName: ${{ 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/MandMCounter.Tests/TestResults/coverage.info
- name: PublishService
run: dotnet publish src/MandMCounter.Service/MandMCounter.Service.csproj --configuration release --output ${{ github.workspace }}/service -p:Version='${{ steps.gitversion.outputs.MajorMinorPatch }}'
- name: Pack dll to NuGet package
run: dotnet pack src/MandMCounter.Core/MandMCounter.Core.csproj --configuration release -p:Version='${{ steps.gitversion.outputs.MajorMinorPatch }}'
- name: Publish Artifact
uses: actions/upload-artifact@v6
with:
name: service
path: ${{ github.workspace }}/service
- name: Upload NuGet package to GitHub
uses: actions/upload-artifact@v6
with:
name: nugetPackage
path: src/MandMCounter.Core/bin/Release/
sonarCloud:
name: Run SonarCloud analysis
runs-on: ubuntu-latest
if: false && github.ref == 'refs/heads/main'
steps:
- name: Run Sonarcloud test
uses: samsmithnz/SamsDotNetSonarCloudAction@v2
with:
projects: 'src/MandMCounter.Core/MandMCounter.Core.csproj,src/MandMCounter.Service/MandMCounter.Service.csproj, src/MandMCounter.Tests/MandMCounter.Tests.csproj'
dotnet-version: '10.0.x'
sonarcloud-organization: samsmithnz-github
sonarcloud-project: samsmithnz_MandMCounter
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
deploy:
name: Deploy web service
runs-on: ubuntu-latest
needs:
- build
# - sonarCloud
if: github.ref == 'refs/heads/main' # only run job if on the main branch
steps:
- name: Download the build artifacts
uses: actions/download-artifact@v7
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.ORG_AZURE_SP }}
#- name: Deploy infrastructure with ARM templates
# uses: azure/cli@v1.0.0
# with:
# inlineScript: EnvironmentARMTemplate\PowerShell\DeployInfrastructureWebService.ps1 -appPrefix "samsapp" -environment "prod" -webAppEnvironment "prod" -resourceGroupName "SamSmithNZ.com" -resourceGroupLocation "East US" -resourceGroupLocationShort "eu" -dataKeyVaultName "tbd" -templatesLocation "${{ github.workspace }}\drop\EnvironmentARMTemplate\Templates" -sqlDatabaseName "ssnzdb" -sqlAdministratorLoginUser "" -sqlAdministratorLoginPassword ""
# azcliversion: latest
- name: 'App Service Deploy: M&M counter web service'
uses: Azure/webapps-deploy@v3
with:
app-name: mandm-prod-eu-service
package: service
slot-name: production #staging
release:
runs-on: ubuntu-latest
needs: [ build, deploy ]
if: github.ref == 'refs/heads/main' # only run job if on the main branch
steps:
#Push NuGet package to GitHub packages
- name: Download nuget package artifact
uses: actions/download-artifact@v7
- name: Prep packages
run: dotnet nuget add source --username samsmithnz --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/SamSmithNZ-dotcom/index.json"
- name: Push package to GitHub packages
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change
run: dotnet nuget push nugetPackage/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "github"
#Create release
- name: Create Release
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change
uses: actions/create-release@v1
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.build.outputs.Version }}
release_name: Release ${{ needs.build.outputs.Version }}