2021-05-12 06:35:00 +00:00
|
|
|
export interface BuildContext {
|
|
|
|
app?: string | null;
|
|
|
|
channel?: string | null;
|
|
|
|
gitCommit?: string | null;
|
|
|
|
gitRef?: string | null;
|
|
|
|
smokeTest: boolean;
|
|
|
|
version: string | null;
|
2020-08-24 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
const fromGitRef = (): BuildContext => {
|
2020-08-24 20:40:40 +00:00
|
|
|
const {
|
|
|
|
GIT_TAG,
|
|
|
|
GITHUB_REF,
|
|
|
|
GITHUB_SHA,
|
|
|
|
TRAVIS_TAG,
|
|
|
|
TRAVIS_COMMIT,
|
|
|
|
TRAVIS_CURRENT_BRANCH,
|
|
|
|
} = process.env;
|
|
|
|
|
|
|
|
const gitCommit = GITHUB_SHA || TRAVIS_COMMIT;
|
|
|
|
const gitRef = GIT_TAG || GITHUB_REF || TRAVIS_TAG || TRAVIS_CURRENT_BRANCH || '';
|
2021-02-02 23:19:22 +00:00
|
|
|
const tagMatch = gitRef.match(/(core)@(\d{4}\.\d+\.\d+(-(alpha|beta)\.\d+)?)$/);
|
2020-08-24 20:40:40 +00:00
|
|
|
|
2021-03-02 22:41:23 +00:00
|
|
|
const app = tagMatch ? tagMatch[1] : null;
|
2020-08-24 20:40:40 +00:00
|
|
|
const version = tagMatch ? tagMatch[2] : null;
|
|
|
|
const channel = tagMatch ? tagMatch[4] : 'stable';
|
|
|
|
|
|
|
|
return {
|
2021-03-02 22:41:23 +00:00
|
|
|
app,
|
2020-08-24 20:40:40 +00:00
|
|
|
channel,
|
|
|
|
gitCommit,
|
2021-05-12 06:35:00 +00:00
|
|
|
gitRef,
|
|
|
|
smokeTest: false,
|
|
|
|
version,
|
2020-08-24 20:40:40 +00:00
|
|
|
};
|
2021-05-12 06:35:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getBuildContext = (forceFromGitRef: boolean) => {
|
|
|
|
if (forceFromGitRef) {
|
|
|
|
return fromGitRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.SMOKE_TEST) {
|
|
|
|
return {
|
|
|
|
smokeTest: true,
|
|
|
|
version: '0.0.1',
|
|
|
|
} as const;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fromGitRef();
|
|
|
|
};
|