Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Prioritize git SHA instead of GH actions env var #175

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/cli/src/config/getCiSettings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ProvisionalConfig } from './types';

type EnvObject = Record<string, string>;

type DetectionFn = (env: EnvObject) => boolean;
Expand All @@ -11,7 +13,7 @@ export type CiEnvironment = {
name: string;
readableName: string;
check: DetectionFn;
getSettings: (env: EnvObject) => CiSettings;
getSettings: (env: EnvObject, provisionalConfig: ProvisionalConfig) => CiSettings;
};

const FALLBACK_CI: CiEnvironment = {
Expand Down Expand Up @@ -55,8 +57,8 @@ const CI_ENVIRONMENTS: CiEnvironment[] = [
name: 'github_actions',
readableName: 'GitHub Actions',
check: env => !!env.GITHUB_ACTION && !!env.GITHUB_REPOSITORY,
getSettings: env => ({
commit: env.GITHUB_SHA,
getSettings: (env, provisionalConfig) => ({
commit: provisionalConfig.commit || env.GITHUB_SHA,
ci: true,
}),
},
Expand Down Expand Up @@ -89,9 +91,9 @@ const CI_ENVIRONMENTS: CiEnvironment[] = [
];

export default function getCiSettingsFactory(env) {
return () => {
return (provisionalConfig: ProvisionalConfig) => {
const environment: CiEnvironment =
CI_ENVIRONMENTS.find(({ check }) => check(env)) || FALLBACK_CI;
return environment.getSettings(env);
return environment.getSettings(env, provisionalConfig);
};
}
17 changes: 11 additions & 6 deletions packages/cli/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { normaliseConfig } from './normaliseConfig';

import { getGitSettings } from './getGitSettings';
import { loadConfigFile } from './loadConfigFile';
import { Config, BaseConfig } from './types';
import { Config, BaseConfig, ProvisionalConfig } from './types';
import { getConfigFromStorybook } from '../storybook/getConfigFromStorybook';

export * from './types';
Expand Down Expand Up @@ -35,13 +35,18 @@ export const getConfig: (customConfig: Partial<BaseConfig>) => Promise<Config> =
configFilePrio: CONFIG_FILE_PRIO,
fs,
});

const provisionalConfig: ProvisionalConfig = {
...(await getGitSettings(configFile.executionPath || defaultConfig.executionPath)),
...defaultConfig,
...getConfigFromStorybook(),
...configFile,
};

return normaliseConfig(
{
...(await getGitSettings(configFile.executionPath || defaultConfig.executionPath)),
...defaultConfig,
...getConfigFromStorybook(),
...configFile,
...getCiSettings(),
...provisionalConfig,
...getCiSettings(provisionalConfig),
...customConfig,
},
configFileDirectory
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type BaseConfig = {
previewDownloadUrl: string;
};

export type ProvisionalConfig = BaseConfig & {
commit?: string;
};

export type Config = CiSettings &
Omit<BaseConfig, 'webpackConfig' | 'storyPath' | 'storyPathIgnorePatterns'> & {
storyPath: string[];
Expand Down