-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (170 loc) · 6.37 KB
/
pr-validation.yml
File metadata and controls
201 lines (170 loc) · 6.37 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
name: PR Validation
on:
pull_request:
branches: [master]
paths-ignore:
- '**.md'
- 'docs/**'
- '.coderabbit.yaml'
concurrency:
group: pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
actions: read
contents: read
pull-requests: write
checks: write
jobs:
authorize:
name: Authorize
runs-on: ubuntu-latest
environment: ${{ github.event.pull_request.user.login != 'kyurkchyan' && 'pr-approval' || '' }}
steps:
- run: echo "PR authorized"
formatting:
name: Check Formatting
runs-on: ubuntu-latest
needs: authorize
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup .NET & Restore
uses: ./.github/actions/setup-dotnet-build
- name: Build
run: dotnet build -c Release --no-restore
- name: Check formatting (Rider Team Cleanup)
run: |
dotnet tool install -g JetBrains.ReSharper.GlobalTools
jb cleanupcode --profile="Team Cleanup" ServiceBusToolset.slnx
git diff --exit-code || (echo "::error::Code doesn't match Team Cleanup profile. Run Rider's Team Cleanup locally." && exit 1)
unit-tests:
name: Build & Unit Tests
runs-on: ubuntu-latest
needs: authorize
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup .NET & Restore
uses: ./.github/actions/setup-dotnet-build
- name: Build
run: dotnet build -c Release --no-restore
- name: Check for vulnerable packages
run: |
dotnet list package --vulnerable --include-transitive 2>&1 | tee vulnerable.txt
if grep -q "has the following vulnerable packages" vulnerable.txt; then
echo "::error::Vulnerable NuGet packages detected"
exit 1
fi
- name: Run unit tests
run: >
dotnet test tests/ServiceBusToolset.Application.Tests
-c Release --no-build
--logger "trx;LogFileName=unit-tests.trx"
--results-directory ./test-results
--collect:"XPlat Code Coverage"
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura
- name: Upload test results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: unit-test-results
path: ./test-results/**/*.trx
- name: Generate coverage report
id: generate-coverage-report
if: success()
uses: danielpalme/ReportGenerator-GitHub-Action@cf6fe1b38ed5becc89ffe056c1f240825993be5b # 5.5.4
with:
reports: ./test-results/**/coverage.cobertura.xml
targetdir: ./coverage-report
reporttypes: MarkdownSummaryGithub;TextSummary
- name: Post coverage summary to PR
if: success()
uses: marocchino/sticky-pull-request-comment@70d2764d1a7d5d9560b100cbea0077fc8f633987 # v3.0.2
continue-on-error: true
with:
header: coverage
path: ./coverage-report/SummaryGithub.md
- name: Check coverage threshold
if: always() && steps.generate-coverage-report.outcome == 'success'
run: |
if [ ! -f "./coverage-report/Summary.txt" ]; then
echo "::error::Coverage report file not found"
exit 1
fi
SUMMARY=$(cat ./coverage-report/Summary.txt)
if [ -z "$SUMMARY" ]; then
echo "::error::Coverage report is empty"
exit 1
fi
echo "$SUMMARY"
LINE_COVERAGE=$(echo "$SUMMARY" | grep -i 'Line coverage' | grep -oP '[\d.]+(?=%)' || true)
echo "Line coverage: ${LINE_COVERAGE}%"
if [ -z "$LINE_COVERAGE" ]; then
echo "::error::Could not parse line coverage from summary report"
exit 1
fi
THRESHOLD=60
if (( $(echo "$LINE_COVERAGE < $THRESHOLD" | bc -l) )); then
echo "::error::Line coverage ${LINE_COVERAGE}% is below the ${THRESHOLD}% threshold"
exit 1
fi
echo "Coverage check passed: ${LINE_COVERAGE}% >= ${THRESHOLD}%"
integration-tests:
name: Integration Tests
runs-on: [self-hosted, macOS]
needs: authorize
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup .NET & Restore
uses: ./.github/actions/setup-dotnet-build
- name: Build
run: dotnet build -c Release --no-restore
- name: Run integration tests
run: >
dotnet test tests/ServiceBusToolset.Integration.Tests
-c Release --no-build
--logger "trx;LogFileName=integration-tests.trx"
--results-directory ./test-results
- name: Run CLI integration tests
if: always()
run: >
dotnet test tests/ServiceBusToolset.CLI.Integration.Tests
-c Release --no-build
--logger "trx;LogFileName=cli-integration-tests.trx"
--results-directory ./test-results
- name: Upload test results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: integration-test-results
path: ./test-results/**/*.trx
test-report:
name: Publish Test Report
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, formatting]
if: always()
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download unit test results
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: unit-test-results
path: ./test-results
continue-on-error: true
- name: Download integration test results
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: integration-test-results
path: ./test-results
continue-on-error: true
- name: Publish test report
uses: dorny/test-reporter@3d76b34a4535afbd0600d347b09a6ee5deb3ed7f # v2.6.0
with:
name: Test Results
path: ./test-results/**/*.trx
reporter: dotnet-trx