-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
354 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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,76 @@ | ||
name: PR CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
- beta | ||
paths: | ||
- "./.github/**.yml" | ||
- "**/packages/**.js" | ||
- "**/packages/**/package.json" | ||
- "test/**/*.js" | ||
|
||
jobs: | ||
pr-tests: | ||
name: Install, lint, test | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
os: [ubuntu-latest, windows-latest] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- name: Checkout actions | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- run: | | ||
git checkout -b master origin/master | ||
git checkout - | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install npm 7 | ||
run: npm i -g npm@7 --registry=https://registry.npmjs.org | ||
|
||
- name: Install | ||
run: npm ci | ||
|
||
- name: Lint | ||
run: npm run lint:ci | ||
|
||
- name: Unit tests | ||
run: npm test --workspaces | ||
|
||
- name: E2E tests | ||
run: npm run test:e2e | ||
|
||
- name: Run Coverage | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
run: npm run clean:cov && npm run test:cov:changes && npm run cov:md | ||
|
||
- name: Run Coverage | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
run: cat coverage_changes/coverage-summary.json | ||
|
||
- name: Find previous coverage comment | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
uses: peter-evans/find-comment@v1 | ||
id: findcomment | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: Coverage Report | ||
|
||
- name: Create or update comment | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
comment-id: ${{ steps.findcomment.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body-path: ci/branch-coverage-changes.md | ||
edit-mode: replace |
This file contains 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
node_modules | ||
coverage | ||
coverage_unit | ||
coverage_changes | ||
coverage.json | ||
.nyc_output | ||
.nyc_output_unit | ||
.nyc_output_changes | ||
.vscode | ||
**/.DS_Store | ||
.env | ||
.npmrc | ||
.npmrc | ||
ci/branch-coverage-changes.md |
This file contains 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,8 @@ | ||
const shell = require('shelljs'); | ||
|
||
shell.rm('-rf', 'coverage'); | ||
shell.rm('-rf', 'coverage_unit'); | ||
shell.rm('-rf', 'coverage_changes'); | ||
shell.rm('-rf', '.nyc_output'); | ||
shell.rm('-rf', '.nyc_output_unit'); | ||
shell.rm('-rf', '.nyc_output_changes'); |
This file contains 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,44 @@ | ||
const { writeFileSync } = require('fs'); | ||
const json2md = require('json2md'); | ||
const coverageSummary = require('../coverage_changes/coverage-summary.json'); | ||
|
||
const rows = Object.entries(coverageSummary) | ||
.filter(([filePath]) => { | ||
return filePath !== 'total'; | ||
}) | ||
.map(([filePath, value]) => { | ||
const packagePath = filePath.split('packages')[1]; | ||
return [ | ||
`packages${packagePath}`, | ||
getValue(value.statements), | ||
getValue(value.branches), | ||
getValue(value.functions), | ||
getValue(value.lines), | ||
]; | ||
}); | ||
|
||
const headers = ['File Path', 'Statements', 'Branches', 'Functions', 'Lines']; | ||
const markdown = json2md([{ h2: 'Coverage Report'}, { table: { headers, rows } }]); | ||
const aligned = markdown.replace('| --------- | ---------- | -------- | --------- | ----- |', '| :--------- | ----------: | --------: | ---------: | -----: |'); | ||
writeFileSync('ci/branch-coverage-changes.md', aligned, 'utf8'); | ||
|
||
function getValue(input) { | ||
if (input.pct === 100) { | ||
return `${input.pct} `; | ||
} | ||
|
||
if (input.pct > 90) { | ||
return `${input.pct} `; | ||
} | ||
|
||
if (input.pct > 80) { | ||
return `${input.pct} `; | ||
} | ||
|
||
if (input.pct > 70) { | ||
return `${input.pct} `; | ||
} | ||
|
||
return `${input.pct} `; | ||
} | ||
|
This file contains 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,21 @@ | ||
const shell = require('shelljs'); | ||
const git = require('simple-git'); | ||
|
||
git().diffSummary(['--name-only', '--relative', 'origin/master']) | ||
.then(summary => { | ||
const {files} = summary; | ||
const srcFiles = files.filter(({ file }) => { | ||
return file.endsWith('.js') && !file.endsWith('spec.js'); | ||
}).map(({ file }) => { | ||
return `-n ${file}`; | ||
}); | ||
|
||
if (srcFiles.length === 0) { | ||
process.exit(); | ||
} | ||
|
||
const cmd = `nyc -r=json-summary --report-dir=coverage_changes --temp-dir=.nyc_output_changes ${srcFiles.join(' ')} npm run test:quiet`; | ||
shell.exec(cmd); | ||
}); | ||
|
||
//console.log(diff) |
Oops, something went wrong.