Skip to content

Commit

Permalink
chore(ci): skip spreading if generated/main does not exist (#273)
Browse files Browse the repository at this point in the history
* chore(ci): skip spreading if generated/main does not exist

* chore: update implementation of gitBranchExists
  • Loading branch information
eunjae-lee committed Mar 22, 2022
1 parent 2115992 commit 1cbfb01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions scripts/ci/codegen/cleanGeneratedBranch.ts
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import { run } from '../../common';
import { gitBranchExists, run } from '../../common';

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

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

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

return;
Expand Down
16 changes: 15 additions & 1 deletion scripts/ci/codegen/spreadGeneration.ts
@@ -1,4 +1,11 @@
import { gitCommit, LANGUAGES, run, toAbsolutePath } from '../../common';
/* eslint-disable no-console */
import {
gitBranchExists,
gitCommit,
LANGUAGES,
run,
toAbsolutePath,
} from '../../common';
import { getLanguageFolder } from '../../config';
import {
cloneRepository,
Expand Down Expand Up @@ -41,6 +48,13 @@ async function spreadGeneration(): Promise<void> {
throw new Error('Environment variable `GITHUB_TOKEN` does not exist.');
}

if (!(await gitBranchExists(GENERATED_MAIN_BRANCH))) {
console.log(
`Skiping because the branch \`${GENERATED_MAIN_BRANCH}\` does not exist.`
);
return;
}

const lastCommitMessage = await run(`git log -1 --format="%s"`);
const name = (await run(`git log -1 --format="%an"`)).trim();
const email = (await run(`git log -1 --format="%ae"`)).trim();
Expand Down
4 changes: 4 additions & 0 deletions scripts/common.ts
Expand Up @@ -189,3 +189,7 @@ export async function buildCustomGenerators(verbose: boolean): Promise<void> {
});
spinner.succeed();
}

export async function gitBranchExists(branchName: string): Promise<boolean> {
return Boolean(await run(`git ls-remote --heads origin ${branchName}`));
}

0 comments on commit 1cbfb01

Please sign in to comment.