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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
description: "Fail the action if a standard fails"
required: false
default: "true"
additional_args:
description: "Additional arguments to pass into `diff-all`"
required: false
runs:
using: "node16"
main: "build/index.js"
18 changes: 13 additions & 5 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, standardsFail, eventName, headRef, baseRef, owner, repo, sha) {
async function runAction(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha) {
const failOnCheckError = standardsFail === "true";
const valid = verifyInput(opticToken, eventName, owner, repo);
if (!valid) {
Expand Down Expand Up @@ -4038,7 +4038,7 @@ async function runAction(opticToken, githubToken, standardsFail, eventName, head
core.error("Unable to determine base for comparison.");
return 1;
}
const comparisonRun = await diffAll(opticToken, from);
const comparisonRun = await diffAll(opticToken, from, additionalArgs);
if (eventName === "pull_request") {
const commentResult = await prComment(githubToken, owner || "", repo || "", pr || "", sha || "");
if (!commentResult) {
Expand Down Expand Up @@ -4096,9 +4096,16 @@ async function deepen() {
}
return true;
}
async function diffAll(token, from) {
async function diffAll(token, from, additionalArgs) {
core.info("Running Optic diff-all");
return execCommand("optic", ["diff-all", "--compare-from", from, "--check", "--upload"], {
return execCommand("optic", [
"diff-all",
"--compare-from",
from,
"--check",
"--upload",
...(additionalArgs ? [additionalArgs] : []),
], {
env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }),
}, false);
}
Expand Down Expand Up @@ -4160,13 +4167,14 @@ const action_1 = __nccwpck_require__(672);
const opticToken = core.getInput("optic_token");
const githubToken = core.getInput("github_token");
const standardsFail = core.getInput("standards_fail");
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 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, standardsFail, eventName, headRef, baseRef, owner, repo, sha)
(0, action_1.runAction)(opticToken, githubToken, additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha)
.then((exitCode) => {
return process.exit(exitCode);
})
Expand Down
47 changes: 45 additions & 2 deletions src/__tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test("invalid input", async () => {
const exitCode = await runAction(
"optic-token",
"github-token",
"",
"true",
"",
"",
Expand All @@ -24,6 +25,7 @@ test("failed install", async () => {
const exitCode = await runAction(
"optic-token",
"github-token",
"",
"true",
"push",
"refs/heads/main",
Expand All @@ -45,6 +47,7 @@ test("pull_request event", async () => {
const exitCode = await runAction(
"optic-token",
"github-token",
"",
"true",
"pull_request",
"refs/pulls/1/merge",
Expand All @@ -68,6 +71,32 @@ test("push event", async () => {
const exitCode = await runAction(
"optic-token",
"github-token",
"",
"true",
"push",
"refs/heads/main",
undefined,
"owner",
"repo",
"abc123"
);
expect(exitCode).toBe(0);
assertInstall();
assertDeepen();
assertDiffAll();
});

test("push event with additional-args", async () => {
const assertInstall = mockInstall();
const assertDeepen = mockDeepen();
const assertDiffAll = mockDiffAll("optic-token", "HEAD~1", false, [
"--fail-on-untracked-openapi",
]);

const exitCode = await runAction(
"optic-token",
"github-token",
"--fail-on-untracked-openapi",
"true",
"push",
"refs/heads/main",
Expand All @@ -90,6 +119,7 @@ test("push event with standards failure and standards_fail set to true", async (
const exitCode = await runAction(
"optic-token",
"github-token",
"",
"true",
"push",
"refs/heads/main",
Expand All @@ -112,6 +142,7 @@ test("push event with standards failure but standards_fail set to false", async
const exitCode = await runAction(
"optic-token",
"github-token",
"",
"false",
"push",
"refs/heads/main",
Expand Down Expand Up @@ -167,7 +198,12 @@ function mockDeepen(): () => void {
);
}

function mockDiffAll(token: string, from: string, error = false): () => void {
function mockDiffAll(
token: string,
from: string,
error = false,
additionalArgs: string[] = []
): () => void {
if (error) {
jest.mocked(exec.exec).mockRejectedValue(new Error("Something broke"));
} else {
Expand All @@ -177,7 +213,14 @@ function mockDiffAll(token: string, from: string, error = false): () => void {
return () =>
expect(jest.mocked(exec.exec)).toHaveBeenCalledWith(
"optic",
["diff-all", "--compare-from", from, "--check", "--upload"],
[
"diff-all",
"--compare-from",
from,
"--check",
"--upload",
...additionalArgs,
],
expect.objectContaining({
env: expect.objectContaining({ OPTIC_TOKEN: "optic-token" }),
})
Expand Down
18 changes: 15 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function execCommand(
export async function runAction(
opticToken: string,
githubToken: string,
additionalArgs: string | undefined,
standardsFail: string,
eventName: string | undefined,
headRef: string | undefined,
Expand Down Expand Up @@ -75,7 +76,7 @@ export async function runAction(
return 1;
}

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

if (eventName === "pull_request") {
const commentResult = await prComment(
Expand Down Expand Up @@ -163,12 +164,23 @@ async function deepen(): Promise<boolean> {
return true;
}

async function diffAll(token: string, from: string): Promise<boolean> {
async function diffAll(
token: string,
from: string,
additionalArgs: string | undefined
): Promise<boolean> {
core.info("Running Optic diff-all");

return execCommand(
"optic",
["diff-all", "--compare-from", from, "--check", "--upload"],
[
"diff-all",
"--compare-from",
from,
"--check",
"--upload",
...(additionalArgs ? [additionalArgs] : []),
],
{
env: {
...process.env,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { runAction } from "./action";
const opticToken = core.getInput("optic_token");
const githubToken = core.getInput("github_token");
const standardsFail = core.getInput("standards_fail");
const additionalArgs = core.getInput("additional_args");

const eventName = process.env.GITHUB_EVENT_NAME;
const headRef = process.env.GITHUB_REF;
Expand All @@ -15,6 +16,7 @@ const sha = process.env.GITHUB_SHA;
runAction(
opticToken,
githubToken,
additionalArgs,
standardsFail,
eventName,
headRef,
Expand Down