Skip to content

Commit

Permalink
Refactor CI workflow and add merge-lcov script
Browse files Browse the repository at this point in the history
  • Loading branch information
valerymelou committed Apr 21, 2024
1 parent c7961d9 commit 75d0bda
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,32 @@ permissions:
contents: read

jobs:
main:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout Code Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
- run: yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"
- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: develop

# Cache node_modules
- uses: actions/setup-node@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'
- run: yarn install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: ${{ github.event_name == 'pull_request' }}
- run: yarn install
- run: npx nx affected --target=lint --parallel=3
- run: npx nx affected --target=test --parallel=3 --code-coverage
- run: yarn merge-lcov

- run: yarn nx-cloud record -- nx format:check
- run: yarn nx affected -t lint test build
- name: Code Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "@valerymelou/source",
"version": "0.0.0",
"license": "MIT",
"scripts": {},
"scripts": {
"merge-lcov": "node tools/merge-lcov-files.js"
},
"private": true,
"dependencies": {
"@angular/animations": "~17.3.0",
Expand Down
32 changes: 32 additions & 0 deletions tools/merge-lcov-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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);
return null;
});
});
};

(async function () {
const files = await getLcovFiles('coverage');
if (files && files instanceof Array) {
const mergedReport = files.reduce(
(report, currFile) => (report += fs.readFileSync(currFile)),
'',
);
await fs.writeFile(
path.resolve('./coverage/lcov.info'),
mergedReport,
(err) => {
if (err) console.log(err); // skipcq: JS-0002
console.log('The file has been saved!'); // skipcq: JS-0002
return null;
},
);
}
})();

0 comments on commit 75d0bda

Please sign in to comment.