From ce7ffe98851e8bab5f6ce366c6fde7ebca805511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Herv=C3=A9?= Date: Thu, 8 Jun 2023 15:06:00 +0200 Subject: [PATCH 1/4] make optic token optional, only upload when token is set --- src/action.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/action.ts b/src/action.ts index f190f80..33ca968 100644 --- a/src/action.ts +++ b/src/action.ts @@ -20,7 +20,7 @@ async function execCommand( } export async function runAction( - opticToken: string, + opticToken: string | undefined, githubToken: string, { additionalArgs, @@ -50,7 +50,7 @@ export async function runAction( ): Promise { const failOnCheckError = standardsFail === "true"; - const valid = verifyInput(opticToken, eventName, owner, repo); + const valid = verifyInput(eventName, owner, repo); if (!valid) { return 1; } @@ -129,18 +129,10 @@ export async function runAction( } function verifyInput( - token: string, eventName: string | undefined, owner: string | undefined, repo: string | undefined ): boolean { - if (!token) { - core.error( - "No token was provided. You can generate a token through our app at https://app.useoptic.com" - ); - return false; - } - if (eventName !== "push" && eventName !== "pull_request") { core.error("Only 'push' and 'pull_request' events are supported."); return false; @@ -196,7 +188,7 @@ async function parseAndEnsureRef(ref: string): Promise { } async function diffAll( - token: string, + token: string | undefined, from: string, additionalArgs: string | undefined, headTag: string | undefined @@ -210,14 +202,14 @@ async function diffAll( "--compare-from", from, "--check", - "--upload", + ...(token ? ["--upload"] : []), ...(headTag ? ["--head-tag", headTag] : []), ...(additionalArgs ? [...additionalArgs.split(" ")] : []), ], { env: { ...process.env, - OPTIC_TOKEN: token, + ...(token ? { OPTIC_TOKEN: token }: {}), }, }, false From 2fb143eedc85059b370250aecf908c62dc6628aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Herv=C3=A9?= Date: Thu, 8 Jun 2023 16:25:25 +0200 Subject: [PATCH 2/4] prettier format and add empty config --- package.json | 3 ++- src/action.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 39822c8..d22d972 100644 --- a/package.json +++ b/package.json @@ -46,5 +46,6 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1" - } + }, + "prettier": {} } diff --git a/src/action.ts b/src/action.ts index 33ca968..bccee3a 100644 --- a/src/action.ts +++ b/src/action.ts @@ -209,7 +209,7 @@ async function diffAll( { env: { ...process.env, - ...(token ? { OPTIC_TOKEN: token }: {}), + ...(token ? { OPTIC_TOKEN: token } : {}), }, }, false From a6544111821c35c4419f39e3e30ac01795e455f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Herv=C3=A9?= Date: Thu, 8 Jun 2023 16:27:38 +0200 Subject: [PATCH 3/4] update action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index fc328ab..5f31d32 100644 --- a/action.yml +++ b/action.yml @@ -2,8 +2,8 @@ name: "Optic" description: "Run Optic against the current commit" inputs: optic_token: - description: "Your organization's Optic token" - required: true + description: "Your organization's Optic token to use Optic cloud" + required: false github_token: description: "A GitHub token that can append comments to a PR" required: true From 244d557966a3efbf58eec2339695b4cb038c9735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Herv=C3=A9?= Date: Thu, 8 Jun 2023 16:30:47 +0200 Subject: [PATCH 4/4] build --- build/index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/build/index.js b/build/index.js index c546c21..b9475fd 100644 --- a/build/index.js +++ b/build/index.js @@ -4001,7 +4001,7 @@ async function execCommand(command, args, options = {}, logError = true) { } async function runAction(opticToken, githubToken, { additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName, compareFromPush, compareFromPr, }) { const failOnCheckError = standardsFail === "true"; - const valid = verifyInput(opticToken, eventName, owner, repo); + const valid = verifyInput(eventName, owner, repo); if (!valid) { return 1; } @@ -4057,11 +4057,7 @@ async function runAction(opticToken, githubToken, { additionalArgs, standardsFai return 0; } exports.runAction = runAction; -function verifyInput(token, eventName, owner, repo) { - if (!token) { - core.error("No token was provided. You can generate a token through our app at https://app.useoptic.com"); - return false; - } +function verifyInput(eventName, owner, repo) { if (eventName !== "push" && eventName !== "pull_request") { core.error("Only 'push' and 'pull_request' events are supported."); return false; @@ -4115,11 +4111,11 @@ async function diffAll(token, from, additionalArgs, headTag) { "--compare-from", from, "--check", - "--upload", + ...(token ? ["--upload"] : []), ...(headTag ? ["--head-tag", headTag] : []), ...(additionalArgs ? [...additionalArgs.split(" ")] : []), ], { - env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }), + env: Object.assign(Object.assign({}, process.env), (token ? { OPTIC_TOKEN: token } : {})), }, false); } async function prComment(githubToken, owner, repo, pr, sha) {