Skip to content

Commit a63207f

Browse files
authored
Merge branch 'main' into chore/log
2 parents b25bb55 + 431b986 commit a63207f

File tree

5 files changed

+15
-35
lines changed

5 files changed

+15
-35
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GENERATED_MAIN_BRANCH } from '../../../common';
1+
import { MAIN_BRANCH } from '../../../common';
22
import { cleanGeneratedBranch } from '../cleanGeneratedBranch';
33
import { pushGeneratedCode } from '../pushGeneratedCode';
44
import commentText from '../text';
@@ -67,7 +67,7 @@ describe('codegen', () => {
6767
expect(await getCommentBody('cleanup')).toMatchInlineSnapshot(`
6868
"### ✗ The generated branch has been deleted.
6969
70-
If the PR has been merged, you can check the generated code on the [\`${GENERATED_MAIN_BRANCH}\` branch](https://github.com/algolia/api-clients-automation/tree/${GENERATED_MAIN_BRANCH})."
70+
If the PR has been merged, you can check the generated code on the [\`${MAIN_BRANCH}\` branch](https://github.com/algolia/api-clients-automation/tree/${MAIN_BRANCH})."
7171
`);
7272
});
7373

@@ -85,7 +85,7 @@ describe('codegen', () => {
8585
| Name | Link |
8686
|---------------------------------|------------------------|
8787
| 🔨 Triggered by | [\`myCommit\`](https://github.com/algolia/api-clients-automation/pull/42/commits/myCommit) |
88-
| 🔍 Generated code | [\`theGeneratedCommit\`](https://github.com/algolia/api-clients-automation/compare/generated/main...theGeneratedCommit) |
88+
| 🔍 Generated code | [\`theGeneratedCommit\`](https://github.com/algolia/api-clients-automation/commit/theGeneratedCommit) |
8989
| 🌲 Generated branch | [\`myBranch\`](https://github.com/algolia/api-clients-automation/tree/myBranch) |
9090
"
9191
`);

scripts/ci/codegen/pushGeneratedCode.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { run } from '../../common';
2+
import { MAIN_BRANCH, run } from '../../common';
33
import { configureGitHubAuthor } from '../../release/common';
44
import { getNbGitDiff } from '../utils';
55

@@ -17,10 +17,11 @@ export async function pushGeneratedCode(): Promise<void> {
1717
await configureGitHubAuthor();
1818

1919
const baseBranch = await run('git branch --show-current');
20+
const isMainBranch = baseBranch === MAIN_BRANCH;
2021
console.log(`Checking codegen status on '${baseBranch}'.`);
2122

2223
const nbDiff = await getNbGitDiff({
23-
branch: 'origin/generated/main',
24+
branch: baseBranch,
2425
head: null,
2526
path: FOLDERS_TO_CHECK,
2627
});
@@ -38,22 +39,13 @@ export async function pushGeneratedCode(): Promise<void> {
3839
console.log(`${nbDiff} changes found for ${FOLDERS_TO_CHECK}`);
3940

4041
// determine generated branch name based on current branch
41-
const generatedCodeBranch = `generated/${baseBranch}`;
42+
const branchToPush = isMainBranch ? baseBranch : `generated/${baseBranch}`;
4243

43-
// We don't re-create GENERATED_MAIN_BRANCH
44-
if (baseBranch !== 'main') {
44+
if (!isMainBranch) {
4545
await run(`yarn workspace scripts cleanGeneratedBranch ${baseBranch}`);
4646

47-
console.log(`Creating branch for generated code: '${generatedCodeBranch}'`);
48-
await run(`git branch ${generatedCodeBranch}`);
49-
}
50-
51-
await run(`git checkout ${generatedCodeBranch}`);
52-
53-
// For the GENERATED_MAIN_BRANCH, we take the latest commit on main and generate code
54-
if (baseBranch === 'main') {
55-
console.log(`Merging '${baseBranch}' in '${generatedCodeBranch}'`);
56-
await run(`git merge --no-commit ${baseBranch}`);
47+
console.log(`Creating branch for generated code: '${branchToPush}'`);
48+
await run(`git checkout -b ${branchToPush}`);
5749
}
5850

5951
const commitMessage =
@@ -62,11 +54,11 @@ export async function pushGeneratedCode(): Promise<void> {
6254
Co-authored-by: %an <%ae>"`);
6355

6456
console.log(
65-
`Pushing code for folders '${FOLDERS_TO_CHECK}' to generated branch: '${generatedCodeBranch}'`
57+
`Pushing code for folders '${FOLDERS_TO_CHECK}' to generated branch: '${branchToPush}'`
6658
);
6759
await run(`git add ${FOLDERS_TO_CHECK}`);
6860
await run(`git commit -m "${commitMessage}"`);
69-
await run(`git push origin ${generatedCodeBranch}`);
61+
await run(`git push origin ${branchToPush}`);
7062

7163
if (PR_NUMBER) {
7264
await run(`git checkout ${baseBranch}`);

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { copy } from 'fs-extra';
33

44
import {
55
emptyDirExceptForDotGit,
6-
gitBranchExists,
76
gitCommit,
87
LANGUAGES,
98
run,
109
toAbsolutePath,
11-
GENERATED_MAIN_BRANCH,
1210
REPO_URL,
1311
} from '../../common';
1412
import { getLanguageFolder } from '../../config';
@@ -44,21 +42,12 @@ async function spreadGeneration(): Promise<void> {
4442
throw new Error('Environment variable `GITHUB_TOKEN` does not exist.');
4543
}
4644

47-
if (!(await gitBranchExists(GENERATED_MAIN_BRANCH))) {
48-
console.log(
49-
`Skiping because the branch \`${GENERATED_MAIN_BRANCH}\` does not exist.`
50-
);
51-
return;
52-
}
53-
5445
const lastCommitMessage = await run(`git log -1 --format="%s"`);
5546
const name = (await run(`git log -1 --format="%an"`)).trim();
5647
const email = (await run(`git log -1 --format="%ae"`)).trim();
5748
const commitMessage = cleanUpCommitMessage(lastCommitMessage);
5849
const langs = decideWhereToSpread(lastCommitMessage);
5950

60-
await run(`git checkout ${GENERATED_MAIN_BRANCH}`);
61-
6251
for (const lang of langs) {
6352
const { tempGitDir } = await cloneRepository({
6453
lang,

scripts/ci/codegen/text.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { REPO_URL, GENERATED_MAIN_BRANCH } from '../../common';
1+
import { MAIN_BRANCH, REPO_URL } from '../../common';
22

33
export default {
44
notification: {
@@ -11,7 +11,7 @@ export default {
1111
},
1212
cleanup: {
1313
header: '### ✗ The generated branch has been deleted.',
14-
body: `If the PR has been merged, you can check the generated code on the [\`${GENERATED_MAIN_BRANCH}\` branch](${REPO_URL}/tree/${GENERATED_MAIN_BRANCH}).`,
14+
body: `If the PR has been merged, you can check the generated code on the [\`${MAIN_BRANCH}\` branch](${REPO_URL}/tree/${MAIN_BRANCH}).`,
1515
},
1616
codegen: {
1717
header: '### ✔️ Code generated!',
@@ -25,7 +25,7 @@ export default {
2525
| Name | Link |
2626
|---------------------------------|------------------------|
2727
| 🔨 Triggered by | [\`${commit}\`](${REPO_URL}/pull/${eventNumber}/commits/${commit}) |
28-
| 🔍 Generated code | [\`${generatedCommit}\`](${REPO_URL}/compare/${GENERATED_MAIN_BRANCH}...${generatedCommit}) |
28+
| 🔍 Generated code | [\`${generatedCommit}\`](${REPO_URL}/commit/${generatedCommit}) |
2929
| 🌲 Generated branch | [\`${branch}\`](${REPO_URL}/tree/${branch}) |
3030
`;
3131
},

scripts/common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type {
1818
} from './types';
1919

2020
export const MAIN_BRANCH = config.mainBranch;
21-
export const GENERATED_MAIN_BRANCH = `generated/${MAIN_BRANCH}`;
2221
export const OWNER = config.owner;
2322
export const REPO = config.repo;
2423
export const REPO_URL = `https://github.com/${OWNER}/${REPO}`;

0 commit comments

Comments
 (0)