Skip to content

Commit

Permalink
chore: Updated the node script.
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed Apr 9, 2024
1 parent 75811dc commit 7e74634
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-eels-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workleap/chromatic-ado": patch
---

Trying to deprecated the azure devops script.
70 changes: 0 additions & 70 deletions chromatic.yml

This file was deleted.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "wl-chromatic-ado",
"name": "@workleap/chromatic-ado",
"author": "Workleap",
"version": "0.0.4",
"description": "Utilities to use Chromatic with Azure DevOps.",
Expand All @@ -14,9 +14,6 @@
},
"type": "module",
"bin": "./dist/bin.js",
"exports": {
"./chromatic.yml": "./dist/chromatic.yml"
},
"files": [
"dist"
],
Expand Down
23 changes: 0 additions & 23 deletions scripts/chromatic_short.yml

This file was deleted.

40 changes: 20 additions & 20 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@
*/

import { getVariable, setResult, TaskResult } from "azure-pipelines-task-lib";
import { run as runNode } from "chromatic/node";
import { run as chromatic } from "chromatic/node";
import { postThread } from "./helpers.ts";

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

async function run() {
try {
const commitHash = getVariable("Build.SourceVersion");

// Accept additional CLI arguments.
const output = await runNode({ argv: process.argv.slice(2) });
const argv: string[] = process.argv.slice(2);

console.log("*****************************: ", argv, JSON.stringify(argv));

// TEMP
argv.push("--only-changed");

// 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 (getVariable("Build.Reason") !== "PullRequest" && getVariable("Build.SourceBranch") === "refs/heads/main") {
argv.push("--auto-accept-changes main");
}

const output = await chromatic({ argv });

if (isSkippedOrOutputIsInvalid(output)) {
if (output.code !== 0) {
setResult(
TaskResult.Failed,
`Chromatic exited with code '${output.code}'.`
);
setResult(TaskResult.Failed, `Chromatic exited with code "${output.code}".`);
}

return;
Expand All @@ -41,7 +48,7 @@ async function run() {
<tbody>
<tr>
<td><b>Latest commit:</b></td>
<td><code>${commitHash}</code></td>
<td><code>${getVariable("Build.SourceVersion")}</code></td>
</tr>
<tr>
<td><b>Errors:</b></td>
Expand Down Expand Up @@ -83,10 +90,7 @@ ${output.changeCount === 0
});

if (output.errorCount > 0) {
setResult(
TaskResult.Failed,
`${output.errorCount} ${output.errorCount === 1 ? "test" : "tests"} failed.`
);
setResult(TaskResult.Failed, `${output.errorCount} ${output.errorCount === 1 ? "test" : "tests"} failed.`);
}

if (output.changeCount > 0) {
Expand All @@ -98,12 +102,8 @@ ${output.changeCount === 0
} catch (error) {
if (error instanceof Error) {
setResult(TaskResult.Failed, error.message);

return;
} else {
setResult(TaskResult.Failed, `An unknown error occured: ${error}`);

return;
}
}
}
Expand Down

0 comments on commit 7e74634

Please sign in to comment.