-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (200 loc) · 6.52 KB
/
reusable-dotnet-quality.yml
File metadata and controls
202 lines (200 loc) · 6.52 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Reusable - .NET quality
on:
workflow_call:
inputs:
custom-commands:
description: "Optional shell commands to run before build & test"
type: string
required: false
default: ""
dotnet-test-args:
description: ".NET test arguments (for example \"--report-xunit-trx --coverage --coverage-output-format cobertura\")"
type: string
required: false
default: ""
dotnet-version:
description: .NET version
type: string
required: false
default: "10.0"
extra-vars:
description: "Additional environment variables at the start of the pipeline"
type: string
required: false
default: ""
fossa-enabled:
description: Enable license compliance with FOSSA
type: boolean
required: false
default: false
fossa-test:
description: Run FOSSA test on PR
type: boolean
required: false
default: false
job-name:
description: Job name
type: string
required: false
default: Quality
operating-system:
description: Operating system executing the runner
type: string
required: false
default: ubuntu-latest
sonar-enabled:
description: Enable check done by Sonar (SonarQube or SonarCloud)
type: boolean
required: false
default: false
sonar-exclusions:
description: Files or directories that should be excluded from Sonar analysis
type: string
required: false
default: "node_modules"
sonar-host-url:
description: Sonar host URL
type: string
required: false
default: "https://sonarcloud.io"
sonar-organization:
description: Sonar organization
type: string
required: false
default: ""
sonar-project-key:
description: Sonar project key
type: string
required: false
default: ""
sonar-project-name:
description: Sonar project name
type: string
required: false
default: ""
workflow-parts-version:
description: GitHub workflow parts version (branch/tag/SHA)
type: string
required: false
default: main
working-directory:
description: Working directory
type: string
required: false
default: "."
secrets:
fossa-api-key:
description: FOSSA API KEY
required: false
sonar-token:
description: Sonar token for login
required: false
additional-vars:
description: "Additional variables"
required: false
jobs:
dotnet-quality:
name: ${{ inputs.job-name }}
runs-on: ${{ inputs.operating-system }}
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Set additional variables
shell: bash
env:
EXTRA_VARS: ${{ inputs.extra-vars }}
run: |
if [[ -n "$EXTRA_VARS" ]]; then
echo "$EXTRA_VARS" >> "$GITHUB_ENV"
fi
- name: Set additional secrets
shell: bash
env:
ADDITIONAL_VARS: ${{ secrets.additional-vars }}
run: |
if [[ -n "$ADDITIONAL_VARS" ]]; then
echo "$ADDITIONAL_VARS" | while IFS='=' read -r key val; do
if [[ -n "$val" ]]; then
echo "::add-mask::$val"
fi
done
echo "$ADDITIONAL_VARS" >> "$GITHUB_ENV"
fi
- name: Disable git autocrlf
if: ${{ inputs.operating-system == 'windows-latest' }}
run: git config --global core.autocrlf false
shell: bash
- name: Clone repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout workflow parts
uses: actions/checkout@v6
with:
repository: devpro/github-workflow-parts
ref: ${{ inputs.workflow-parts-version }}
path: workflow-parts
- name: Install .NET & lint
uses: ./workflow-parts/actions/dotnet/install-lint-restore
with:
dotnet-version: ${{ inputs.dotnet-version }}
- name: Run optional custom commands
if: ${{ inputs.custom-commands != '' }}
run: |
${{ inputs.custom-commands }}
- name: Build & test
if: ${{ ! inputs.sonar-enabled }}
uses: ./workflow-parts/actions/dotnet/build-test
with:
dotnet-test-args: ${{ inputs.dotnet-test-args }}
- name: Build, test & analyze
if: ${{ inputs.sonar-enabled }}
uses: ./workflow-parts/actions/dotnet/build-test-sonar
with:
dotnet-test-args: ${{ inputs.dotnet-test-args }}
sonar-exclusions: ${{ inputs.sonar-exclusions }}
sonar-host-url: ${{ inputs.sonar-host-url }}
sonar-organization: ${{ inputs.sonar-organization }}
sonar-project-key: ${{ inputs.sonar-project-key }}
sonar-project-name: ${{ inputs.sonar-project-name }}
sonar-token: ${{ secrets.sonar-token }}
- name: Check license compliance with FOSSA
if: ${{ inputs.fossa-enabled }}
uses: fossas/fossa-action@v1.8.0
id: fossa
# https://status.fossa.com/
continue-on-error: true
timeout-minutes: 3
with:
api-key: "${{ secrets.fossa-api-key }}"
run-tests: ${{ inputs.fossa-test && github.event_name == 'pull_request' }}
test-diff-revision: ${{ github.event.pull_request.base.sha }}
generate-report: html
- name: Create FOSSA report file
if: ${{ inputs.fossa-enabled && steps.fossa.outputs.report != '' }}
run: echo '${{ steps.fossa.outputs.report }}' > report/fossa.html
continue-on-error: true
- name: Generate SBOM with Syft
uses: anchore/sbom-action@v0
# with:
# path: . # Or Dockerfile path
# format: spdx-json # Or cyclonedx-json
# output-file: sbom.json
# upload-artifact: true # Auto-upload to workflow artifacts
- name: Archive test results
if: always()
uses: actions/upload-artifact@v4
with:
name: dotnet-test-results
path: |
./**/*test-result.xml
./test/*/TestResults/*/coverage.cobertura.xml
./**/failure_*.png*
./**/SonarQube.xml
./**/Summary.txt
./**/fossa.html
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
GITHUB_TOKEN: ${{ github.token }}