From 7e746349f719416838589d0ae05ab294206af56a Mon Sep 17 00:00:00 2001 From: patricklafrance Date: Mon, 8 Apr 2024 23:23:42 -0400 Subject: [PATCH] chore: Updated the node script. --- .changeset/cuddly-eels-love.md | 5 +++ chromatic.yml | 70 ---------------------------------- package.json | 5 +-- scripts/chromatic_short.yml | 23 ----------- src/bin.ts | 40 +++++++++---------- 5 files changed, 26 insertions(+), 117 deletions(-) create mode 100644 .changeset/cuddly-eels-love.md delete mode 100644 chromatic.yml delete mode 100644 scripts/chromatic_short.yml diff --git a/.changeset/cuddly-eels-love.md b/.changeset/cuddly-eels-love.md new file mode 100644 index 0000000..b244a2d --- /dev/null +++ b/.changeset/cuddly-eels-love.md @@ -0,0 +1,5 @@ +--- +"@workleap/chromatic-ado": patch +--- + +Trying to deprecated the azure devops script. diff --git a/chromatic.yml b/chromatic.yml deleted file mode 100644 index f10218a..0000000 --- a/chromatic.yml +++ /dev/null @@ -1,70 +0,0 @@ -# Run Chromatic on the main branch after a PR has been merged (currently required to update the baseline when doing "squash" merge for PRs). -trigger: - branches: - include: - - main - -# Run Chromatic on every Pull Request targeting the "main" branch as destination. -pr: - branches: - include: - - main - -variables: - - group: Azure DevOps - -steps: - - task: UseNode@1 - displayName: Use Node.js >=20.0.0 - inputs: - version: ">=20.0.0" - checkLatest: true - - # Chromatic needs the full Git history to compare the baselines. - # Checkout must happen before the setup template. - - checkout: self - displayName: Get full Git history - fetchDepth: 0 - - - task: Cache@2 - displayName: Cache pnpm - inputs: - key: '"pnpm" | "$(Agent.OS)" | pnpm-lock.yaml' - restoreKeys: | - "pnpm" | "$(Agent.OS)" - "pnpm" - path: $(Pipeline.Workspace)/.pnpm-store - - - script: | - corepack enable - corepack prepare pnpm@latest-8 --activate - pnpm config set store-dir $(Pipeline.Workspace)/.pnpm-store - displayName: Setup pnpm - - - task: npmAuthenticate@0 - displayName: Authenticate to private npm feed - inputs: - workingFile: .npmrc - - - script: pnpm install --frozen-lockfile - displayName: pnpm install - - # 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. - - task: CmdLine@2 - displayName: Chromatic (main branch) - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) - inputs: - - script: pnpm dlx chromatic --only-changed --skip renovate/** --auto-accept-changes main - env: - CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN) - - - task: CmdLine@2 - displayName: Chromatic (PR) - condition: eq(variables['Build.Reason'], 'PullRequest') - inputs: - - script: pnpm dlx @workleap/chromatic-ado --only-changed --skip renovate/** - env: - CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN) - PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN) diff --git a/package.json b/package.json index 673a896..974ed57 100644 --- a/package.json +++ b/package.json @@ -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.", @@ -14,9 +14,6 @@ }, "type": "module", "bin": "./dist/bin.js", - "exports": { - "./chromatic.yml": "./dist/chromatic.yml" - }, "files": [ "dist" ], diff --git a/scripts/chromatic_short.yml b/scripts/chromatic_short.yml deleted file mode 100644 index 713397d..0000000 --- a/scripts/chromatic_short.yml +++ /dev/null @@ -1,23 +0,0 @@ -variables: - - group: Azure DevOps - -steps: - # 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. - - task: CmdLine@2 - displayName: Chromatic (main branch) - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) - inputs: - - script: pnpm dlx chromatic --only-changed --skip renovate/** --auto-accept-changes main - env: - CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN) - - - task: CmdLine@2 - displayName: Chromatic (PR) - condition: eq(variables['Build.Reason'], 'PullRequest') - inputs: - - script: pnpm dlx @workleap/chromatic-ado --only-changed --skip renovate/** - env: - CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN) - PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN) diff --git a/src/bin.ts b/src/bin.ts index 06b707f..e35c985 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -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> -) { +function isSkippedOrOutputIsInvalid(output: Awaited>) { 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; @@ -41,7 +48,7 @@ async function run() { Latest commit: - ${commitHash} + ${getVariable("Build.SourceVersion")} Errors: @@ -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) { @@ -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; } } }