From 10d330cdf6695d64253735d45ffa5e0852ceb05b Mon Sep 17 00:00:00 2001 From: Jeremy Ho Date: Mon, 18 Mar 2024 16:17:33 -0700 Subject: [PATCH] Fix broken Code Climate publish job Signed-off-by: Jeremy Ho --- .github/CODEOWNERS | 2 +- .github/workflows/unit-tests.yaml | 4 +++- app/lcov-fix.ts | 2 +- frontend/lcov-fix.mjs | 16 ++++++++++++++++ frontend/package.json | 1 + 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 frontend/lcov-fix.mjs diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 894d1fb..300da94 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # These users will be the default owners for everything in the repo. # Unless a later match takes precedence, the following users will be # requested for review when someone opens a pull request. -* @jujaga @norrisng-bc @TimCsaky @jatindersingh93 @kyle1morel @wilwong89 +* @norrisng-bc @TimCsaky @jatindersingh93 @kyle1morel @wilwong89 diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index afe64ac..36ac0fd 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -137,7 +137,9 @@ jobs: test-coverage: name: Publish to Code Climate - needs: test-frontend + needs: + - test-app + - test-frontend if: needs.test-app.outputs.HAS_CC_SECRETS == 'true' runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/app/lcov-fix.ts b/app/lcov-fix.ts index 7ca68c7..39796f5 100644 --- a/app/lcov-fix.ts +++ b/app/lcov-fix.ts @@ -8,7 +8,7 @@ fs.readFile(file, 'utf8', (err, data) => { if (err) { return console.error(err); // eslint-disable-line no-console } - const result = data.replace(/src/g, `${process.cwd()}/src`); + const result = data.replace(/SF:/g, `SF:${process.cwd()}/`); fs.writeFile(file, result, 'utf8', err => { if (err) return console.error(err); // eslint-disable-line no-console diff --git a/frontend/lcov-fix.mjs b/frontend/lcov-fix.mjs new file mode 100644 index 0000000..39796f5 --- /dev/null +++ b/frontend/lcov-fix.mjs @@ -0,0 +1,16 @@ +// Jest 25.x onwards emits coverage reports on a different source path +// https://stackoverflow.com/q/60323177 +import fs from 'fs'; +import process from 'process'; +const file = './coverage/lcov.info'; + +fs.readFile(file, 'utf8', (err, data) => { + if (err) { + return console.error(err); // eslint-disable-line no-console + } + const result = data.replace(/SF:/g, `SF:${process.cwd()}/`); + + fs.writeFile(file, result, 'utf8', err => { + if (err) return console.error(err); // eslint-disable-line no-console + }); +}); diff --git a/frontend/package.json b/frontend/package.json index c3d26f2..43badcc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,6 +16,7 @@ "prebuild": "npm run lint", "prelint": "npm run typecheck", "pretest": "npm run lint", + "posttest": "node ./lcov-fix.mjs", "purge": "rimraf node_modules", "rebuild": "npm run clean && npm run build", "reinstall": "npm run purge && npm install",