Skip to content

airbyte-ci: format perf improvement + exit 1 when modified files #33097

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

Conversation

alafanechere
Copy link
Contributor

@alafanechere alafanechere commented Dec 5, 2023

What

Relates to #32935

As we want developers to adopt airbyte-ci format fix locally it has to:

  • Be fast
  • Exit with 1 when files are modified

How

This PR refactors the format command significantly:

  • fix and check run the same command in containers: it will guarantee that formatting errors thrown by check can always be fixed. We also improve caching, as it's the same command a fix following a check will reuse the same docker layer. The single difference between check and fix is that fix exports modified files back to the file system.

  • Avoid code duplication at subcommand declaration and centralize the formatters configurations in a single module

  • Only exports back to the host the modified files by diffing the original repo dir state and the formatted code. It makes the exportoperation faster

  • Exit with 1 status code when fix is modifying files: this is a requirement to wrap this command in a future pre-push hook to avoid pushing unformatted code

  • Leverage internal caching in formatters with caching abilities (prettier and black): it leads to a significant boost for prettier: 8seconds vs 30s.

Outcome

airbyte-ci format fix all runs in ~30s once you pulled the images.

NB

  • The binary used on this branch by the automatic formatting in the CI will format the unformatted code I added for tests. We should cancel auto format otherwise the tests will fail on master. The committed unformatted code will be ignored by formatters on master once the latest binary is released.
  • The tests are not passing because of the same reason: the master binary is used in the CI but I had to make change to airbyte-ci test command to run the formatting tests.

Copy link

vercel bot commented Dec 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview Dec 8, 2023 10:02am

@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from 8369ede to cef58a8 Compare December 5, 2023 13:42
Comment on lines +57 to +71
if: always()
run: git ls-files -i -c --exclude-from=.gitignore | xargs -r git rm --cached

- name: Commit Formatting Changes (PR)
uses: stefanzweifel/git-auto-commit-action@v5
# do not commit if master branch
if: github.ref != 'refs/heads/master'
if: github.ref != 'refs/heads/master' && always()
with:
commit_message: Automated Commit - Formatting Changes
commit_user_name: Octavia Squidington III
commit_user_email: [email protected]

- name: Run airbyte-ci format check all
if: always()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to add this condition now that airbyte-ci format fix all exits with status code 1 if files were modified.
We'll soon only run check on PRs so this file will likely be removed and replaced by format_check.yml on PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced by commands.py a level higher.

@alafanechere alafanechere marked this pull request as ready for review December 5, 2023 14:04
@alafanechere alafanechere requested review from a team and postamar and removed request for a team December 5, 2023 14:04
Copy link
Contributor

@postamar postamar left a comment

Choose a reason for hiding this comment

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

LGTM modulo fixing a very minor bug that adds *.groovy source files instead of *.grade.
My review is somewhat superficial and doesn't look into the airbyte-ci structure changes too much, but I didn't notice anything shocking. I figure that the correctness of this change is straightforward for you to validate on your end.

@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from 2b2f3b9 to be9d671 Compare December 6, 2023 11:08
@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from a4bd53a to 346c554 Compare December 6, 2023 15:08
@airbytehq airbytehq deleted a comment from CLAassistant Dec 6, 2023
@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from e3ace0e to e92b61d Compare December 6, 2023 15:11
@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from e92b61d to 37f2b9c Compare December 6, 2023 15:13
Copy link
Contributor

@bnchrch bnchrch left a comment

Choose a reason for hiding this comment

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

This is a great improvement!

There are only a few small changes I think we should make.

The only blocking one is how we define our cache keys.

Copy link
Contributor

@erohmensing erohmensing left a comment

Choose a reason for hiding this comment

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

Great refactor. Nothing blocking from me!

@alafanechere
Copy link
Contributor Author

Thanks for the review @erohmensing ! I'll push the your suggestions

If the commands are the same, would we consider putting them back together into one command with a --check arg? definitely not required in any case - but if we're going down the path of making things easier to reason about, and potentially later having a lint or other check that includes linting (or other checks which can't be autofixed)

I created https://github.com/airbytehq/airbyte-internal-issues/issues/2763 . I agree it's indeed something we shall consider. I don't think it's pressing though and we could revisit the interface when we'll want to add linting.

@alafanechere
Copy link
Contributor Author

@bnchrch about the cache keys:

  • We're not talking about NPM or Python (pip) cache here. It's only prettier and black cache.
  • I changed the cache volume name for prettier and black to capture their version
  • I think it's worth it for prettier: we know the version we install as it's hardcoded in the function building the container.
  • It's a bit harder for black as in the execution context we can't determine the exact black version we're going to install. It's determined by poetry.lock (root of the repo) and I find it a bit far fetched to parse this file to check the black version. I took a look at black's code and it appears that their cache folder has __version__ subfolder, so we're rather safe in term of cache/version isolation.

@alafanechere alafanechere requested a review from bnchrch December 7, 2023 14:27
@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from c753e8f to b55ef13 Compare December 7, 2023 15:20
@erohmensing erohmensing mentioned this pull request Dec 7, 2023
@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from b55ef13 to e1d8e65 Compare December 7, 2023 17:44
Copy link
Contributor

@bnchrch bnchrch left a comment

Choose a reason for hiding this comment

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

One nit but nothing to stand in the way

LGTM!

@erohmensing erohmensing force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from e1d8e65 to 8c7d2f0 Compare December 7, 2023 20:34
@CLAassistant
Copy link

CLAassistant commented Dec 7, 2023

CLA assistant check
All committers have signed the CLA.

@alafanechere alafanechere force-pushed the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch from 089465f to b078259 Compare December 8, 2023 10:02
@alafanechere
Copy link
Contributor Author

Will merge without CI checks as the binary used for them is the one from master.
I confirmed that the format is 🆗 locally:
airbyte-ci format chell all:

                    Summary of commands results
                    ========================

                    ✅ java

                    ✅ js

                    ✅ license

                    ✅ python

The airbyte-ci tests are also passing locally.

@alafanechere alafanechere merged commit aab74b2 into master Dec 8, 2023
@alafanechere alafanechere deleted the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch December 8, 2023 10:20
Copy link

sentry-io bot commented Dec 8, 2023

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ExceptionGroup: 3 exceptions were raised in the task group: anyio._backends._asyncio in __aexit__ View Issue
  • ‼️ ExceptionGroup: 2 exceptions were raised in the task group: anyio._backends._asyncio in __aexit__ View Issue
  • ‼️ QueryError: Unavailable: error reading from server: EOF dagger.api.base in _handle_execute View Issue
  • ‼️ QueryError: Unavailable: error reading from server: EOF dagger.api.base in _handle_execute View Issue
  • ‼️ QueryError: Unavailable: error reading from server: EOF dagger.api.base in _handle_execute View Issue

Did you find this useful? React with a 👍 or 👎

@erohmensing erohmensing restored the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch December 12, 2023 18:21
rishabh-cldcvr pushed a commit to ollionorg/datapipes-airbyte that referenced this pull request Dec 14, 2023
@erohmensing erohmensing deleted the augustin/12-04-airbyte-ci_format_fix_exit_with_1_when_formatted_files branch March 8, 2024 22:24
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.

5 participants