Skip to content

Commit c2aaa3c

Browse files
committed
chore: consolidate changes
1 parent 9f9a30e commit c2aaa3c

File tree

14 files changed

+354
-25
lines changed

14 files changed

+354
-25
lines changed

.github/workflows/ci-tests.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
name: CI tests
1+
name: Master CI Tests
22

33
on:
44
push:
55
branches: [ master ]
6-
pull_request:
7-
branches:
8-
- master
9-
- beta
10-
paths:
11-
- "./.github/**.yml"
12-
- "**/packages/**.js"
13-
- "**/packages/**/package.json"
14-
- "test/**/*.js"
156

167
jobs:
178
pr-tests:
@@ -24,7 +15,14 @@ jobs:
2415
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2516

2617
steps:
27-
- uses: actions/checkout@v3
18+
- name: Checkout actions
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
- run: |
23+
git checkout -b master origin/master
24+
git checkout -
25+
2826
- uses: actions/setup-node@v3
2927
with:
3028
node-version: ${{ matrix.node-version }}

.github/workflows/pr-tests.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: PR CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- beta
8+
paths:
9+
- "./.github/**.yml"
10+
- "**/packages/**.js"
11+
- "**/packages/**/package.json"
12+
- "test/**/*.js"
13+
14+
jobs:
15+
pr-tests:
16+
name: Install, lint, test
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
node-version: [18.x]
21+
os: [ubuntu-latest, windows-latest]
22+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
23+
24+
steps:
25+
- name: Checkout actions
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
- run: |
30+
git checkout -b master origin/master
31+
git checkout -
32+
33+
- uses: actions/setup-node@v3
34+
with:
35+
node-version: ${{ matrix.node-version }}
36+
37+
- name: Install npm 7
38+
run: npm i -g npm@7 --registry=https://registry.npmjs.org
39+
40+
- name: Install
41+
run: npm ci
42+
43+
- name: Lint
44+
run: npm run lint:ci
45+
46+
- name: Unit tests
47+
run: npm test --workspaces
48+
49+
- name: E2E tests
50+
run: npm run test:e2e
51+
52+
- name: Run Coverage
53+
if: ${{ matrix.os == 'ubuntu-latest' }}
54+
run: npm run clean:cov && npm run test:cov:changes && npm run cov:md
55+
56+
- name: Run Coverage
57+
if: ${{ matrix.os == 'ubuntu-latest' }}
58+
run: cat coverage_changes/coverage-summary.json
59+
60+
- name: Find previous coverage comment
61+
if: ${{ matrix.os == 'ubuntu-latest' }}
62+
uses: peter-evans/find-comment@v1
63+
id: findcomment
64+
with:
65+
issue-number: ${{ github.event.pull_request.number }}
66+
comment-author: 'github-actions[bot]'
67+
body-includes: Coverage Report
68+
69+
- name: Create or update comment
70+
if: ${{ matrix.os == 'ubuntu-latest' }}
71+
uses: peter-evans/create-or-update-comment@v4
72+
with:
73+
comment-id: ${{ steps.findcomment.outputs.comment-id }}
74+
issue-number: ${{ github.event.pull_request.number }}
75+
body-path: ci/branch-coverage-changes.md
76+
edit-mode: replace

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
node_modules
22
coverage
33
coverage_unit
4+
coverage_changes
5+
coverage.json
46
.nyc_output
57
.nyc_output_unit
8+
.nyc_output_changes
69
.vscode
710
**/.DS_Store
811
.env
9-
.npmrc
12+
.npmrc
13+
ci/branch-coverage-changes.md

ci/clean-coverage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const shell = require('shelljs');
2+
3+
shell.rm('-rf', 'coverage');
4+
shell.rm('-rf', 'coverage_unit');
5+
shell.rm('-rf', 'coverage_changes');
6+
shell.rm('-rf', '.nyc_output');
7+
shell.rm('-rf', '.nyc_output_unit');
8+
shell.rm('-rf', '.nyc_output_changes');

ci/format-branch-coverage-changes.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { writeFileSync } = require('fs');
2+
const json2md = require('json2md');
3+
const coverageSummary = require('../coverage_changes/coverage-summary.json');
4+
5+
const rows = Object.entries(coverageSummary)
6+
.filter(([filePath]) => {
7+
return filePath !== 'total';
8+
})
9+
.map(([filePath, value]) => {
10+
const packagePath = filePath.split('packages')[1];
11+
return [
12+
`packages${packagePath}`,
13+
getValue(value.statements),
14+
getValue(value.branches),
15+
getValue(value.functions),
16+
getValue(value.lines),
17+
];
18+
});
19+
20+
const headers = ['File Path', 'Statements', 'Branches', 'Functions', 'Lines'];
21+
const markdown = json2md([{ h2: 'Coverage Report'}, { table: { headers, rows } }]);
22+
const aligned = markdown.replace('| --------- | ---------- | -------- | --------- | ----- |', '| :--------- | ----------: | --------: | ---------: | -----: |');
23+
writeFileSync('ci/branch-coverage-changes.md', aligned, 'utf8');
24+
25+
function getValue(input) {
26+
if (input.pct === 100) {
27+
return `${input.pct} ![green](https://github.com/koopjs/koop/assets/4369192/fd82d4b7-7f6e-448c-a56c-82ac6781a629)`;
28+
}
29+
30+
if (input.pct > 90) {
31+
return `${input.pct} ![yellow-green](https://github.com/koopjs/koop/assets/4369192/683b2df8-7379-4e4f-bb36-f5e20b2631d6)`;
32+
}
33+
34+
if (input.pct > 80) {
35+
return `${input.pct} ![yellow](https://github.com/koopjs/koop/assets/4369192/d5214a5c-c5a9-4449-82ca-8a4e922ef9ef)`;
36+
}
37+
38+
if (input.pct > 70) {
39+
return `${input.pct} ![orange](https://github.com/koopjs/koop/assets/4369192/8651f10c-e986-491d-8b51-bc559aac88a2)`;
40+
}
41+
42+
return `${input.pct} ![red](https://github.com/koopjs/koop/assets/4369192/83e9c13e-0548-4b97-a116-6e49f77a8f38)`;
43+
}
44+

ci/run-coverage-on-branch-changes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const shell = require('shelljs');
2+
const git = require('simple-git');
3+
4+
git().diffSummary(['--name-only', '--relative', 'origin/master'])
5+
.then(summary => {
6+
const {files} = summary;
7+
const srcFiles = files.filter(({ file }) => {
8+
return file.endsWith('.js') && !file.endsWith('spec.js');
9+
}).map(({ file }) => {
10+
return `-n ${file}`;
11+
});
12+
13+
if (srcFiles.length === 0) {
14+
process.exit();
15+
}
16+
17+
const cmd = `nyc -r=json-summary --report-dir=coverage_changes --temp-dir=.nyc_output_changes ${srcFiles.join(' ')} npm run test:quiet`;
18+
shell.exec(cmd);
19+
});
20+
21+
//console.log(diff)

0 commit comments

Comments
 (0)