Skip to content

fix(script): no branch change on codegen #431

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

Merged
merged 2 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion scripts/ci/codegen/__tests__/codegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('codegen', () => {
// @ts-expect-error a parameter is required
upsertGenerationComment()
).rejects.toThrow(
'`upsertGenerationComment` requires a `trigger` parameter (`codegen` | `notification`).'
"'upsertGenerationComment' requires a 'trigger' parameter (notification | codegen | noGen | cleanup)."
);
});

Expand Down
1 change: 0 additions & 1 deletion scripts/ci/codegen/pushGeneratedCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Co-authored-by: %an <%ae>
await run(`git push origin ${branchToPush}`);

if (PR_NUMBER) {
await run(`git checkout ${baseBranch}`);
await run(`yarn workspace scripts upsertGenerationComment codegen`);
}
}
Expand Down
10 changes: 7 additions & 3 deletions scripts/ci/codegen/upsertGenerationComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const allowedTriggers = ['notification', 'codegen', 'noGen', 'cleanup'];
type Trigger = keyof typeof commentText;

export async function getCommentBody(trigger: Trigger): Promise<string> {
// All of the case where we are not pushing generated code.
if (
trigger === 'notification' ||
trigger === 'noGen' ||
Expand All @@ -24,10 +25,11 @@ export async function getCommentBody(trigger: Trigger): Promise<string> {
${commentText[trigger].body}`;
}

const baseBranch = await run('git branch --show-current');
// We are on a codegen step on a pull request here
const generatedBranch = await run('git branch --show-current');
const baseBranch = generatedBranch.replace('generated/', '');
const baseCommit = await run(`git show ${baseBranch} -s --format=%H`);

const generatedBranch = `generated/${baseBranch}`;
const generatedCommit = await run(
`git show ${generatedBranch} -s --format=%H`
);
Expand All @@ -48,7 +50,9 @@ ${commentText.codegen.body(
export async function upsertGenerationComment(trigger: Trigger): Promise<void> {
if (!trigger || allowedTriggers.includes(trigger) === false) {
throw new Error(
'`upsertGenerationComment` requires a `trigger` parameter (`codegen` | `notification`).'
`'upsertGenerationComment' requires a 'trigger' parameter (${allowedTriggers.join(
' | '
)}).`
);
}

Expand Down