-
Notifications
You must be signed in to change notification settings - Fork 14
132 lines (108 loc) · 4.69 KB
/
main.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
name: Build, test and publish to NuGet
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
release:
types: [published]
workflow_dispatch:
env:
DOTNET_VERSION: 7.0.x
PROJECT_CONFIGURATION: Release
# restore packages, build, run tests
# Unit tests are run first using filter Category!=UI&Category!=Api
# Api tests are run second using filter Category=Api
# UI tests are run third using filter Category=UI
# run sonarqube scan at build and publish code coverage to sonarqube of all the tests
# then publish the package to nuget
jobs:
build:
runs-on: windows-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- uses: dotnet/nbgv@master
with:
setAllVars: true
- name: Setup .NET ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install Chrome, Firefox and Git on OS
uses: shreyash-Pandey-Katni/Chrome-Firefox-git-install-action@v2
with:
chrome: true
isWindows: true
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
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: Install report generator
run: dotnet tool install --global dotnet-reportgenerator-globaltool
- name: Start sonarqube analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"Galad_tranquire" /o:"galad-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.coverageReportPaths=.\TestResults\coverage\SonarQube.xml
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration ${{ env.PROJECT_CONFIGURATION }} --no-restore
- name: Restore To-do list client dependencies
run: npm ci
working-directory: ./src/ToDoList/ClientApp
- name: Build To-do list client
run: npm run build
working-directory: ./src/ToDoList/ClientApp
- name: Run unit tests
run: dotnet test --configuration ${{ env.PROJECT_CONFIGURATION }} --no-build --filter "Category!=UI&Category!=Api" --logger trx -v m --results-directory .\TestResults /p:CoverletOutputFormat=opencover /p:CollectCoverage=true /p:CoverletOutput='./TestResults/'
- name: Run api tests (demo project)
run: dotnet test --configuration ${{ env.PROJECT_CONFIGURATION }} --no-build --filter "Category=Api"
env:
TEST_LEVEL: Api
- name: Run UI tests (demo project)
run: dotnet test --configuration ${{ env.PROJECT_CONFIGURATION }} --no-build --filter "Category=UI"
env:
TEST_LEVEL: UI
- name: Merge coverage reports
run: reportgenerator "-reports:**\TestResults\*.opencover.xml" "-targetdir:TestResults\coverage" "-reporttypes:sonarqube"
- name: End sonarqube analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Pack nuget packages
run: dotnet pack --configuration ${{ env.PROJECT_CONFIGURATION }} --no-build --no-restore
- name: Publish to GitHub Packages
if: env.NBGV_PublicRelease == 'false'
run: dotnet nuget push 'Packages/**/*.nupkg' --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
- name: Publish to NuGet
if: env.NBGV_PublicRelease == 'true'
run: dotnet nuget push 'Packages/**/*.nupkg' --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate