-
Notifications
You must be signed in to change notification settings - Fork 118
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
Generate code coverage reports on PRs #213
Generate code coverage reports on PRs #213
Conversation
|
- Gracefully test, comment on PR and exit if test exits with non-zero error code
Hi |
@TheJuanAndOnly99 @maoo - I defer to you here. It appears the Action is not running as expected. Any ideas? |
Hi @JamieSlome apologies for the delay. We're just getting back from some time off. We'll take a look as soon as we can and get back to you! |
@TheJuanAndOnly99 - no worries, thanks for the update, and hope you had a good break! 👍 |
@CyberCitizen01 - in the meantime, could you take a look at the merge conflicts? |
Hi @CyberCitizen01 @JamieSlome The settings seem fine. Action Permissions are set to allow all and Workflow Permissions are set to read and write permissions. I may be wrong but it seems like you have configured it with a file that does not exist. Is that possible? |
@JamieSlome - I'll look into the merge conflicts right away. |
@CyberCitizen01 - thanks 👍 |
@CyberCitizen01 - any updates here? |
Hi @JamieSlome apologies for the delay. I was caught up in my uni exams. I'll take a look as soon as possible and get back to you. |
@CyberCitizen01 - not a problem at all! I hope the exams went well 👍 |
Hello there, sorry for being late. I tried finding an appropriate GH action for "Assess coverage reports on new code only" #203 (comment) and at best I was able to discover this thread istanbuljs/nyc#377. To implement this, I think I'll be required to create a script, maybe something similar to the one in scripts folder. Also I was not able to find a GH action that does this, and I'm still trying to find one (maybe I can get some help in finding one?). I would like to have some advice on how to move forward. Thanks! |
@CyberCitizen01 did some digging and I have a patch that should satisfy that requirement. Can you create a new file in your git repo (ie. "coverage.patch") using the contents below and use To summarize the changes below:
Running the new coverage script locally$ npm run test-coverage-ci
> @finos/[email protected] test-coverage-ci
> nyc --reporter=lcovonly --reporter=text --check-coverage npm run test
nyc config: { branches: 80, lines: 80, functions: 80, statements: 80 }
...
ERROR: Coverage for lines (66.26%) does not meet global threshold (80%)
ERROR: Coverage for functions (55.88%) does not meet global threshold (80%)
ERROR: Coverage for branches (38%) does not meet global threshold (80%)
ERROR: Coverage for statements (64.3%) does not meet global threshold (80%)
----------------------------------|---------|----------|---------|---------|----------------------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------------|---------|----------|---------|---------|----------------------------------------------
All files | 64.3 | 38 | 55.88 | 66.26 |
packages/git-proxy-notify-hello | 12.5 | 100 | 0 | 12.5 |
index.js | 12.5 | 100 | 0 | 12.5 | 2-11
src | 57.14 | 50 | 44.44 | 57.14 |
plugin.js | 57.14 | 50 | 44.44 | 57.14 | 35,38-48,74-121,130 Simulating the workflow under a PR$ GITHUB_BASE_REF=main GITHUB_SHA=$(git rev-parse HEAD) npm run test-coverage-ci
> @finos/[email protected] test-coverage-ci
> nyc --reporter=lcovonly --reporter=text --check-coverage npm run test
Generating coverage report for changed files...
nyc config: {
branches: 80,
lines: 80,
functions: 80,
statements: 80,
include: [
'.github/workflows/nodejs.yml',
'README.md',
'nyc.config.js',
'package-lock.json',
'package.json',
'test/1.test.js',
'test/addRepoTest.test.js',
'test/testCheckRepoInAuthList.test.js',
'test/testLogin.test.js',
'test/testUserCreation.test.js',
''
]
}
...
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|------------------- Here are working examples: coopernetes#2 With a "synthetic commit" by changing a file with tests: FYI @JamieSlome diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index 84e8ee0..6cb4630 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -24,6 +24,8 @@ jobs:
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
+ with:
+ fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
diff --git a/.nycrc.json b/.nycrc.json
deleted file mode 100644
index a61301d..0000000
--- a/.nycrc.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "branches": 80,
- "lines": 80,
- "functions": 80,
- "statements": 80
-}
diff --git a/README.md b/README.md
index 60a5e4c..6ac7c0d 100644
--- a/README.md
+++ b/README.md
@@ -290,3 +290,4 @@ This project is distributed under the Apache-2.0 license. See <a href="./LICENSE
If you have a query or require support with this project, [raise an issue](https://github.com/finos/git-proxy/issues). Otherwise, reach out to [[email protected]](mailto:[email protected]).
+
diff --git a/nyc.config.js b/nyc.config.js
new file mode 100644
index 0000000..2971607
--- /dev/null
+++ b/nyc.config.js
@@ -0,0 +1,41 @@
+/* eslint-disable max-len */
+'use strict';
+
+const { execFileSync } = require('child_process');
+
+let opts = {
+ branches: 80,
+ lines: 80,
+ functions: 80,
+ statements: 80,
+};
+
+// Only generate coverage report for changed files in PR
+// see: https://github.com/actions/checkout/issues/438#issuecomment-1446882066
+// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
+if (process.env.GITHUB_BASE_REF !== undefined) {
+ console.log('Generating coverage report for changed files...');
+ try {
+ const baseRef = execFileSync('git', [
+ 'rev-parse',
+ `origin/${process.env.GITHUB_BASE_REF}`,
+ ])
+ .toString()
+ .replace('\n', '');
+ const headRef = process.env.GITHUB_SHA;
+ const stdout = execFileSync('git', [
+ 'diff',
+ '--name-only',
+ `${baseRef}..${headRef}`,
+ ]).toString();
+ opts = {
+ ...opts,
+ include: stdout.split('\n'),
+ };
+ } catch (error) {
+ console.log('Error: ', error);
+ }
+}
+
+console.log('nyc config: ', opts);
+module.exports = opts;
diff --git a/package.json b/package.json
index 1bcaa42..82e1a12 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"server-test": "mocha --exit",
"test": "mocha --exit",
"test-coverage": "nyc npm run test",
- "test-coverage-ci": "nyc --reporter=lcovonly --reporter=text-summary --check-coverage npm run test",
+ "test-coverage-ci": "nyc --reporter=lcovonly --reporter=text --check-coverage npm run test",
"prepare": "node ./scripts/prepare.js",
"lint": "eslint --fix . --ext .js,.jsx"
}, |
@CyberCitizen01 - thank you for the follow-up! 🎉 Happy to merge if you are @coopernetes... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 |
Hello @JamieSlome I wanted to ask and clarify, whether anything from my side is being expected. As it will be lovely if the PR gets merged soon. However I understand if maybe this PR is being regarded as a low priority for now. In that case please let me know if I can do anything to help around here. Thank you and happy holidays 🎉 |
@CyberCitizen01 can you refresh the package-lock.json file by running |
@coopernetes @CyberCitizen01 - I've sorted out our failing CI as it was affecting multiple PRs. Are you able to just resolve the outstanding conflict on the Once that's sorted we'll merge this PR 👍 |
@CyberCitizen01 - just pinging on the above, are we able to get the merge conflict resolved? Very keen to get your fab contributions merged! 👍 |
@JamieSlome - Done 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JamieSlome @CyberCitizen01 please have a look at the suggested change. We don't want to drag this out too much longer but I am concerned with the deprecation notice being generated.
…actions-report-lcov` The original action used is based on a deprecated version of @actions/core that runs on Node 12.x & generates a deprecation warning. Co-authored-by: Thomas Cooper <[email protected]>
@JamieSlome @coopernetes - I've verified that the run of the updated workflow has the expected outcome. I also went ahead and resolved our conversation (#213 (comment)). Please verify and let me know if I can do anything to help. Lets merge this PR 🦾! |
Seems like the new LCOV report action fails when coverage data is missing. Ugh. @CyberCitizen01 can you add @maoo wondering if we should be leveraging codecov instead for generating coverage reports outside of GitHub? It looks available for all FINOS repos2 as far as I can tell. Footnotes |
e75209f
to
e40cfce
Compare
@coopernetes - adding Rationale for forced push: I thought, if there are no tests for created/modified files |
LGTM - thank you @CyberCitizen01 for the contribution and sticking with it after many iterations! |
Nice job, @CyberCitizen01! Hopefully the first of many contributions, you're a star! ⭐ I have left a follow-up comment on #203 with regards to a failing PR which includes a bug fix and new test cases. If we could get some eyes on that, it would be appreciated. |
…overage-reports-on-pull-requests Generate code coverage reports on PRs
Closes #203