Skip to content

Commit

Permalink
chore(ci): stop CI from push generated code when no up to date (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Apr 25, 2022
1 parent aedf57f commit ec4561f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/ci/codegen/pushGeneratedCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import text from './text';
const PR_NUMBER = parseInt(process.env.PR_NUMBER || '0', 10);
const FOLDERS_TO_CHECK = 'yarn.lock openapitools.json clients specs/bundled';

async function isUpToDate(): Promise<boolean> {
await run('git fetch origin');
return (await run('git status')).includes('Your branch is up to date with');
}

/**
* Push generated code for the current `JOB` and `CLIENT` on a `generated/` branch.
*/
Expand Down Expand Up @@ -50,6 +55,13 @@ export async function pushGeneratedCode(): Promise<void> {
await run(`git checkout -b ${branchToPush}`);
}

if (!(await isUpToDate())) {
console.log(
`The branch ${branchToPush} is not up to date with ${baseBranch}, stopping this task and letting the new job push generated code.`
);
return;
}

const commitMessage = await run(`git show -s ${baseBranch} --format="${
text.commitStartMessage
} %H. ${isMainBranch ? '[skip ci]' : ''}
Expand Down

0 comments on commit ec4561f

Please sign in to comment.