Skip to content

chore: keep generated/main alive #349

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 7 commits into from
Apr 8, 2022
Merged

Conversation

shortcuts
Copy link
Member

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-389

Changes included:

This PR should enable future iterations on removing generated stuff from main while keeping generated/main up to date.

  • Re-create a branch from the latest ref when the current branch is not main
  • Merge main in generated/main before pushing the generated commit
  • Update generation comment to leverage the compare UI with the generated/main branch

Notes:

  1. Changes seems too small to work, idk why 🤷🏼
  2. I've made multiple tests on my fork, which seems to work, but we will most likely need to disable the concurrency option on main to avoid wrong authoring.

🧪 Test

CI :D

@shortcuts shortcuts requested a review from a team April 7, 2022 12:53
@shortcuts shortcuts self-assigned this Apr 7, 2022
@shortcuts shortcuts requested review from eunjae-lee and damcou and removed request for a team April 7, 2022 12:53
@netlify
Copy link

netlify bot commented Apr 7, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 7a1e748
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/625006cf1a5cbd0008032d10

@algolia-bot
Copy link
Collaborator

algolia-bot commented Apr 7, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the generated/main branch.

@shortcuts shortcuts marked this pull request as draft April 7, 2022 13:26
Base automatically changed from chore/set-ci-variables-from-js to main April 7, 2022 14:48
@shortcuts shortcuts force-pushed the chore/keep-generated/main-alive branch from 06a5ecf to f348b20 Compare April 7, 2022 14:52
@shortcuts shortcuts marked this pull request as ready for review April 7, 2022 15:10
millotp
millotp previously approved these changes Apr 8, 2022
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of complicated to test, let's see it in action, great job !

@@ -3,6 +3,8 @@ import { run } from '../../common';
import { configureGitHubAuthor } from '../../release/common';
import { getNbGitDiff } from '../utils';

import { GENERATED_MAIN_BRANCH } from './text';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that GENERATED_MAIN_BRANCH will pull a dependency from the release folder, can you put MAIN_BRANCH in the root common.ts pls ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we need re-arrange the scripts folder imo, there's a lot of duplicate or deps that does not really make sense

@@ -3,6 +3,8 @@ import { run } from '../../common';
import { configureGitHubAuthor } from '../../release/common';
import { getNbGitDiff } from '../utils';

import { GENERATED_MAIN_BRANCH } from './text';

const PR_NUMBER = parseInt(process.env.PR_NUMBER || '0', 10);
const FOLDERS_TO_CHECK = 'yarn.lock openapitools.json clients specs/bundled';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be a list and getNbGitDiff accept a list, but I should have said that in the last PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was at first but then I had to join everything so I've went with a simple string, we will definitely need to iterate on this part so it can change anytime actually

I guess we can leave those changes for when we will remove generated code from main

// For the GENERATED_MAIN_BRANCH, we take the latest commit on main and generate code
if (baseBranch === 'main') {
console.log(`Merging '${baseBranch}' in '${generatedCodeBranch}'`);
await run(`git merge --no-commit ${baseBranch}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So generated/main will move by 2 commits for each PR ? Is it possible to squash the merge and the changes of the PR ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't create a merge commit, so it should only be ahead of one generation commit for each PR merged to main, which keeps the history correct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashing was my first option, but can lead to wrong authoring if multiple commits are merged to main. Which could also be solved by avoid cancelling concurrent jobs on main (2nd point in the PR body)

millotp
millotp previously approved these changes Apr 8, 2022
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome !

Comment on lines +20 to +21
export const MAIN_BRANCH = config.mainBranch;
export const GENERATED_MAIN_BRANCH = `generated/${MAIN_BRANCH}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this make more sense 👍

@shortcuts shortcuts enabled auto-merge (squash) April 8, 2022 09:50
@shortcuts shortcuts force-pushed the chore/keep-generated/main-alive branch from 0210f20 to e26ffbc Compare April 8, 2022 09:56
@shortcuts shortcuts requested a review from millotp April 8, 2022 09:56
@shortcuts shortcuts merged commit 6f17c84 into main Apr 8, 2022
@shortcuts shortcuts deleted the chore/keep-generated/main-alive branch April 8, 2022 10:11
shortcuts added a commit that referenced this pull request Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants