Skip to content

Commit

Permalink
Merge pull request #44 from gsoft-inc/fix/custom_default_branch
Browse files Browse the repository at this point in the history
fix: Default branch baseline was not updated properly when a custom d…
  • Loading branch information
patricklafrance authored Feb 7, 2025
2 parents 66c7511 + a142283 commit e898a93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-tables-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workleap/chromado": patch
---

Default branch baseline was not updated properly when a custom default branch was provided.
8 changes: 4 additions & 4 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ async function run() {
argv.push("--only-changed");
}

// 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";

// 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";
const isAutoAcceptingChangesOnMainBranch = getVariable("Build.Reason") !== "PullRequest" && getVariable("Build.SourceBranch") === `refs/heads/${defaultBranch}`;

if (isAutoAcceptingChangesOnMainBranch) {
// 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);
}
Expand Down

0 comments on commit e898a93

Please sign in to comment.