Skip to content

Commit

Permalink
chore: consolidate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwozdz committed Feb 19, 2024
1 parent 9f9a30e commit c2aaa3c
Show file tree
Hide file tree
Showing 14 changed files with 354 additions and 25 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
name: CI tests
name: Master CI Tests

on:
push:
branches: [ master ]
pull_request:
branches:
- master
- beta
paths:
- "./.github/**.yml"
- "**/packages/**.js"
- "**/packages/**/package.json"
- "test/**/*.js"

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

steps:
- uses: actions/checkout@v3
- 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 }}
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/pr-tests.yml
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
6 changes: 5 additions & 1 deletion .gitignore
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
8 changes: 8 additions & 0 deletions ci/clean-coverage.js
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');
44 changes: 44 additions & 0 deletions ci/format-branch-coverage-changes.js
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} ![green](https://github.com/koopjs/koop/assets/4369192/fd82d4b7-7f6e-448c-a56c-82ac6781a629)`;
}

if (input.pct > 90) {
return `${input.pct} ![yellow-green](https://github.com/koopjs/koop/assets/4369192/683b2df8-7379-4e4f-bb36-f5e20b2631d6)`;
}

if (input.pct > 80) {
return `${input.pct} ![yellow](https://github.com/koopjs/koop/assets/4369192/d5214a5c-c5a9-4449-82ca-8a4e922ef9ef)`;
}

if (input.pct > 70) {
return `${input.pct} ![orange](https://github.com/koopjs/koop/assets/4369192/8651f10c-e986-491d-8b51-bc559aac88a2)`;
}

return `${input.pct} ![red](https://github.com/koopjs/koop/assets/4369192/83e9c13e-0548-4b97-a116-6e49f77a8f38)`;
}

21 changes: 21 additions & 0 deletions ci/run-coverage-on-branch-changes.js
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)
Loading

0 comments on commit c2aaa3c

Please sign in to comment.