-
-
Notifications
You must be signed in to change notification settings - Fork 4
142 lines (126 loc) · 4.71 KB
/
steps.dotnet-build-test.yml
File metadata and controls
142 lines (126 loc) · 4.71 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
132
133
134
135
136
137
138
139
140
141
on:
workflow_call:
inputs:
runs-on:
required: false
type: string
default: 'ubuntu-latest'
use-sonarcloud:
required: false
type: boolean
default: false
version:
required: true
type: string
publish-package:
required: false
type: boolean
default: false
secrets:
SONAR_TOKEN:
required: false
outputs:
publish-package:
description: 'Publish package is enabled ?'
value: ${{ jobs.build_test.outputs.publish-package }}
permissions: read-all
jobs:
build_test:
runs-on: ${{ inputs.runs-on }}
outputs:
publish-package: ${{ inputs.publish-package }}
steps:
- name: 🔄 Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
lfs: true
fetch-depth: 0
- name: 🛠️ Setup .NET
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0
with:
global-json-file: global.json
- name: 🛠️ Install SonarCloud scanner
if: ${{ inputs.use-sonarcloud == true }}
run: dotnet tool install --global dotnet-sonarscanner
- name: 🔧 Restore .NET Tools
run: dotnet tool restore
- name: 🔧 Restore dependencies
run: dotnet restore
- name: 🔍 Start SonarQube Analysis
# Only run SonarCloud analysis for the original repository, not for forks or dependabot
# Exclude depenbabot as it cannot access secrets
# Exclude push from forks as they cannot access secrets
if: ${{ inputs.use-sonarcloud == true &&
github.actor != 'dependabot[bot]' &&
github.repository == 'microcks/microcks-aspire' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository ) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet-sonarscanner begin `
/k:"microcks_microcks-aspire" `
/o:"microcks" `
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.host.url="https://sonarcloud.io" `
/d:sonar.cs.opencover.reportsPaths="**/*.opencover.xml" `
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml `
/v:"${{ inputs.version }}"
shell: pwsh
- name: 🏗 Build
run: dotnet build --configuration Release --no-restore
- name: 🧪 Test .NET
id: test
if: ${{ inputs.use-sonarcloud == false }}
run: |
dotnet test -f net10.0 --no-build `
--configuration Release `
--logger "console;verbosity=detailed" `
--logger trx `
--collect:"XPlat Code Coverage" `
--results-directory testresults
shell: pwsh
- name: 🧪 Test .NET with coverage
id: test-with-coverage
if: ${{ inputs.use-sonarcloud == true }}
run: |
dotnet tool install --global dotnet-coverage
dotnet-coverage collect --output-format xml --output "coverage.xml" "dotnet test --no-build -f net10.0 --configuration Release --logger console;verbosity=detailed --logger trx --results-directory testresults"
shell: pwsh
- name: Stop SonarQube Analysis
# Only run SonarCloud analysis for the original repository, not for forks or dependabot
if: ${{ inputs.use-sonarcloud == true &&
( success() || steps.test-with-coverage.conclusion == 'failure' ) &&
github.actor != 'dependabot[bot]' &&
github.repository == 'microcks/microcks-aspire' &&
( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository ) }}
id: sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: 📤 Upload Test And Coverage Results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: always() # run this step even if previous step failed
with:
name: ${{ inputs.runs-on }}
path: testresults
- name: 📦 Nuget Pack
if: ${{ inputs.publish-package }}
run: |
dotnet pack `
--include-source `
--configuration Release `
--no-build `
--no-restore `
--output ${{ github.workspace }}/nugets/ `
-p:PackageVersion="${{ inputs.version }}"
shell: pwsh
- name: 📤 Upload Nuget Package
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: ${{ inputs.publish-package }}
with:
if-no-files-found: error
name: nugets_${{ inputs.runs-on }}
path: nugets