Skip to content

Commit

Permalink
fix: Don't commit coverage directory (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton authored Aug 22, 2024
1 parent e411b2e commit 3211e3e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .coverage/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
f
fabf
fabf
fabf
fabd
sliders
dartf
32 changes: 25 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113816,27 +113816,45 @@ const push = async (coverageDirectory) => {
console.error("Unable to check if there are changes", e);
}
(0, core_1.endGroup)();
/// If `stdout` is empty, there are no changes
if (stdout != "") {
(0, core_1.startGroup)("Parse changes and remove coverage directory");
const changes = stdout.split("\n").filter((line) => line.trim() !== "");
if (changes.length === 1 && changes[0].includes(coverageDirectory)) {
changes.pop();
}
(0, core_1.endGroup)();
if (changes.length > 0) {
try {
(0, core_1.startGroup)("Push changes");
(0, core_1.startGroup)("Set up git");
await (0, exec_1.exec)('git config --global user.name "github-actions"');
await (0, exec_1.exec)('git config --global user.email "[email protected]"');
await (0, exec_1.exec)(`git add -A -- ':!${coverageDirectory}'`);
(0, core_1.endGroup)();
try {
(0, core_1.startGroup)("Stage files");
await (0, exec_1.exec)(`git add -A -- :!${coverageDirectory}/`);
await (0, exec_1.exec)(`git add -A -- :!${coverageDirectory}/*`);
}
catch (e) {
console.error("Unable to add files", e);
}
finally {
(0, core_1.endGroup)();
}
(0, core_1.startGroup)("Commit changes");
(0, child_process_1.execSync)(`git commit -m 'chore(automated): Lint commit and format' `);
(0, core_1.endGroup)();
(0, core_1.startGroup)("Push changes");
await (0, exec_1.exec)("git push -f");
(0, core_2.debug)("Changes pushed onto branch");
(0, core_1.endGroup)();
}
catch (e) {
console.error("Unable to push changes", e);
(0, core_1.setFailed)("Unable to push changes to branch");
}
finally {
(0, core_1.endGroup)();
}
}
};
exports.push = push;
(0, exports.push)(".coverage");


/***/ }),
Expand Down
33 changes: 27 additions & 6 deletions src/scripts/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { endGroup, setFailed, setOutput, startGroup } from "@actions/core";
import { exec } from "@actions/exec";
import { execSync } from "child_process";
import { debug } from "@actions/core";
import { start } from "repl";

/**
* Push changes to the branch
Expand All @@ -17,22 +18,42 @@ export const push = async (coverageDirectory: string) => {
console.error("Unable to check if there are changes", e);
}
endGroup();
startGroup("Parse changes and remove coverage directory");
const changes = stdout.split("\n").filter((line) => line.trim() !== "");
if (changes.length === 1 && changes[0].includes(coverageDirectory)) {
changes.pop();
}
endGroup();

/// If `stdout` is empty, there are no changes
if (stdout != "") {
if (changes.length > 0) {
try {
startGroup("Push changes");
startGroup("Set up git");
await exec('git config --global user.name "github-actions"');
await exec('git config --global user.email "[email protected]"');
await exec(`git add -A -- ':!${coverageDirectory}'`);
endGroup();

try {
startGroup("Stage files");
await exec(`git add -A -- :!${coverageDirectory}/`);
await exec(`git add -A -- :!${coverageDirectory}/*`);
} catch (e) {
console.error("Unable to add files", e);
} finally {
endGroup();
}
startGroup("Commit changes");
execSync(`git commit -m 'chore(automated): Lint commit and format' `);
endGroup();
startGroup("Push changes");
await exec("git push -f");

debug("Changes pushed onto branch");
endGroup();
} catch (e) {
console.error("Unable to push changes", e);
setFailed("Unable to push changes to branch");
} finally {
endGroup();
}
}
};

push(".coverage");

0 comments on commit 3211e3e

Please sign in to comment.