Skip to content

Commit

Permalink
Merge pull request #812 from chromaui/tom/ap-3635-ignore-single-commi…
Browse files Browse the repository at this point in the history
…t-restriction-in-addon-initiated-builds

Allow running a build on a single commit repo w/ option
  • Loading branch information
tmeasday committed Sep 6, 2023
2 parents a5e8204 + 4bed9fe commit 9bb3918
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 9 additions & 1 deletion node-src/git/getCommitAndBranch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,19 @@ describe('getCommitAndBranch', () => {
expect(info).toMatchObject({ branch: 'master' });
});

it('throws when there is only one commit', async () => {
it('throws when there is only one commit, CI', async () => {
envCi.mockReturnValue({ isCi: true });
hasPreviousCommit.mockResolvedValue(false);
await expect(getCommitAndBranch({ log })).rejects.toThrow('Found only one commit');
});

it('does NOT throw when there is only one commit, non-CI', async () => {
envCi.mockReturnValue({ isCi: false });
hasPreviousCommit.mockResolvedValue(false);
const info = await getCommitAndBranch({ log });
expect(info).toMatchObject({});
});

describe('with branchName', () => {
it('uses provided branchName as branch', async () => {
const info = await getCommitAndBranch({ log }, { branchName: 'foobar' });
Expand Down
9 changes: 7 additions & 2 deletions node-src/git/getCommitAndBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ export default async function getCommitAndBranch(
CHROMATIC_PULL_REQUEST_SHA,
CHROMATIC_SLUG,
} = process.env;
const { isCi, service, prBranch, branch: ciBranch, commit: ciCommit, slug: ciSlug } = envCi();

const isFromEnvVariable = CHROMATIC_SHA && CHROMATIC_BRANCH; // Our GitHub Action also sets these
const isTravisPrBuild = TRAVIS_EVENT_TYPE === 'pull_request';
const isGitHubAction = GITHUB_ACTIONS === 'true';
const isGitHubPrBuild = GITHUB_EVENT_NAME === 'pull_request';

if (!(await hasPreviousCommit())) {
throw new Error(gitOneCommit(isGitHubAction));
const message = gitOneCommit(isGitHubAction);
if (isCi) {
throw new Error(message);
} else {
log.warn(message);
}
}

if (isFromEnvVariable) {
Expand Down Expand Up @@ -117,7 +123,6 @@ export default async function getCommitAndBranch(
slug = GITHUB_REPOSITORY;
}

const { isCi, service, prBranch, branch: ciBranch, commit: ciCommit, slug: ciSlug } = envCi();
const ciService = process.env.CHROMATIC_ACTION ? 'chromaui/action' : service;
slug = slug || ciSlug;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromatic",
"version": "7.0.0",
"version": "7.1.0-canary.4",
"description": "Automate visual testing across browsers. Gather UI feedback. Versioned documentation.",
"keywords": [
"storybook-addon",
Expand Down

0 comments on commit 9bb3918

Please sign in to comment.