Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3999,7 +3999,7 @@ async function execCommand(command, args, options = {}, logError = true) {
return false;
}
}
async function runAction(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha) {
async function runAction(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName) {
const failOnCheckError = standardsFail === "true";
const valid = verifyInput(opticToken, eventName, owner, repo);
if (!valid) {
Expand Down Expand Up @@ -4038,7 +4038,8 @@ async function runAction(opticToken, githubToken, additionalArgs, standardsFail,
core.error("Unable to determine base for comparison.");
return 1;
}
const comparisonRun = await diffAll(opticToken, from, additionalArgs);
const headTag = refName ? `gitbranch:${refName}` : undefined;
const comparisonRun = await diffAll(opticToken, from, additionalArgs, headTag);
if (eventName === "pull_request") {
const commentResult = await prComment(githubToken, owner || "", repo || "", pr || "", sha || "");
if (!commentResult) {
Expand Down Expand Up @@ -4096,14 +4097,15 @@ async function deepen() {
}
return true;
}
async function diffAll(token, from, additionalArgs) {
async function diffAll(token, from, additionalArgs, headTag) {
core.info("Running Optic diff-all");
return execCommand("optic", [
"diff-all",
"--compare-from",
from,
"--check",
"--upload",
...(headTag ? ["--head-tag", headTag] : []),
...(additionalArgs ? [additionalArgs] : []),
], {
env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }),
Expand Down Expand Up @@ -4171,10 +4173,11 @@ const additionalArgs = core.getInput("additional_args");
const eventName = process.env.GITHUB_EVENT_NAME;
const headRef = process.env.GITHUB_REF;
const baseRef = process.env.GITHUB_BASE_REF;
const refName = process.env.GITHUB_REF_NAME;
const owner = process.env.GITHUB_REPOSITORY_OWNER;
const repo = (_a = process.env.GITHUB_REPOSITORY) === null || _a === void 0 ? void 0 : _a.split("/")[1];
const sha = process.env.GITHUB_SHA;
(0, action_1.runAction)(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha)
(0, action_1.runAction)(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName)
.then((exitCode) => {
return process.exit(exitCode);
})
Expand Down
23 changes: 16 additions & 7 deletions src/__tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ test("invalid input", async () => {
undefined,
"owner",
"repo",
"abc123"
"abc123",
""
);
expect(exitCode).toBe(1);
});
Expand All @@ -32,7 +33,8 @@ test("failed install", async () => {
undefined,
"owner",
"repo",
"abc123"
"abc123",
"main"
);
expect(exitCode).toBe(1);
assertFailedInstall();
Expand All @@ -54,7 +56,8 @@ test("pull_request event", async () => {
"main",
"owner",
"repo",
"abc123"
"abc123",
"main"
);
expect(exitCode).toBe(0);
assertInstall();
Expand All @@ -78,7 +81,8 @@ test("push event", async () => {
undefined,
"owner",
"repo",
"abc123"
"abc123",
"main"
);
expect(exitCode).toBe(0);
assertInstall();
Expand All @@ -103,7 +107,8 @@ test("push event with additional-args", async () => {
undefined,
"owner",
"repo",
"abc123"
"abc123",
"main"
);
expect(exitCode).toBe(0);
assertInstall();
Expand All @@ -126,7 +131,8 @@ test("push event with standards failure and standards_fail set to true", async (
undefined,
"owner",
"repo",
"abc123"
"abc123",
"main"
);
expect(exitCode).toBe(1);
assertInstall();
Expand All @@ -149,7 +155,8 @@ test("push event with standards failure but standards_fail set to false", async
undefined,
"owner",
"repo",
"abc123"
"abc123",
"main"
);
expect(exitCode).toBe(0);
assertInstall();
Expand Down Expand Up @@ -219,6 +226,8 @@ function mockDiffAll(
from,
"--check",
"--upload",
"--head-tag",
"gitbranch:main",
...additionalArgs,
],
expect.objectContaining({
Expand Down
18 changes: 15 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export async function runAction(
baseRef: string | undefined,
owner: string | undefined,
repo: string | undefined,
sha: string | undefined
sha: string | undefined,
refName: string | undefined
): Promise<number> {
const failOnCheckError = standardsFail === "true";

Expand Down Expand Up @@ -76,7 +77,16 @@ export async function runAction(
return 1;
}

const comparisonRun = await diffAll(opticToken, from, additionalArgs);
const headTag: string | undefined = refName
? `gitbranch:${refName}`
: undefined;

const comparisonRun = await diffAll(
opticToken,
from,
additionalArgs,
headTag
);

if (eventName === "pull_request") {
const commentResult = await prComment(
Expand Down Expand Up @@ -167,7 +177,8 @@ async function deepen(): Promise<boolean> {
async function diffAll(
token: string,
from: string,
additionalArgs: string | undefined
additionalArgs: string | undefined,
headTag: string | undefined
): Promise<boolean> {
core.info("Running Optic diff-all");

Expand All @@ -179,6 +190,7 @@ async function diffAll(
from,
"--check",
"--upload",
...(headTag ? ["--head-tag", headTag] : []),
...(additionalArgs ? [additionalArgs] : []),
],
{
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const additionalArgs = core.getInput("additional_args");
const eventName = process.env.GITHUB_EVENT_NAME;
const headRef = process.env.GITHUB_REF;
const baseRef = process.env.GITHUB_BASE_REF;
const refName = process.env.GITHUB_REF_NAME;
const owner = process.env.GITHUB_REPOSITORY_OWNER;
const repo = process.env.GITHUB_REPOSITORY?.split("/")[1];
const sha = process.env.GITHUB_SHA;
Expand All @@ -23,7 +24,8 @@ runAction(
baseRef,
owner,
repo,
sha
sha,
refName
)
.then((exitCode) => {
return process.exit(exitCode);
Expand Down