diff --git a/scripts/ci/codegen/pushGeneratedCode.ts b/scripts/ci/codegen/pushGeneratedCode.ts index 13935b6860..24b58d030c 100644 --- a/scripts/ci/codegen/pushGeneratedCode.ts +++ b/scripts/ci/codegen/pushGeneratedCode.ts @@ -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 { + 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. */ @@ -50,6 +55,13 @@ export async function pushGeneratedCode(): Promise { 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]' : ''}