-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Node.js coverage workflow template for cloudhealthoffice repo #18
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
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/add-code-coverage-report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60d1d2b
Initial plan
Copilot ac534f4
Add enhanced coverage workflow template for CloudHealthOffice
Copilot a721aa8
Fix YAML linting issues and add quick start guide
Copilot ff7ee57
Add implementation summary for enhanced coverage workflow
Copilot 83fc2bd
Add top-level README for coverage template
Copilot 694aa04
Address code review feedback: fix build step, remove deprecated flagsβ¦
Copilot 488b59f
Merge branch 'main' into copilot/add-code-coverage-report
aurelianware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
303 changes: 303 additions & 0 deletions
303
.github/workflow-templates/CLOUDHEALTHOFFICE_COVERAGE_GUIDE.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,303 @@ | ||
| # Enhanced Code Coverage Report Template for cloudhealthoffice | ||
|
|
||
| ## Overview | ||
|
|
||
| This document provides a workflow template to enhance the code coverage reporting in the **cloudhealthoffice** repository, modeled after the comprehensive coverage implementation in the **privaseeai.net** build (PrivaseeAI.Security repository). | ||
|
|
||
| ## What's Different? | ||
|
|
||
| ### Current CloudHealthOffice Coverage (codecov.yml) | ||
| β Basic codecov upload | ||
| β Terminal coverage summary | ||
| β No HTML coverage artifacts | ||
| β No test result publishing | ||
| β No PR coverage comments | ||
| β No test artifacts | ||
|
|
||
| ### Enhanced Coverage (This Template) | ||
| β Codecov upload (retained) | ||
| β Terminal coverage summary (retained) | ||
| β **HTML coverage reports as downloadable artifacts** (30-day retention) | ||
| β **Test results published as PR status checks** | ||
| β **Automated coverage comments on PRs** | ||
| β **Test result artifacts for debugging** | ||
|
|
||
| ## Implementation Guide | ||
|
|
||
| ### Step 1: Install Required Dependencies | ||
|
|
||
| Add the `jest-junit` package to your `devDependencies` in `package.json`: | ||
|
|
||
| ```bash | ||
| npm install --save-dev jest-junit | ||
| ``` | ||
|
|
||
| ### Step 2: Configure Jest for JUnit Output | ||
|
|
||
| Update your `jest.config.js` or `package.json` jest configuration to support junit reporting: | ||
|
|
||
| ```javascript | ||
| // jest.config.js | ||
| module.exports = { | ||
| // ... existing config ... | ||
| reporters: [ | ||
| 'default', | ||
| ['jest-junit', { | ||
| outputDirectory: './test-results', | ||
| outputName: 'junit.xml', | ||
| }] | ||
| ], | ||
| }; | ||
| ``` | ||
|
|
||
| Or in `package.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "jest": { | ||
| "reporters": [ | ||
| "default", | ||
| ["jest-junit", { | ||
| "outputDirectory": "./test-results", | ||
| "outputName": "junit.xml" | ||
| }] | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Step 3: Update `.gitignore` | ||
|
|
||
| Add these lines to `.gitignore` if not already present: | ||
|
|
||
| ``` | ||
| # Test results and coverage | ||
| coverage/ | ||
| test-results/ | ||
| *.lcov | ||
| ``` | ||
|
|
||
| ### Step 4: Replace the Workflow File | ||
|
|
||
| Replace the current `.github/workflows/codecov.yml` with the enhanced version: | ||
|
|
||
| 1. **Option A: Direct replacement** | ||
| - Copy the content from `.github/workflow-templates/nodejs-coverage-enhanced.yml` in this repository | ||
| - Replace `.github/workflows/codecov.yml` in cloudhealthoffice repository | ||
|
|
||
| 2. **Option B: Create new workflow** | ||
| - Keep the existing `codecov.yml` as backup | ||
| - Create a new file `.github/workflows/test.yml` with the enhanced template | ||
| - Disable the old workflow once the new one is verified | ||
|
|
||
| ### Step 5: Verify Permissions | ||
|
|
||
| Ensure your GitHub Actions workflow has the necessary permissions. The enhanced workflow requires: | ||
|
|
||
| ```yaml | ||
| permissions: | ||
| contents: read | ||
| checks: write | ||
| pull-requests: write | ||
| ``` | ||
|
|
||
| These are already included in the template. | ||
|
|
||
| ### Step 6: Test the Workflow | ||
|
|
||
| 1. Create a pull request with the new workflow | ||
| 2. Verify that the workflow runs successfully | ||
| 3. Check for the following: | ||
| - β Tests execute with coverage | ||
| - β Codecov upload succeeds | ||
| - β Test results appear as PR checks | ||
| - β Coverage comment appears on PR | ||
| - β Artifacts are available for download | ||
|
|
||
| ## What You'll Get | ||
|
|
||
| ### 1. HTML Coverage Reports | ||
|
|
||
| After each workflow run, you can download a complete HTML coverage report: | ||
|
|
||
| - Navigate to the workflow run in the **Actions** tab | ||
| - Scroll to the **Artifacts** section | ||
| - Download `coverage-report-html` | ||
| - Open `index.html` in your browser for interactive coverage exploration | ||
|
|
||
| ### 2. Test Results as PR Checks | ||
|
|
||
| Test results will appear as status checks on pull requests: | ||
| - β Total tests passed/failed/skipped | ||
| - β Test execution time | ||
| - β Detailed breakdown by test suite | ||
|
|
||
| ### 3. PR Coverage Comments | ||
|
|
||
| Each PR will get an automated comment showing: | ||
| - Overall coverage percentage | ||
| - Coverage changes (increase/decrease) | ||
| - File-by-file coverage breakdown | ||
| - Uncovered lines highlighted | ||
|
|
||
| ### 4. Test Result Artifacts | ||
|
|
||
| JUnit XML test results are uploaded as artifacts for: | ||
| - Integration with external tools | ||
| - Historical test result tracking | ||
| - Debugging test failures | ||
|
|
||
| ## Enhanced Features Explained | ||
|
|
||
| ### Feature 1: Multiple Coverage Report Formats | ||
|
|
||
| ```yaml | ||
| npm test -- --coverage \ | ||
| --coverageReporters=lcov \ # For Codecov | ||
| --coverageReporters=json-summary \ # For summary display | ||
| --coverageReporters=text \ # For terminal output | ||
| --coverageReporters=html # For browsable report | ||
| ``` | ||
|
|
||
| ### Feature 2: Test Results Publishing | ||
|
|
||
| ```yaml | ||
| - name: Publish Test Results | ||
| uses: EnricoMi/publish-unit-test-result-action@v2 | ||
| if: always() | ||
| with: | ||
| files: test-results/junit.xml | ||
| check_name: Test Results | ||
| ``` | ||
|
|
||
| This creates a status check on PRs with test statistics. | ||
|
|
||
| ### Feature 3: Coverage Comments on PRs | ||
|
|
||
| ```yaml | ||
| - name: Comment coverage on PR | ||
| uses: romeovs/lcov-reporter-action@v0.3.1 | ||
| if: github.event_name == 'pull_request' | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| lcov-file: ./coverage/lcov.info | ||
| delete-old-comments: true | ||
| ``` | ||
|
|
||
| Automatically posts coverage information to PRs. | ||
|
|
||
| **Security Note:** This example uses a mutable tag (`@v0.3.1`). For enhanced security in production environments, consider pinning this action to a specific commit SHA to prevent potential supply chain attacks. For example: `uses: romeovs/lcov-reporter-action@<commit-sha>`. You can find the commit SHA for a specific release on the action's GitHub repository. | ||
|
|
||
| ### Feature 4: Artifact Upload | ||
|
|
||
| ```yaml | ||
| - name: Upload coverage HTML report | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: coverage-report-html | ||
| path: coverage/ | ||
| retention-days: 30 | ||
| ``` | ||
|
|
||
| Stores coverage and test results for 30 days. | ||
|
|
||
| ## Comparison with PrivaseeAI.Security | ||
|
|
||
| | Feature | PrivaseeAI.Security (Python) | Enhanced CloudHealthOffice (TypeScript) | | ||
| |---------|----------------------------|----------------------------------------| | ||
| | Code Coverage Tool | pytest-cov | Jest | | ||
| | Coverage Upload | Codecov | Codecov | | ||
| | HTML Reports | β htmlcov/ | β coverage/ | | ||
| | Test Result Publishing | β EnricoMi action | β EnricoMi action | | ||
| | PR Coverage Comments | β py-cov-action/python-coverage-comment-action | β lcov-reporter-action | | ||
| | Test Artifacts | β JUnit XML | β JUnit XML | | ||
| | Artifact Retention | 30 days | 30 days | | ||
| | Multi-version Matrix | Python 3.11, 3.12 | Node.js 20 (single) | | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Issue: jest-junit not generating output | ||
|
|
||
| **Solution:** Ensure jest-junit is properly configured in jest.config.js and the outputDirectory exists or can be created. | ||
|
|
||
| ### Issue: Coverage comment not appearing on PR | ||
|
|
||
| **Solution:** | ||
| 1. Verify the workflow has `pull-requests: write` permission | ||
| 2. Check that the workflow is running on `pull_request` events | ||
| 3. Ensure the lcov.info file exists in ./coverage/ | ||
|
|
||
| ### Issue: Test Results check not showing up | ||
|
|
||
| **Solution:** | ||
| 1. Verify the workflow has `checks: write` permission | ||
| 2. Ensure JUnit XML file is generated in the correct location | ||
| 3. Check workflow logs for any errors from the publish-unit-test-result-action | ||
|
|
||
| ### Issue: Artifacts not uploading | ||
|
|
||
| **Solution:** | ||
| 1. Verify paths are correct (coverage/ and test-results/) | ||
| 2. Ensure tests are running and generating output | ||
| 3. Check that `if: always()` is present to upload even on failure | ||
|
|
||
| ## Additional Customization | ||
|
|
||
| ### Adjust Coverage Thresholds | ||
|
|
||
| You can add coverage thresholds in your `jest.config.js`: | ||
|
|
||
| ```javascript | ||
| module.exports = { | ||
| coverageThreshold: { | ||
| global: { | ||
| branches: 80, | ||
| functions: 80, | ||
| lines: 80, | ||
| statements: 80 | ||
| } | ||
| } | ||
| }; | ||
| ``` | ||
|
|
||
| ### Change Artifact Retention | ||
|
|
||
| Modify the `retention-days` value (default is 30, max is 90): | ||
|
|
||
| ```yaml | ||
| retention-days: 90 # Keep artifacts for 90 days | ||
| ``` | ||
|
|
||
| ### Add Coverage Badges | ||
|
|
||
| After implementing this workflow, add a coverage badge to your README: | ||
|
|
||
| ```markdown | ||
| [](https://codecov.io/gh/aurelianware/cloudhealthoffice) | ||
| ``` | ||
|
|
||
| ## Benefits | ||
|
|
||
| 1. **Better PR Reviews**: Reviewers can see coverage impact immediately | ||
| 2. **Interactive Exploration**: HTML reports let you explore uncovered code paths | ||
| 3. **Historical Tracking**: 30-day artifact retention for trend analysis | ||
| 4. **Automated Feedback**: PR comments reduce manual coverage checks | ||
| 5. **Debugging Support**: JUnit XML for integration with test reporting tools | ||
|
|
||
| ## Support | ||
|
|
||
| For issues or questions: | ||
| 1. Check the workflow logs in GitHub Actions | ||
| 2. Review the troubleshooting section above | ||
| 3. Compare with the working PrivaseeAI.Security implementation | ||
| 4. Consult the documentation for the GitHub Actions used: | ||
| - [codecov-action](https://github.com/codecov/codecov-action) | ||
| - [publish-unit-test-result-action](https://github.com/EnricoMi/publish-unit-test-result-action) | ||
| - [lcov-reporter-action](https://github.com/romeovs/lcov-reporter-action) | ||
|
|
||
| --- | ||
|
|
||
| **Template Version:** 1.0 | ||
| **Last Updated:** 2026-02-04 | ||
| **Tested With:** Node.js 20, Jest 29, TypeScript 5 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This example configures the third-party action
romeovs/lcov-reporter-action@v0.3.1via a mutable tag and passessecrets.GITHUB_TOKENwithpull-requests: writeprivileges to any repo that copies it. If that upstream action or its tag is ever compromised, consumer repositories could leak their repo token and allow an attacker to forge or remove coverage comments on pull requests. Update the recommended configuration to pin this action to a vetted commit SHA and, where possible, reduce the token/permissions it receives to the minimum needed for posting comments.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.
Added security note in commit 694aa04. Documentation now includes a warning about using mutable tags and recommends pinning to a specific commit SHA for enhanced security in production environments.