Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed Apr 9, 2024
1 parent b942edc commit a400fac
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { getVariable, setResult, TaskResult } from "azure-pipelines-task-lib";
import { run as chromatic } from "chromatic/node";
import { postThread } from "./helpers.ts";

function isInvalidBuild(output: Awaited<ReturnType<typeof chromatic>>) {
return output.url === undefined && output.storybookUrl === undefined;
}

function validateArgs(args: string[]) {
if (args.find(x => x.includes("--only-changed"))) {
throw new Error("To enable Turbosnap, set the CHROMATIC_ENABLE_TURBOSNAP environment variable to true.");
Expand All @@ -34,12 +30,12 @@ async function run() {
argv.push("--only-changed");
}

const shouldAutoAcceptChanges = getVariable("Build.Reason") !== "PullRequest" && getVariable("Build.SourceBranch") === "refs/heads/main";

// Accepting the baseline automatically when Chromatic is executed on the "main" branch.
// Running Chromatic on the "main" branch allow us to use "squash" merge for PRs, see: https://www.chromatic.com/docs/custom-ci-provider/#squashrebase-merge-and-the-main-branch.
// Furthermore, changes from PR doesn't seem to be updating the baseline at all but I don't know why, it seems like a bug with ADO.
if (shouldAutoAcceptChanges) {
const isAutoAcceptChanges = getVariable("Build.Reason") !== "PullRequest" && getVariable("Build.SourceBranch") === "refs/heads/main";

if (isAutoAcceptChanges) {
argv.push("--auto-accept-changes", "main");
}

Expand All @@ -52,7 +48,8 @@ async function run() {

const output = await chromatic({ argv });

if (isInvalidBuild(output)) {
// This is an invalid build.
if (output.url === undefined && output.storybookUrl === undefined) {
// For error codes view: https://www.chromatic.com/docs/cli/#exit-codes.
if (output.code !== 0) {
setResult(TaskResult.Failed, `Chromatic exited with code "${output.code}".`);
Expand All @@ -61,8 +58,8 @@ async function run() {
return;
}

if (shouldAutoAcceptChanges) {
setResult(TaskResult.Succeeded, `${output.changeCount} has been automatically accepted.`);
if (isAutoAcceptChanges) {
setResult(TaskResult.Succeeded, `${output.changeCount} changes has been automatically accepted.`);
}

const comment = `
Expand Down

0 comments on commit a400fac

Please sign in to comment.