-
Notifications
You must be signed in to change notification settings - Fork 3
Post reports as a single PR comment #151
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
gohabereg
wants to merge
45
commits into
main
Choose a base branch
from
chore/pr-reporting
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
45 commits
Select commit
Hold shift + click to select a range
2ce87da
Post reports as a single PR comment
gohabereg d8edf3a
Merge branch 'main' into chore/pr-reporting
gohabereg 88f1dd4
update all actions
gohabereg c175508
Remove core require
gohabereg 8b117ee
build packages for base branch test run
gohabereg 8904eb5
Replace require with import
gohabereg 2f21c6c
Revert "Replace require with import"
gohabereg 6642696
Replace require only inside js scripts
gohabereg 1898afa
Fixes
gohabereg 1b629a0
Remove unused code
gohabereg f6382d4
Pass core and github as parameters
gohabereg 6834c3e
Remove require core and github
gohabereg 1cca3ed
revert github require
gohabereg e962bcc
Pass context separately
gohabereg 7910489
Remove turnstyle initial wait, update cache action
gohabereg d8bf2c1
Add reporting for unit tests to each package, update changed-files ac…
gohabereg 9197c9b
Use coverage json-summary reporter
gohabereg ff2acc8
Upload mutation artifact even if no files changed
gohabereg 7aa89ef
Send message about files not found if the files list is empty
gohabereg 00051da
Add concurrency
gohabereg acb8efd
Test coverage drop and mutation tests report
gohabereg e41ee6e
Add at least one test
gohabereg b3be451
fixes
gohabereg 3865c3c
update files list formatting
gohabereg 389e2b5
Update artifact paths
gohabereg d5e785f
Test coverage drop
gohabereg 7b9bb7e
Always run report, add dashboard url to mutation report
gohabereg 952d1e8
fix base branch tests checkout
gohabereg eca9bfe
Test dashboard url
gohabereg 72a3a1c
Add json report for dom-adapters
gohabereg 9da66ec
Mutation score to percent conversion
gohabereg 1685a8c
Switch warning and caution
gohabereg b30e1fd
resolve review comments
gohabereg 488bf4c
Extract duplication to a common workflow. Run workflow only if packag…
gohabereg 8f2da60
resolve base ref for shallow clone
gohabereg fbe7bd8
Update script
gohabereg 9533fee
Update path to script
gohabereg 0d24791
Remove some lint warnings
gohabereg 962b1b0
Update format
gohabereg a08ce4a
Fix typo
gohabereg d0bb75a
Get info from computed data
gohabereg 6461226
Add pipes at the end of the rows
gohabereg 1515928
Remove empty lines between rows
gohabereg c13ff85
test updates and mutation report
gohabereg 605d146
Revert test
gohabereg 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
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,78 @@ | ||
| name: Aggregate report | ||
| description: 'Process downloaded artifacts (downloaded with actions/download-artifact) and produce a markdown report section' | ||
| inputs: | ||
| package-name: | ||
| description: 'Full package name (workspace)' | ||
| required: true | ||
| working-directory: | ||
| description: 'Path to the ./packages/name_of_your_package_folder' | ||
| required: true | ||
| outputs: | ||
| report: | ||
| description: 'Markdown report section generated by the action' | ||
| value: ${{ steps.section-report.outputs.report }} | ||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Download artifacts | ||
| uses: actions/download-artifact@v8 | ||
|
|
||
| - name: Find current PR's number | ||
| uses: jwalton/gh-find-current-pr@v1 | ||
| id: find_pr | ||
|
|
||
| - name: Process coverage reports | ||
| uses: actions/github-script@v9 | ||
| id: process_test_report | ||
| env: | ||
| PACKAGE_NAME: ${{ inputs.package-name }} | ||
| with: | ||
| script: | | ||
| const processReports = require('./.github/scripts/compare-coverage.js').processReports; | ||
|
|
||
| core.setOutput('message', processReports(process.env.PACKAGE_NAME, 'test-report', 'test-report-base')); | ||
|
|
||
| - name: Process mutation report | ||
| uses: actions/github-script@v9 | ||
| id: process_mutation_report | ||
| env: | ||
| WORKING_DIR: ${{ inputs.working-directory }} | ||
| PR_NUMBER: ${{ steps.find_pr.outputs.number }} | ||
| PACKAGE_NAME: ${{ inputs.package-name }} | ||
| with: | ||
| script: | | ||
| const processMutationReport = require('./.github/scripts/process-mutation.js').processMutationReport; | ||
|
|
||
| core.setOutput('message', processMutationReport('mutation-report', `${process.env.WORKING_DIR}/reports/mutation/mutation.json`, 'changed-files.json', process.env.PR_NUMBER, process.env.PACKAGE_NAME)); | ||
|
|
||
| - name: Acquire comment-update lock | ||
| id: acquire_lock | ||
| uses: softprops/turnstyle@v3 | ||
| with: | ||
| queue-name: aggregated-comment-${{ steps.find_pr.outputs.number || github.ref_name || github.ref }}}} | ||
|
|
||
| - name: Create or update PR comment with report | ||
| uses: actions/github-script@v9 | ||
| env: | ||
| REPORT: ${{ steps.section-report.outputs.report }} | ||
| PACKAGE: ${{ inputs.package-name }} | ||
| PR_NUMBER: ${{ steps.find_pr.outputs.number }} | ||
| MUTATION_MESSAGE: ${{ steps.process_mutation_report.outputs.message }} | ||
| UNIT_TEST_MESSAGE: ${{ steps.process_test_report.outputs.message }} | ||
| with: | ||
| script: | | ||
| const updater = require('./.github/scripts/update-aggregated-comment.js'); | ||
|
|
||
| (async () => { | ||
| try { | ||
| const packageName = process.env.PACKAGE; | ||
| const mutationRow = process.env.MUTATION_MESSAGE; | ||
| const unitTestRow = process.env.UNIT_TEST_MESSAGE; | ||
| const pr = process.env.PR_NUMBER || undefined; | ||
| // Pass the injected core, github and context objects | ||
| await updater.updateAggregatedComment(unitTestRow, mutationRow, packageName, pr, core, github, context); | ||
| } catch (err) { | ||
| core.error(err && err.stack ? err.stack : String(err)); | ||
| throw err; | ||
| } | ||
| })(); | ||
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,45 @@ | ||
| name: Base coverage | ||
| description: "Checkout base ref, run package coverage and upload artifact" | ||
| inputs: | ||
| package-name: | ||
| description: 'Full package name (workspace)' | ||
| required: true | ||
| working-directory: | ||
| description: 'Working directory relative to repo root (package folder)' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Checkout base ref | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: .nvmrc | ||
|
|
||
| - name: Setup environment | ||
| uses: ./.github/actions/setup | ||
|
|
||
| - name: Build the package | ||
| shell: bash | ||
| run: yarn workspace ${{ inputs.package-name }} run build | ||
| working-directory: ${{ inputs.working-directory }} | ||
|
|
||
| - name: Run coverage | ||
| shell: bash | ||
| run: yarn workspace ${{ inputs.package-name }} test:coverage | ||
| working-directory: ${{ inputs.working-directory }} | ||
|
|
||
| - name: Upload base coverage artifact | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: test-report-base | ||
| path: | | ||
| ${{ inputs.working-directory }}/coverage | ||
| ${{ inputs.working-directory }}/jest-report.json | ||
| retention-days: 3 |
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
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
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
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
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
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
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,71 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
gohabereg marked this conversation as resolved.
|
||
|
|
||
| function findCoverageJson(dir) { | ||
| if (!dir) return null; | ||
| const report = path.join(dir, 'coverage', 'coverage-summary.json'); | ||
|
|
||
|
|
||
| if (fs.existsSync(report)) { | ||
| try { | ||
| return JSON.parse(fs.readFileSync(report, 'utf8')); | ||
| } catch (report) { | ||
| console.error(report); | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+9
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice if eslint checked this scripts too, but for now i would suggest logging of the report or explicitly dismissing with |
||
| return null; | ||
| } | ||
|
|
||
|
|
||
| function pctFromCoverageSummary(obj, category) { | ||
| if (!obj) return null; | ||
|
|
||
| if (obj.total && obj.total[category] && typeof obj.total[category].pct === 'number') return obj.total[category].pct; | ||
|
|
||
| if (obj[category] && typeof obj[category].pct === 'number') return obj[category].pct; | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| function compute(headSummary, baseSummary) { | ||
| const categories = ['statements', 'branches', 'functions', 'lines']; | ||
|
|
||
| const out = {}; | ||
|
|
||
| for (const cat of categories) { | ||
| const headPct = pctFromCoverageSummary(headSummary, cat); | ||
| const basePct = pctFromCoverageSummary(baseSummary, cat); | ||
|
|
||
| let delta = 'N/A'; | ||
|
|
||
| if (headPct != null && basePct != null) { | ||
| delta = Number((headPct - basePct).toFixed(2)); | ||
| } | ||
|
|
||
| out[cat] = { head: headPct, base: basePct, delta }; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| export function processReports(pkg, headDir, baseDir) { | ||
| const headCov = findCoverageJson(headDir); | ||
| const baseCov = findCoverageJson(baseDir); | ||
|
|
||
| const categories = compute(headCov, baseCov); | ||
|
|
||
| let delta = categories.branches.delta; | ||
|
|
||
| if (delta < 0) { | ||
| delta = `+${delta}% 🟢`; | ||
| } else if (delta > 0) { | ||
| delta = `-${delta}% 🔴`; | ||
| } else if (delta === 0) { | ||
| delta = `0% ⚪️`; | ||
| } | ||
|
|
||
| // | Package | Branches coverage | Delta | | ||
| return `| ${pkg} | ${categories.branches.head}% | ${delta} |`; | ||
| } | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.