Skip to content

Commit

Permalink
Merge branch 'releases/v4-flow' of https://github.com/JamesIves/githu…
Browse files Browse the repository at this point in the history
…b-pages-deploy-action into releases/v4-flow
  • Loading branch information
JamesIves committed May 18, 2024
2 parents d39ecd4 + 51e091a commit 4dd89e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/execute.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
type ExecuteOutput = {
stdout: string;
stderr: string;
exitCode: number;
};
/** Wrapper around the GitHub toolkit exec command which returns the output.
* Also allows you to easily toggle the current working directory.
Expand Down
13 changes: 10 additions & 3 deletions lib/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.stderr = exports.stdout = exports.execute = void 0;
const exec_1 = require("@actions/exec");
const buffer_1 = __importDefault(require("buffer"));
const output = { stdout: '', stderr: '' };
const output = { stdout: '', stderr: '', exitCode: 0 };
/** Wrapper around the GitHub toolkit exec command which returns the output.
* Also allows you to easily toggle the current working directory.
*
Expand All @@ -29,11 +29,18 @@ function execute(cmd_1, cwd_1, silent_1) {
return __awaiter(this, arguments, void 0, function* (cmd, cwd, silent, ignoreReturnCode = false) {
output.stdout = '';
output.stderr = '';
yield (0, exec_1.exec)(cmd, [], {
output.exitCode = yield (0, exec_1.exec)(cmd, [], {
// Silences the input unless the INPUT_DEBUG flag is set.
silent,
cwd,
listeners: { stdout, stderr },
listeners: {
stdout: (data) => {
stdout(data);
},
stderr: (data) => {
stderr(data);
}
},
ignoreReturnCode
});
return Promise.resolve(output);
Expand Down
6 changes: 6 additions & 0 deletions lib/worktree.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ function generateWorktree(action, worktreedir, branchExists) {
if (branchExists) {
yield (0, execute_1.execute)(`git fetch --no-recurse-submodules --depth=1 origin ${action.branch}`, action.workspace, action.silent);
}
// Check if the worktree already exists
const { exitCode } = yield (0, execute_1.execute)(`git worktree list | grep ${worktreedir}`, action.workspace, action.silent);
// If the worktree exists, remove it
if (exitCode === 0) {
yield (0, execute_1.execute)(`git worktree remove ${worktreedir}`, action.workspace, action.silent);
}
yield (0, execute_1.execute)(`git worktree add --no-checkout --detach ${worktreedir}`, action.workspace, action.silent);
const checkout = new GitCheckout(action.branch);
if (branchExists) {
Expand Down

0 comments on commit 4dd89e1

Please sign in to comment.