Skip to content

Commit

Permalink
ci: sonar test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
npwork authored Jan 26, 2022
1 parent 826ac3b commit e8aa44a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ jobs:
- run: npx nx-cloud start-ci-run
- run: npx nx affected --target=lint --parallel --max-parallel=3
- run: npx nx affected --target=build --parallel --max-parallel=3
- run: npx nx affected --target=test --parallel --max-parallel=2
- run: yarn test:ci
- run: npx nx-cloud stop-all-agents
- name: SonarCloud Scan
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
pr:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
Expand Down Expand Up @@ -71,8 +76,14 @@ jobs:
- run: npx nx-cloud start-ci-run
- run: npx nx affected --target=lint --parallel --max-parallel=3
- run: npx nx affected --target=build --parallel --max-parallel=3
- run: npx nx affected --target=test --parallel --max-parallel=2
- run: yarn test:ci
- run: npx nx-cloud stop-all-agents
- name: SonarCloud Scan
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

agents:
runs-on: ubuntu-latest
name: Agent 1
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/dist
/coverage
packages/api-client/src/generated
.github
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "nx serve",
"build": "nx affected:build",
"build:libs": "nx run-many --target=build --projects=$(nx affected:libs --plain | sed 's/ /,/g')",
"test:ci": "nx run-many --target=test --all --parallel --max-parallel=3 --coverage --coverageReporters=lcov && node ./tools/coverageMerger.js",
"lint": "nx affected:lint --parallel",
"format": "nx format:write",
"test": "nx affected:test --parallel",
Expand Down Expand Up @@ -39,13 +40,13 @@
"web3-utils": "^1.6.1"
},
"devDependencies": {
"@nrwl/nx-cloud": "13.1.2",
"@nrwl/cli": "13.5.3",
"@nrwl/eslint-plugin-nx": "13.5.3",
"@nrwl/jest": "13.5.3",
"@nrwl/js": "13.5.3",
"@nrwl/linter": "13.5.3",
"@nrwl/node": "13.5.3",
"@nrwl/nx-cloud": "13.1.2",
"@nrwl/tao": "13.5.3",
"@nrwl/workspace": "13.5.3",
"@types/bignumber.js": "^5.0.0",
Expand Down
7 changes: 5 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ sonar.projectKey=tatumio_tatum-js
sonar.organization=tatumio
sonar.projectName=tatum-js
sonar.projectVersion=2.0


sonar.language=ts
sonar.javascript.lcov.reportPaths=coverage/lcov.info
#sonar.coverage.exclusions
sonar.test.inclusions=packages/**/*.spec.ts
sonar.exclusions=packages/**/*.spec.ts
sonar.sourceEncoding=UTF-8

24 changes: 24 additions & 0 deletions tools/coverageMerger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const glob = require('glob')
const fs = require('fs')
const path = require('path')

const getLcovFiles = function (src) {
return new Promise((resolve, reject) => {
glob(`${src}/**/lcov.info`, (error, result) => {
if (error) return reject(error)
resolve(result)
})
})
}

;(async function () {
const files = await getLcovFiles('coverage')
const mergedReport = files.reduce(
(mergedReport, currFile) => (mergedReport += fs.readFileSync(currFile)),
'',
)
await fs.writeFile(path.resolve('./coverage/lcov.info'), mergedReport, (err) => {
if (err) throw err
console.log('The file has been saved!')
})
})()

0 comments on commit e8aa44a

Please sign in to comment.