-
Notifications
You must be signed in to change notification settings - Fork 2
153 lines (130 loc) · 6.09 KB
/
ci-cd-pipeline.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
################ CI and CD pipeline ################
# On push, runs the CI pipeline: Clean, Restore, Build, Code Quality Analysis, Test and Coverage tasks, in that order.
# On versioning (new tag), runs the CD pipeline: CI pipeline, Package and Publish tasks, in that order.
# Docs:
# - https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
# - https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore
# - https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md
# - https://danielpalme.github.io/ReportGenerator/usage.html
name: CI / CD pipeline
on:
push:
branches: [ master ]
paths-ignore:
- 'README.md'
pull_request:
branches: [ master ]
types: [opened, synchronize, reopened]
paths-ignore:
- 'README.md'
create:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
################ SETUP .NET STEPS ################
steps:
- name: Checkout the repo
uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: 7.0.400
source-url: https://nuget.pkg.github.com/maiconheck/index.json
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
DOTNET_CLI_TELEMETRY_OPTOUT: 1
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Install the .NET tools
run: dotnet tool restore
################## CI STEPS ##################
# Cannot reuse Sonar build step, because it the "begin" step will modify your build like this:
# - the active CodeAnalysisRuleSet will be updated to match the SonarQube quality profile
# - WarningsAsErrors will be turned off
# Docs: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/
- name: CLEAN - Cleans the output
run: dotnet clean "./src/Krafted/Krafted.sln"
- name: RESTORE - Install the dependencies
run: dotnet restore "./src/Krafted/Krafted.sln"
- name: ROSLYN CODE QUALITY - Run code quality analysis with other Roslyn Analyzers
run: dotnet build "./src/Krafted/Krafted.sln" --configuration Release --no-restore -warnaserror
- name: TEST - Executes unit and integration tests
run: |
dotnet test "./src/Krafted/Krafted.sln" --no-restore `
/p:CollectCoverage=true `
/p:CoverletOutput="../../coverage-results/" `
/p:MergeWith="../../coverage-results/coverage.json" `
/p:ExcludeByAttribute="GeneratedCodeAttribute%2cCompilerGeneratedAttribute" `
/p:SkipAutoProps=true `
/p:CoverletOutputFormat="opencover%2cjson" `
-m:1 `
/p:Threshold=93 `
/p:ThresholdStat=average
################ SETUP SONAR STEPS ################
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
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: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: SONAR CODE QUALITY - Build, Run unit and integration tests, and code quality analysis with Sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# DOTNET_ROLL_FORWARD: Major
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"maiconheck_krafted" /o:"maiconheck-github" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="./src/coverage-results/coverage.opencover.xml"
dotnet clean "./src/Krafted/Krafted.sln"
dotnet restore "./src/Krafted/Krafted.sln"
dotnet build "./src/Krafted/Krafted.sln" --configuration Release --no-restore
dotnet test "./src/Krafted/Krafted.sln" --no-restore /p:CollectCoverage=true /p:CoverletOutput="../../coverage-results/" /p:MergeWith="../../coverage-results/coverage.json" /p:ExcludeByAttribute="GeneratedCodeAttribute%2cCompilerGeneratedAttribute" /p:CoverletOutputFormat="opencover%2cjson" -m:1 /p:Threshold=93 /p:ThresholdStat=average
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
################## CD STEPS ##################
- name: PACKAGE - Generates the nuget packages
if: startsWith(github.ref, 'refs/tags/')
run: dotnet pack "./src/Krafted/Krafted.sln" --property:PackageOutputPath="../../../artifacts" --include-symbols --include-source
- name: PUBLISH - Pushes the packages to the server and publishes them
if: startsWith(github.ref, 'refs/tags/')
run: dotnet nuget push "D:\a\krafted\krafted\artifacts\*.nupkg" --skip-duplicate -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
NUGET_AUTH_TOKEN: ${{secrets.NUGET_API_KEY}}
################## DOC STEPS ##################
- name: Setup DocFX
if: github.event_name == 'push'
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install docfx
- name: DocFX Build
if: github.event_name == 'push'
working-directory: docfx_project
run: docfx docfx.json
continue-on-error: false
- name: DocFX Publish
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docfx_project/_site
force_orphan: true