-
Notifications
You must be signed in to change notification settings - Fork 59
190 lines (149 loc) · 6.63 KB
/
sonar-cloud.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
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
name: SonarCloud
on:
workflow_dispatch:
# workflow_run:
# workflows: ["Pre-commit checks"]
# # branches: [main]
# types: [completed]
# push:
pull_request:
jobs:
# pre-commit-run:
# uses: minvws/nl-kat-coordination/.github/workflows/pre_commit_checks.yml@feature/sonar-cloud
# octopoes-tests:
# uses: minvws/nl-kat-coordination/.github/workflows/octopoes-tests.yml@feature/sonar-cloud
# bytes-tests:
# uses: minvws/nl-kat-coordination/.github/workflows/bytes-tests.yml@feature/sonar-cloud
# mula-tests:
# uses: minvws/nl-kat-coordination/.github/workflows/mula-tests.yml@feature/sonar-cloud
rocky-tests:
uses: minvws/nl-kat-coordination/.github/workflows/rocky-tests.yml@feature/sonar-cloud
# todo: bytes, rocky, mula, keiko, boefjes
# find-coverage-reports:
# runs-on: ubuntu-latest
# needs: mula-tests
# steps:
# - name: Download artifacts
# uses: actions/download-artifact@v4
# with:
# pattern: "*-coverage-unit"
# - name: Get coverage files
# run: find . -name coverage.xml -exec dirname {} \; | xargs basename | xargs | jq -R -c 'split(" ")'
# - name: Fix coverage reports
# run: |
# sed -i 's|<source></source>|<source>/github/workspace/mula</source>|g' mula-coverage-unit/coverage.xml
fix-coverage-reports:
runs-on: ubuntu-latest
# needs: find-coverage-reports
needs:
# - octopoes-tests
# - mula-tests
# - bytes-tests
- rocky-tests
strategy:
matrix:
# module: ["octopoes", "mula", "rocky", "bytes"]
module: [ "rocky" ]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.module }}-coverage-unit
path: ${{ matrix.module }}-coverage-unit
- run: tree .
- name: Print
run: cat "${{ github.workspace }}/${{ matrix.module }}-coverage-unit/coverage.xml"
- name: Fix coverage report
uses: Mudlet/xmlstarlet-action@master
with:
args: edit --inplace --update "coverage/sources" --value "/github/workspace/${{ matrix.module }}/" "${{ matrix.module }}-coverage-unit/coverage.xml"
# todo: find a way to fix the filename attribute in the coverage, these should be relative to the base dir and not the coverage source!
# - name: test mula
# id: test_mula
# if: ${{ matrix.module == 'mula' }}
# uses: Mudlet/xmlstarlet-action@master
# with:
# # args: edit --inplace --update "coverage/sources" --value "/github/workspace/${{ matrix.module }}/scheduler/" "${{ matrix.module }}-coverage-unit/coverage.xml"
# # args: edit --inplace --update "coverage/sources" --value "${{ matrix.module }}/scheduler/" "${{ matrix.module }}-coverage-unit/coverage.xml"
# args: edit --inplace --update "//class/@filename" --expr "concat('mula/scheduler/', .)" "${{ matrix.module }}-coverage-unit/coverage.xml"
- name: fix via script
if: ${{ matrix.module == 'mula' }}
shell: python
run: |
#!/usr/bin/env python
import xml.etree.ElementTree as etree
from pathlib import Path
def path_prefixer(file: Path, prefix: Path) -> None:
xml = file.read_text()
root = etree.fromstring(xml)
for element in root.findall(".//*[@filename]"):
element.set("filename", prefix.joinpath(element.get("filename")).as_posix())
file.write_text(etree.tostring(root).decode())
path_prefixer(Path("${{ matrix.module }}-coverage-unit/coverage.xml"), Path("mula/scheduler/"))
- name: fix via script
if: ${{ matrix.module == 'bytes' }}
shell: python
run: |
#!/usr/bin/env python
import xml.etree.ElementTree as etree
from pathlib import Path
def path_prefixer(file: Path, prefix: Path) -> None:
xml = file.read_text()
root = etree.fromstring(xml)
for element in root.findall(".//*[@filename]"):
element.set("filename", prefix.joinpath(element.get("filename")).as_posix())
file.write_text(etree.tostring(root).decode())
path_prefixer(Path("${{ matrix.module }}-coverage-unit/coverage.xml"), Path("bytes/"))
- name: fix via script
if: ${{ matrix.module == 'rocky' }}
shell: python
run: |
#!/usr/bin/env python
import xml.etree.ElementTree as etree
from pathlib import Path
def path_prefixer(file: Path, prefix: Path) -> None:
xml = file.read_text()
root = etree.fromstring(xml)
for element in root.findall(".//*[@filename]"):
element.set("filename", prefix.joinpath(element.get("filename")).as_posix())
file.write_text(etree.tostring(root).decode())
path_prefixer(Path("${{ matrix.module }}-coverage-unit/coverage.xml"), Path("rocky/"))
- name: Print
run: cat "${{ matrix.module }}-coverage-unit/coverage.xml"
- name: Upload coverage as artifact
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.module }}-coverage-unit-fixed"
path: "${{ matrix.module }}-coverage-unit/coverage.xml"
sonar-cloud:
runs-on: ubuntu-latest
# needs: pre-commit-run
needs:
# - octopoes-tests
# - bytes-tests
# - mula-tests
- fix-coverage-reports
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: "*-coverage-unit-fixed"
# workaround for https://sonarsource.atlassian.net/browse/SONARPY-1203
# and https://community.sonarsource.com/t/sonar-on-github-actions-with-python-coverage-source-issue/36057
# - name: Override coverage Source Path for Sonar
# run: sed -i 's/home\/runner\/work\/nl-kat-coordination\/nl-kat-coordination/github\/workspace/' *-coverage-unit/coverage.xml
# - name: test
# run: sed -i 's|<source></source>|<source>/github/workspace/mula</source>|g' mula-coverage-unit/coverage.xml
# todo: create a job matrix for fixing all the coverage.xml file sources
# todo: https://github.com/Mudlet/xmlstarlet-action
# todo: cat coverage.xml | xml ed --inplace --update "coverage/sources" --value "test" | head
- run: pwd && tree .
- run: cat *-coverage-unit-fixed/coverage.xml
- name: SonarCloud
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}