Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): stop CI from push generated code when no up to date #421

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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