Skip to content

Commit

Permalink
Added a new CHROMATIC_DEFAULT_BRANCH option
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed Feb 5, 2025
1 parent 772514a commit d2b21a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-moose-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workleap/chromado": minor
---

Added a new CHROMATIC_DEFAULT_BRANCH option to configure the name of the repository default branch.
15 changes: 15 additions & 0 deletions docs/available-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,18 @@ Add the `CHROMATIC_DISABLE_TURBOSNAP` environment variable to your `chromatic.ym
!!!info
We strongly encourage using TurboSnap as Chromatic snapshots are not cheap.
!!!

## CHROMATIC_DEFAULT_BRANCH

If your repository default branch is not `main`, using this option to provide the name of your repository default branch:

```yaml !#8 chromatic.yml
- task: CmdLine@2
displayName: Chromatic
inputs:
script: pnpm dlx @workleap/chromado
env:
CHROMATIC_PROJECT_TOKEN: $(CHROMATIC_PROJECT_TOKEN)
CHROMATIC_PULL_REQUEST_COMMENT_ACCESS_TOKEN: $(PULL_REQUEST_COMMENT_ACCESS_TOKEN)
CHROMATIC_DEFAULT_BRANCH: master
```
11 changes: 7 additions & 4 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ async function run() {
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.
// Accepting the baseline automatically when Chromatic is executed on the default branch.
// Running Chromatic on the default 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 (but according to Chromatic customers support it's normal).
const isAutoAcceptingChangesOnMainBranch = getVariable("Build.Reason") !== "PullRequest" && getVariable("Build.SourceBranch") === "refs/heads/main";

if (isAutoAcceptingChangesOnMainBranch) {
// The second arg restrict the changes to be auto accepted only for the "main" branch.
argv.push("--auto-accept-changes", "main");
// Defaults to "main" but is configurable becase we have a few repos still using "master" as de the default branch.
const defaultBranch = getVariable("CHROMATIC_DEFAULT_BRANCH") ?? "main";

// The second arg restrict the changes to be auto accepted only for the default branch.
argv.push("--auto-accept-changes", defaultBranch);
}

// Add default branch paths to ignore.
Expand Down

0 comments on commit d2b21a2

Please sign in to comment.