-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
airbyte-ci: add format commands #31831
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
async def format_java(fix: bool) -> bool: | ||
logger = logging.getLogger("format") | ||
if fix: | ||
gradle_command = ["./gradlew", "spotlessApply"] | ||
else: | ||
gradle_command = ["./gradlew", "spotlessCheck", "--scan"] | ||
|
||
async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as dagger_client: | ||
try: | ||
format_container = await ( | ||
dagger_client.container() | ||
.from_("openjdk:17.0.1-jdk-slim") | ||
.with_exec( | ||
sh_dash_c( | ||
[ | ||
"apt-get update", | ||
"apt-get install -y bash", | ||
] | ||
) | ||
) | ||
.with_mounted_directory( | ||
"/src", | ||
dagger_client.host().directory( | ||
".", | ||
include=[ | ||
"**/*.java", | ||
"**/*.sql", | ||
"**/*.gradle", | ||
"gradlew", | ||
"gradlew.bat", | ||
"gradle", | ||
"**/deps.toml", | ||
"**/gradle.properties", | ||
"**/version.properties", | ||
"tools/gradle/codestyle/java-google-style.xml", | ||
"tools/gradle/codestyle/sql-dbeaver.properties", | ||
], | ||
exclude=DEFAULT_FORMAT_IGNORE_LIST, | ||
), | ||
) | ||
.with_workdir(f"/src") | ||
.with_exec(gradle_command) | ||
) | ||
|
||
await format_container | ||
if fix: | ||
await format_container.directory("/src").export(".") | ||
|
||
return True | ||
except dagger.ExecError as e: | ||
logger.error("Format failed") | ||
logger.error(e.stderr) | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 This is what I meant in your demo when I asked "are you using the Python GradleTask class" (I know it's utterly confusing when said orally 🤣 ).
Re-using this class (or just its methods) would make sure we have a standard way of running the gradle commands in dagger. We recently improved it to make sure subsequent runs benefit from caching.
I realize that with Lazy subcommand we're stepping away from the Step
and pipeline paradigm which happens in the connector
subgroup.
I find this new approach elegant, nevertheless, I'd appreciate code reuse.
Feel free to split this class up to not make all its internal logic depend on the Step
one and pick the things you need from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this one! true! Great point, I'll take a look :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a try - it was really hard without knowing what's really going on in here. The current code although its a "gradle task" command is highly configured to handle gradle commands in connector containers.
I personally would feel uncomfortable messing around with this too much myself. If you want to stack off of this to split up the gradleTask into a gradle base container in which i can run gradle commands (not just connector gradle commands), that'd be very welcome!
Here's the commit where I took a crack; it was also hard with the PipelineContext etc,:
a22a14b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a sign that some further refactoring is required for this change to land properly. I'm not surprised that the PipelineContext and friends get in the way, and that they would need to be changed at some point. Perhaps the time has come, though that would be outside the scope of this PR.
.from_("node:18.18.0-slim") | ||
.with_exec( | ||
sh_dash_c( | ||
[ | ||
"apt-get update", | ||
"apt-get install -y bash", | ||
] | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be declared a dagger/action/?
module and we'd call: with_node(dagger_client, node_version)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dumb question - that would be a container, not an action, right?
I was tripped up by most containers in dagger actions taking in pipelineContexts, not dagger_clients.
or is it dagger.container().with_go
? 🤔
Without the apt-get updating i've removed, that method would just be
return container.from_(NODE_IMAGE)
I think
try: | ||
license_container = await ( | ||
dagger_client.container() | ||
.from_("golang:1.17") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for node: a with_go(dagger_client, go_version)
action function call would be nice
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/format/python/commands.py
Outdated
Show resolved
Hide resolved
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/format/commands.py
Outdated
Show resolved
Hide resolved
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/format/commands.py
Outdated
Show resolved
Hide resolved
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/format/commands.py
Outdated
Show resolved
Hide resolved
40c3295
to
6235d20
Compare
6235d20
to
d685a6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did another pass. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Before Merging a Connector Pull RequestWow! What a great pull request you have here! 🎉 To merge this PR, ensure the following has been done/considered for each connector added or updated:
If the checklist is complete, but the CI check is failing,
|
/approve-and-merge reason="bypass connectors tests - formatting changes only" |
What
airbyte-ci
How
airbyte-ci format fix
andairbyte-ci format check
subgroupsformat
command from gradle and the gradle check workflow - format checking and formatting should only happen via ci (gradle does other checking still)Usage
General workflow:
0. Dev pushes a PR
Other ways we can increase the ease of formatting:
Todo
Recommended reading order
x.java
y.python
🚨 User Impact 🚨