From 64d7980ceb4f91d46262b48d5b0bfecfbbf2d068 Mon Sep 17 00:00:00 2001 From: Nicholas Lim <18374483+niclim@users.noreply.github.com> Date: Thu, 9 Mar 2023 15:10:37 -0500 Subject: [PATCH 1/2] Update github action to set tag --- build/index.js | 11 +++++++---- src/__tests__/action.test.ts | 23 ++++++++++++++++------- src/action.ts | 11 ++++++++--- src/index.ts | 4 +++- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/build/index.js b/build/index.js index b0444fe..7e88717 100644 --- a/build/index.js +++ b/build/index.js @@ -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) { @@ -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 tag = refName ? `gitbranch:${refName}` : undefined; + const comparisonRun = await diffAll(opticToken, from, additionalArgs, tag); if (eventName === "pull_request") { const commentResult = await prComment(githubToken, owner || "", repo || "", pr || "", sha || ""); if (!commentResult) { @@ -4096,7 +4097,7 @@ async function deepen() { } return true; } -async function diffAll(token, from, additionalArgs) { +async function diffAll(token, from, additionalArgs, tag) { core.info("Running Optic diff-all"); return execCommand("optic", [ "diff-all", @@ -4104,6 +4105,7 @@ async function diffAll(token, from, additionalArgs) { from, "--check", "--upload", + ...(tag ? ["--tag", tag] : []), ...(additionalArgs ? [additionalArgs] : []), ], { env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }), @@ -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); }) diff --git a/src/__tests__/action.test.ts b/src/__tests__/action.test.ts index b548d46..6708717 100644 --- a/src/__tests__/action.test.ts +++ b/src/__tests__/action.test.ts @@ -14,7 +14,8 @@ test("invalid input", async () => { undefined, "owner", "repo", - "abc123" + "abc123", + "" ); expect(exitCode).toBe(1); }); @@ -32,7 +33,8 @@ test("failed install", async () => { undefined, "owner", "repo", - "abc123" + "abc123", + "main" ); expect(exitCode).toBe(1); assertFailedInstall(); @@ -54,7 +56,8 @@ test("pull_request event", async () => { "main", "owner", "repo", - "abc123" + "abc123", + "main" ); expect(exitCode).toBe(0); assertInstall(); @@ -78,7 +81,8 @@ test("push event", async () => { undefined, "owner", "repo", - "abc123" + "abc123", + "main" ); expect(exitCode).toBe(0); assertInstall(); @@ -103,7 +107,8 @@ test("push event with additional-args", async () => { undefined, "owner", "repo", - "abc123" + "abc123", + "main" ); expect(exitCode).toBe(0); assertInstall(); @@ -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(); @@ -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(); @@ -219,6 +226,8 @@ function mockDiffAll( from, "--check", "--upload", + "--tag", + "gitbranch:main", ...additionalArgs, ], expect.objectContaining({ diff --git a/src/action.ts b/src/action.ts index 7efbf5a..dcf56c7 100644 --- a/src/action.ts +++ b/src/action.ts @@ -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 { const failOnCheckError = standardsFail === "true"; @@ -76,7 +77,9 @@ export async function runAction( return 1; } - const comparisonRun = await diffAll(opticToken, from, additionalArgs); + const tag: string | undefined = refName ? `gitbranch:${refName}` : undefined; + + const comparisonRun = await diffAll(opticToken, from, additionalArgs, tag); if (eventName === "pull_request") { const commentResult = await prComment( @@ -167,7 +170,8 @@ async function deepen(): Promise { async function diffAll( token: string, from: string, - additionalArgs: string | undefined + additionalArgs: string | undefined, + tag: string | undefined ): Promise { core.info("Running Optic diff-all"); @@ -179,6 +183,7 @@ async function diffAll( from, "--check", "--upload", + ...(tag ? ["--tag", tag] : []), ...(additionalArgs ? [additionalArgs] : []), ], { diff --git a/src/index.ts b/src/index.ts index 31a72a1..a485629 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; @@ -23,7 +24,8 @@ runAction( baseRef, owner, repo, - sha + sha, + refName ) .then((exitCode) => { return process.exit(exitCode); From 701114c67420959f20b7dcb6e88f3da41e3b9d19 Mon Sep 17 00:00:00 2001 From: Nicholas Lim <18374483+niclim@users.noreply.github.com> Date: Fri, 10 Mar 2023 08:51:05 -0500 Subject: [PATCH 2/2] tag -> head-tag --- build/index.js | 8 ++++---- src/__tests__/action.test.ts | 2 +- src/action.ts | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/build/index.js b/build/index.js index 7e88717..313d80b 100644 --- a/build/index.js +++ b/build/index.js @@ -4038,8 +4038,8 @@ async function runAction(opticToken, githubToken, additionalArgs, standardsFail, core.error("Unable to determine base for comparison."); return 1; } - const tag = refName ? `gitbranch:${refName}` : undefined; - const comparisonRun = await diffAll(opticToken, from, additionalArgs, tag); + 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) { @@ -4097,7 +4097,7 @@ async function deepen() { } return true; } -async function diffAll(token, from, additionalArgs, tag) { +async function diffAll(token, from, additionalArgs, headTag) { core.info("Running Optic diff-all"); return execCommand("optic", [ "diff-all", @@ -4105,7 +4105,7 @@ async function diffAll(token, from, additionalArgs, tag) { from, "--check", "--upload", - ...(tag ? ["--tag", tag] : []), + ...(headTag ? ["--head-tag", headTag] : []), ...(additionalArgs ? [additionalArgs] : []), ], { env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }), diff --git a/src/__tests__/action.test.ts b/src/__tests__/action.test.ts index 6708717..0471d36 100644 --- a/src/__tests__/action.test.ts +++ b/src/__tests__/action.test.ts @@ -226,7 +226,7 @@ function mockDiffAll( from, "--check", "--upload", - "--tag", + "--head-tag", "gitbranch:main", ...additionalArgs, ], diff --git a/src/action.ts b/src/action.ts index dcf56c7..5595cd4 100644 --- a/src/action.ts +++ b/src/action.ts @@ -77,9 +77,16 @@ export async function runAction( return 1; } - const tag: string | undefined = refName ? `gitbranch:${refName}` : undefined; - - const comparisonRun = await diffAll(opticToken, from, additionalArgs, tag); + const headTag: string | undefined = refName + ? `gitbranch:${refName}` + : undefined; + + const comparisonRun = await diffAll( + opticToken, + from, + additionalArgs, + headTag + ); if (eventName === "pull_request") { const commentResult = await prComment( @@ -171,7 +178,7 @@ async function diffAll( token: string, from: string, additionalArgs: string | undefined, - tag: string | undefined + headTag: string | undefined ): Promise { core.info("Running Optic diff-all"); @@ -183,7 +190,7 @@ async function diffAll( from, "--check", "--upload", - ...(tag ? ["--tag", tag] : []), + ...(headTag ? ["--head-tag", headTag] : []), ...(additionalArgs ? [additionalArgs] : []), ], {