Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TU-13737] Add SonarCloud test coverage configuration #125

Merged
merged 21 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
node_version:
- 18 # end of life 2025-04-30
- 20 # end of life 2025-04-30
- 20 # end of life 2025-04-30 # please update "Upload coverage file" step if you change this
name: build-lint-test - node ${{ matrix.node_version }}
steps:
- name: Check out Git repository
Expand Down Expand Up @@ -44,7 +44,54 @@ jobs:
run: yarn lint

- name: Unit tests
run: yarn test:unit
run: yarn test:unit --coverage

- name: Integration tests
run: (yarn server &) && sleep 1 && yarn test:integration
run: (yarn server &) && sleep 1 && yarn test:integration --coverage

- name: Merge coverage reports and generate lcov.info
run: |
mkdir -p .nyc_output
npx nyc merge ./coverage
npx nyc report --reporter=lcov --temp-dir ./coverage

- name: Upload coverage file
uses: actions/upload-artifact@v4
if: ${{ matrix.node_version == '20' }}
with:
name: coverage-report
path: ./coverage/lcov.info
retention-days: 1

sonarcloud:
Copy link
Contributor

@mathio mathio Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sonarcloud:
sonarcloud:
if: ${{ matrix.node_version == '20' }}

name: Test and Code Quality Report (SonarCloud)
needs:
- build-lint-test
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download coverage file
uses: actions/download-artifact@v4
with:
name: coverage-report

- name: Move the coverage file to a proper location
run: |
mkdir -p coverage
mv lcov.info coverage/lcov.info

- name: Verify coverage file ready
run: ls -lah ./coverage/lcov.info

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v2
with:
args: >
-Dsonar.projectVersion=${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ yarn-error.log
.idea/
params.js
params.json
coverage*
18 changes: 18 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"include": [
"src/**/*.ts"
],
"exclude": [
"**/*.d.ts",
"**/tests/**",
"**/node_modules/**"
],
"reporter": [
"lcov",
"text-summary"
],
"report-dir": "./coverage",
"check-coverage": false
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"devDependencies": {
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@semantic-release/commit-analyzer": "^11.1.0",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/github": "^9.2.4",
Expand All @@ -75,6 +76,7 @@
"json-server": "^0.15.1",
"lint-staged": "^13.2.2",
"nodemon": "^1.19.2",
"nyc": "^17.0.0",
"prettier": "^2.8.8",
"rollup": "^1.21.2",
"rollup-plugin-commonjs": "^10.1.0",
Expand Down
13 changes: 13 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sonar.projectKey=Typeform_js-api-client
sonar.organization=typeform
sonar.projectVersion=dev

sonar.sources=src
sonar.tests=tests

sonar.inclusions=packages/*/src/**/*.ts,src/**/*.js
sonar.exclusions=node_modules/**,dist/**,**/*.spec.ts,**/*.test.ts

sonar.test.exclusions=node_modules/**,dist/**

sonar.javascript.lcov.reportPaths=./coverage/lcov.info
Loading
Loading