Compare commits
2 commits
renovate/a
...
0.x
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e3d0b5a9d | |||
| 7610b3bef5 |
3 changed files with 45 additions and 5 deletions
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
|
@ -12,6 +12,9 @@ jobs:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install yarn
|
||||||
|
run: npm i -g yarn
|
||||||
|
|
||||||
- name: Set up Node
|
- name: Set up Node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|
@ -38,6 +41,9 @@ jobs:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install yarn
|
||||||
|
run: npm i -g yarn
|
||||||
|
|
||||||
- name: Set up Node
|
- name: Set up Node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
42
src/index.ts
42
src/index.ts
|
|
@ -48,6 +48,40 @@ export const validate = async (argv: Argv) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function isGitRepo() {
|
||||||
|
const isGit = await exec(`git rev-parse --is-inside-work-tree`);
|
||||||
|
return isGit.code === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isSaplingRepo() {
|
||||||
|
const isSapling = await exec(`sl root`);
|
||||||
|
return isSapling.code === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDiff(): Promise<string | undefined> {
|
||||||
|
if (await isGitRepo()) {
|
||||||
|
const diffText = await exec(`git diff origin/HEAD...HEAD`);
|
||||||
|
if (diffText.code > 0) {
|
||||||
|
error("Error loading the diff\n\n" + diffText.stderr);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return diffText.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await isSaplingRepo()) {
|
||||||
|
const diffText = await exec(`sl diff -g -r '. % public()'`);
|
||||||
|
if (diffText.code > 0) {
|
||||||
|
error("Error loading the diff\n\n" + diffText.stderr);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return diffText.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
error("Unable to get a diff no repo was found\n");
|
||||||
|
}
|
||||||
|
|
||||||
export const run = async (argv = process.argv) => {
|
export const run = async (argv = process.argv) => {
|
||||||
const parsed: Argv = await yargs(hideBin(argv)).options(options).argv;
|
const parsed: Argv = await yargs(hideBin(argv)).options(options).argv;
|
||||||
const validationError = await validate(parsed);
|
const validationError = await validate(parsed);
|
||||||
|
|
@ -62,12 +96,12 @@ export const run = async (argv = process.argv) => {
|
||||||
return lcovDiff(baseCoverage, compareCoverage);
|
return lcovDiff(baseCoverage, compareCoverage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const diffText = await exec(`git diff origin/HEAD...HEAD`);
|
const diffText = await getDiff();
|
||||||
if (diffText.code > 0) {
|
if (!diffText) {
|
||||||
return error("Error loading the diff\n\n" + diffText.stderr);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff = parseDiff.default(diffText.stdout);
|
const diff = parseDiff.default(diffText);
|
||||||
|
|
||||||
const { percentage } = report(diff, baseCoverage);
|
const { percentage } = report(diff, baseCoverage);
|
||||||
process.exit(percentage > 90 ? 0 : 1);
|
process.exit(percentage > 90 ? 0 : 1);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const getCoverageForFile = (file: any, coverage: any) => {
|
const getCoverageForFile = (file: any, coverage: any) => {
|
||||||
for (const cov of coverage) {
|
for (const cov of coverage) {
|
||||||
const report: { [k: number]: number } = {};
|
const report: { [k: number]: number } = {};
|
||||||
if (cov.file === file.to) {
|
if (cov.file.replace("./", "") === file.to) {
|
||||||
for (const detail of cov.lines.details) {
|
for (const detail of cov.lines.details) {
|
||||||
report[detail.line] = detail.hit;
|
report[detail.line] = detail.hit;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue