Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Aug 22, 2024
1 parent 8a4ad0d commit b1c883f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
17 changes: 7 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113817,23 +113817,20 @@ const push = async (coverageDirectory) => {
}
(0, core_1.endGroup)();
const changes = stdout.split("\n").filter((line) => line.trim() !== "");
/// If `stdout` is empty, there are no changes
console.log(changes);
if (stdout != "") {
if (changes.length === 1 && changes[0].includes(coverageDirectory)) {
changes.pop();
}
if (changes.length > 0) {
try {
(0, core_1.startGroup)("Push changes");
await (0, exec_1.exec)('git config --global user.name "github-actions"');
await (0, exec_1.exec)('git config --global user.email "[email protected]"');
try {
await (0, exec_1.exec)(`git add -A -- ':!/${coverageDirectory}/*'`);
await (0, exec_1.exec)(`git add -A -- :!${coverageDirectory}/`);
await (0, exec_1.exec)(`git add -A -- :!${coverageDirectory}/*`);
}
catch (e) {
try {
await (0, exec_1.exec)(`git add -A -- :!/${coverageDirectory}/*`);
}
catch (e) {
console.error("Unable to add files", e);
}
console.error("Unable to add files", e);
}
(0, child_process_1.execSync)(`git commit -m 'chore(automated): Lint commit and format' `);
await (0, exec_1.exec)("git push -f");
Expand Down
36 changes: 22 additions & 14 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,33 +18,40 @@ 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 `stdout` is empty, there are no changes
console.log(changes);
if (stdout != "") {
if (changes.length === 1 && changes[0].includes(coverageDirectory)) {
changes.pop();
}
endGroup();

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]"');
endGroup();

try {
await exec(`git add -A -- ':!/${coverageDirectory}/*'`);
startGroup("Stage files");
await exec(`git add -A -- :!${coverageDirectory}/`);
await exec(`git add -A -- :!${coverageDirectory}/*`);
} catch (e) {
try {
await exec(`git add -A -- :!/${coverageDirectory}/*`);
} catch (e) {
console.error("Unable to add files", 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();
}
}
};
Expand Down

0 comments on commit b1c883f

Please sign in to comment.