Skip to content

Commit bff17e0

Browse files
authored
chore(ci): skip spreading if generated/main does not exist (#273)
* chore(ci): skip spreading if generated/main does not exist * chore: update implementation of gitBranchExists
1 parent ca7021c commit bff17e0

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

scripts/ci/codegen/cleanGeneratedBranch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { run } from '../../common';
2+
import { gitBranchExists, run } from '../../common';
33

44
/**
55
* Deletes a branch for its `generated/${headRef}` name on origin.
@@ -13,7 +13,7 @@ export async function cleanGeneratedBranch(headRef: string): Promise<void> {
1313

1414
const generatedCodeBranch = `generated/${headRef}`;
1515

16-
if (!(await run(`git ls-remote --heads origin ${generatedCodeBranch}`))) {
16+
if (!(await gitBranchExists(generatedCodeBranch))) {
1717
console.log(`No branch named '${generatedCodeBranch}' was found.`);
1818

1919
return;

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { gitCommit, LANGUAGES, run, toAbsolutePath } from '../../common';
1+
/* eslint-disable no-console */
2+
import {
3+
gitBranchExists,
4+
gitCommit,
5+
LANGUAGES,
6+
run,
7+
toAbsolutePath,
8+
} from '../../common';
29
import { getLanguageFolder } from '../../config';
310
import {
411
cloneRepository,
@@ -41,6 +48,13 @@ async function spreadGeneration(): Promise<void> {
4148
throw new Error('Environment variable `GITHUB_TOKEN` does not exist.');
4249
}
4350

51+
if (!(await gitBranchExists(GENERATED_MAIN_BRANCH))) {
52+
console.log(
53+
`Skiping because the branch \`${GENERATED_MAIN_BRANCH}\` does not exist.`
54+
);
55+
return;
56+
}
57+
4458
const lastCommitMessage = await run(`git log -1 --format="%s"`);
4559
const name = (await run(`git log -1 --format="%an"`)).trim();
4660
const email = (await run(`git log -1 --format="%ae"`)).trim();

scripts/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,7 @@ export async function buildCustomGenerators(verbose: boolean): Promise<void> {
189189
});
190190
spinner.succeed();
191191
}
192+
193+
export async function gitBranchExists(branchName: string): Promise<boolean> {
194+
return Boolean(await run(`git ls-remote --heads origin ${branchName}`));
195+
}

0 commit comments

Comments
 (0)