Skip to content

Commit 265b3cb

Browse files
authored
fix(script): no branch change on codegen (#431)
1 parent 554bc2b commit 265b3cb

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

scripts/ci/codegen/__tests__/codegen.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('codegen', () => {
3333
// @ts-expect-error a parameter is required
3434
upsertGenerationComment()
3535
).rejects.toThrow(
36-
'`upsertGenerationComment` requires a `trigger` parameter (`codegen` | `notification`).'
36+
"'upsertGenerationComment' requires a 'trigger' parameter (notification | codegen | noGen | cleanup)."
3737
);
3838
});
3939

scripts/ci/codegen/pushGeneratedCode.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Co-authored-by: %an <%ae>
8080
await run(`git push origin ${branchToPush}`);
8181

8282
if (PR_NUMBER) {
83-
await run(`git checkout ${baseBranch}`);
8483
await run(`yarn workspace scripts upsertGenerationComment codegen`);
8584
}
8685
}

scripts/ci/codegen/upsertGenerationComment.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const allowedTriggers = ['notification', 'codegen', 'noGen', 'cleanup'];
1414
type Trigger = keyof typeof commentText;
1515

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

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

30-
const generatedBranch = `generated/${baseBranch}`;
3133
const generatedCommit = await run(
3234
`git show ${generatedBranch} -s --format=%H`
3335
);
@@ -48,7 +50,9 @@ ${commentText.codegen.body(
4850
export async function upsertGenerationComment(trigger: Trigger): Promise<void> {
4951
if (!trigger || allowedTriggers.includes(trigger) === false) {
5052
throw new Error(
51-
'`upsertGenerationComment` requires a `trigger` parameter (`codegen` | `notification`).'
53+
`'upsertGenerationComment' requires a 'trigger' parameter (${allowedTriggers.join(
54+
' | '
55+
)}).`
5256
);
5357
}
5458

0 commit comments

Comments
 (0)