Skip to content

Commit 4682fc3

Browse files
build(release): compiled action for 1.1.0
[skip ci]
1 parent 681c4a9 commit 4682fc3

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

dist/index.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,23 @@ async function main() {
478478
title: core.getInput("title"),
479479
body: core.getInput("body"),
480480
branch: core.getInput("branch"),
481+
path: core.getInput("path"),
481482
commitMessage: core.getInput("commit-message"),
482483
author: core.getInput("author")
483484
};
484485

485486
core.debug(`Inputs: ${inspect(inputs)}`);
486487

487-
const { hasChanges, hasUncommitedChanges } = await getLocalChanges();
488+
const { hasChanges, hasUncommitedChanges } = await getLocalChanges(
489+
inputs.path
490+
);
488491

489492
if (!hasChanges) {
490-
core.info("No local changes");
493+
if (inputs.path) {
494+
core.info(`No local changes matchin "${inputs.path}"`);
495+
} else {
496+
core.info("No local changes");
497+
}
491498
process.exit(0); // there is currently no neutral exit code
492499
}
493500

@@ -511,10 +518,16 @@ async function main() {
511518
});
512519
}
513520

514-
core.debug(`Comitting local changes`);
515-
await command("git add .", { shell: true });
521+
if (inputs.path) {
522+
core.debug(`Committing local changes matching "${inputs.path}"`);
523+
await command(`git add "${inputs.path}"`, { shell: true });
524+
} else {
525+
core.debug(`Committing all local changes`);
526+
await command("git add .", { shell: true });
527+
}
528+
516529
await command(
517-
`git commit -a -m "${inputs.commitMessage}" --author "${inputs.author}"`,
530+
`git commit -m "${inputs.commitMessage}" --author "${inputs.author}"`,
518531
{ shell: true }
519532
);
520533
} else {
@@ -525,12 +538,11 @@ async function main() {
525538
const remoteBranchExists = await checkOutRemoteBranch(inputs.branch);
526539

527540
core.debug(`Pushing local changes`);
528-
const { stdout: pushStdOut, stderr: pushStdErr } = await command(
541+
await command(
529542
`git push -f https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git HEAD:refs/heads/${inputs.branch}`,
530543
{ shell: true }
531544
);
532545

533-
// no idea why the `git push` output goes into stderr. Checking in both just in case.
534546
if (remoteBranchExists) {
535547
core.info(`Existing pull request for "${inputs.branch}" updated`);
536548
return;
@@ -556,8 +568,10 @@ async function main() {
556568
}
557569
}
558570

559-
async function getLocalChanges() {
560-
const { stdout } = await command("git status", { shell: true });
571+
async function getLocalChanges(path) {
572+
const { stdout } = await command(`git status ${path || "*"}`, {
573+
shell: true
574+
});
561575

562576
if (/Your branch is up to date/.test(stdout)) {
563577
return;
@@ -603,16 +617,27 @@ async function setGitUser({ name, email }) {
603617

604618
async function checkOutRemoteBranch(branch) {
605619
try {
620+
const { stdout } = await command(`git rev-parse --abbrev-ref HEAD`, {
621+
shell: true
622+
});
623+
624+
if (stdout === branch) {
625+
core.info(`Already in "${branch}".`);
626+
return true;
627+
}
628+
606629
await command(
607630
`git fetch https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git ${branch}:${branch}`,
608631
{ shell: true }
609632
);
633+
610634
await command(`git checkout ${branch}`, { shell: true });
611635
core.info(`Remote branch "${branch}" checked out locally.`);
612-
await command(`git rebase -Xtheirs -`, { shell: true });
636+
await command(`git rebase -Xtheirs --autostash -`, { shell: true });
613637
return true;
614638
} catch (error) {
615639
core.info(`Branch "${branch}" does not yet exist on remote.`);
640+
await command(`git checkout -b ${branch}`, { shell: true });
616641
return false;
617642
}
618643
}

0 commit comments

Comments
 (0)