Skip to content

Commit

Permalink
debugging!
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Nov 16, 2023
1 parent f0feaf7 commit 276080b
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { resolve, join } from "node:path";
import assert from "node:assert/strict";
import * as core from "@actions/core";
import * as github from "@actions/github";

process.env.NODE_DEBUG = "execa";
const { $ } = await import("execa");
import { $ } from "execa";

const rootPath = resolve(core.getInput("path"));
const $r = $({ cwd: rootPath });
Expand Down Expand Up @@ -94,18 +92,24 @@ async function push(

add: {
const force = core.getBooleanInput("add-force");
core.info(`add: force=${force}`);
if (core.getInput("add-pathspec")) {
await add(core.getMultilineInput("add-pathspec"), { force });
const pathspecs = core.getMultilineInput("add-pathspec");
core.info(`add: pathspecs=${JSON.stringify(pathspecs)}`);
await add(pathspecs, { force });
} else {
core.info(`add: all`);
await add.all({ force });
}
}

let before: string;
commit: {
({ stdout: before } = await $r`git rev-parse HEAD`);
core.info(`commit: before=${before}`);

if ((await $rs`git diff --cached`).exitCode) {
core.info(`commit: no changes`);
core.setOutput("committed", false);
core.setOutput("commit-sha", before);
break commit;
Expand All @@ -116,29 +120,37 @@ commit: {
(core.getInput("author-name") && core.getInput("author-email"))
? `${core.getInput("author-name")} <${core.getInput("author-email")}>`
: undefined;
core.info(`commit: author=${author}`);

const committer =
core.getInput("committer") ||
(core.getInput("committer-name") && core.getInput("committer-email"))
? `${core.getInput("committer-name")} <${core.getInput(
"committer-email"
)}>`
: undefined;
core.info(`commit: committer=${committer}`);

const message = core.getInput("commit-message");
core.info(`commit: message=${message}`);

const sha = await commit(message, { author, committer });
core.info(`commit: sha=${sha}`);

core.setOutput("committed", true);
core.setOutput("commit-sha", sha);
}

const data = await (async () => {
try {
const { stdout: tag } = await $r`git describe --exact-match --tags ${before}`;
const { stdout: tag } =
await $r`git describe --exact-match --tags ${before}`;
return { type: "tag", tag } as const;
} catch {}

try {
const { stdout: ref } = await $r`git rev-parse --symbolic-full-name ${before}`;
const { stdout: ref } =
await $r`git rev-parse --symbolic-full-name ${before}`;
if (ref.startsWith("refs/pull/")) {
const head = ref.split("/")[2];
return { type: "pull-request", head } as const;
Expand All @@ -148,23 +160,30 @@ const data = await (async () => {
const { stdout: branch } = await $r`git branch --show-current`;
return { type: "branch", branch } as const;
})();
core.info(`data=${JSON.stringify(data)}`);

tag: {
if (data.type === "tag") {
core.info(`tag: tag=${data.tag}`);
const name = core.getInput("tag-tagname") || data.tag;
core.info(`tag: name=${name}`);
const force = core.getInput("tag-force")
? core.getBooleanInput("tag-force")
: !!data.tag;
core.info(`tag: force=${force}`);
await tag(name, { force });
}
}

push: {
const repository = core.getInput("push-repository");
let refspec = core.getInput("push-refspec") || data.tag;
let force = core.getInput("push-force")
core.info(`push: repository=${repository}`);
const refspec = core.getInput("push-refspec") || data.tag;
core.info(`push: refspec=${refspec}`);
const force = core.getInput("push-force")
? core.getBooleanInput("push-force")
: data.type === "tag";
core.info(`push: force=${force}`);

await push(repository, refspec, { force });
core.setOutput("pushed", true);
Expand Down

0 comments on commit 276080b

Please sign in to comment.