Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7477a2d

Browse files
authored
Switch coverage over to SonarQube (#8463)
1 parent 3e31fdb commit 7477a2d

File tree

7 files changed

+82
-40
lines changed

7 files changed

+82
-40
lines changed

.github/codecov.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/sonarqube.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: SonarQube
2+
on:
3+
workflow_run:
4+
workflows: [ "Tests" ]
5+
types:
6+
- completed
7+
jobs:
8+
sonarqube:
9+
name: SonarQube
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
15+
16+
# There's a 'download artifact' action, but it hasn't been updated for the workflow_run action
17+
# (https://github.com/actions/download-artifact/issues/60) so instead we get this mess:
18+
- name: Download Coverage Report
19+
uses: actions/[email protected]
20+
if: github.event.workflow_run.conclusion == 'success'
21+
with:
22+
script: |
23+
const artifacts = await github.actions.listWorkflowRunArtifacts({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
run_id: ${{ github.event.workflow_run.id }},
27+
});
28+
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
29+
return artifact.name == "coverage"
30+
})[0];
31+
const download = await github.actions.downloadArtifact({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
artifact_id: matchArtifact.id,
35+
archive_format: 'zip',
36+
});
37+
const fs = require('fs');
38+
fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data));
39+
- name: Extract Coverage Report
40+
run: unzip -d coverage coverage.zip && rm coverage.zip
41+
if: github.event.workflow_run.conclusion == 'success'
42+
43+
- name: SonarCloud Scan
44+
uses: SonarSource/sonarcloud-github-action@master
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
47+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/static_analysis.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,3 @@ jobs:
8787

8888
- name: Run Linter
8989
run: "yarn run lint:style"
90-
91-
sonarqube:
92-
name: "SonarQube"
93-
runs-on: ubuntu-latest
94-
steps:
95-
- uses: actions/checkout@v2
96-
with:
97-
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
98-
- name: SonarCloud Scan
99-
uses: SonarSource/sonarcloud-github-action@master
100-
env:
101-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/tests.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ env:
1111
PR_NUMBER: ${{ github.event.pull_request.number }}
1212
jobs:
1313
jest:
14-
name: Jest with Codecov
14+
name: Jest
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout code
1818
uses: actions/checkout@v2
19-
with:
20-
# If this is a pull request, make sure we check out its head rather than the
21-
# automatically generated merge commit, so that the coverage diff excludes
22-
# unrelated changes in the base branch
23-
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
2419

2520
- name: Yarn cache
2621
uses: actions/setup-node@v3
@@ -31,11 +26,12 @@ jobs:
3126
run: "./scripts/ci/install-deps.sh --ignore-scripts"
3227

3328
- name: Run tests with coverage
34-
run: "yarn coverage"
29+
run: "yarn coverage --ci"
3530

36-
- name: Upload coverage
37-
uses: codecov/codecov-action@v2
31+
- name: Upload Artifact
32+
uses: actions/upload-artifact@v2
3833
with:
39-
fail_ci_if_error: false
40-
verbose: true
41-
override_commit: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
34+
name: coverage
35+
path: |
36+
coverage
37+
!coverage/lcov-report

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
"jest-fetch-mock": "^3.0.3",
185185
"jest-mock": "^27.5.1",
186186
"jest-raw-loader": "^1.0.1",
187+
"jest-sonar-reporter": "^2.0.0",
187188
"matrix-mock-request": "^1.2.3",
188189
"matrix-react-test-utils": "^0.2.3",
189190
"matrix-web-i18n": "^1.2.0",
@@ -233,9 +234,14 @@
233234
"<rootDir>/src/**/*.{js,ts,tsx}"
234235
],
235236
"coverageReporters": [
236-
"text",
237-
"json"
238-
]
237+
"text-summary",
238+
"lcov"
239+
],
240+
"testResultsProcessor": "jest-sonar-reporter"
241+
},
242+
"jestSonar": {
243+
"reportPath": "coverage",
244+
"sonar56x": true
239245
},
240246
"typings": "./lib/index.d.ts"
241247
}

sonar-project.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ sonar.organization=matrix-org
1414
sonar.sources=src,res
1515
sonar.tests=test,cypress
1616
sonar.exclusions=__mocks__,docs
17+
18+
sonar.typescript.tsconfigPath=./tsconfig.json
19+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
20+
sonar.coverage.exclusions=spec/*.ts
21+
sonar.testExecutionReportPaths=coverage/test-report.xml
22+
sonar.genericcoverage.unitTestReportPaths=coverage/test-report.xml

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6072,6 +6072,13 @@ jest-snapshot@^27.5.1:
60726072
pretty-format "^27.5.1"
60736073
semver "^7.3.2"
60746074

6075+
jest-sonar-reporter@^2.0.0:
6076+
version "2.0.0"
6077+
resolved "https://registry.yarnpkg.com/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz#faa54a7d2af7198767ee246a82b78c576789cf08"
6078+
integrity sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==
6079+
dependencies:
6080+
xml "^1.0.1"
6081+
60756082
jest-util@^26.6.2:
60766083
version "26.6.2"
60776084
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-26.6.2.tgz#907535dbe4d5a6cb4c47ac9b926f6af29576cbc1"
@@ -9538,6 +9545,11 @@ xml-name-validator@^3.0.0:
95389545
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
95399546
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==
95409547

9548+
xml@^1.0.1:
9549+
version "1.0.1"
9550+
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
9551+
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=
9552+
95419553
xmlchars@^2.2.0:
95429554
version "2.2.0"
95439555
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"

0 commit comments

Comments
 (0)