Skip to content
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

Merged
merged 147 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
a4994f4
Add lazy decorator
bnchrch Oct 19, 2023
ccddd26
Add playground subcommands
bnchrch Oct 19, 2023
96643f1
steal
bnchrch Oct 19, 2023
efa0786
Show demo of context coming through
bnchrch Oct 19, 2023
76458dc
Add pass_click_context_and_args_to_children
bnchrch Oct 19, 2023
58845d3
Add click decorator to reduce boilerplate
bnchrch Oct 19, 2023
435f44d
Add click_append_to_context_object decorator
bnchrch Oct 19, 2023
55baf8f
Move files
bnchrch Oct 19, 2023
8bfe2aa
Automated Commit - Formatting Changes
bnchrch Oct 19, 2023
a9b7365
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Oct 24, 2023
27043ae
Bring up to date with async click
bnchrch Oct 24, 2023
c53310a
Replace test with playground impl
bnchrch Oct 24, 2023
b07da00
Add singleton test
bnchrch Oct 24, 2023
03a14c9
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Oct 30, 2023
714d201
Fix low hanging comments
bnchrch Oct 31, 2023
29087ea
Automated Commit - Formatting Changes
bnchrch Oct 31, 2023
fb43cfb
Move decorator to file
bnchrch Oct 31, 2023
323139d
Add tests
bnchrch Nov 1, 2023
f624fa3
Add forgotten test
bnchrch Nov 1, 2023
24297df
Update ctx to click pipeline context
bnchrch Nov 1, 2023
58b28af
Add cli tests
bnchrch Nov 2, 2023
a4e1efb
Remove async
bnchrch Nov 2, 2023
b1e479b
Add async back
bnchrch Nov 2, 2023
d89f7f3
Add doc string
bnchrch Nov 2, 2023
6855ba3
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Nov 2, 2023
7ca02fc
Automated Commit - Formatting Changes
bnchrch Nov 2, 2023
8fb3ba6
Run license check on repo
erohmensing Nov 2, 2023
861d94b
add check command for python
erohmensing Oct 23, 2023
584cfdf
add poetry and pyproject files, ignore git
erohmensing Oct 23, 2023
d0db409
make black a dev dependency
erohmensing Oct 25, 2023
6df5f58
format new code
erohmensing Oct 25, 2023
6449446
remove black and isort code from build.gradle
erohmensing Oct 25, 2023
a331daf
make check/fix option required, change name to format
erohmensing Oct 25, 2023
e9b029f
format group
erohmensing Oct 25, 2023
184ca78
pass down context with --fix
erohmensing Oct 25, 2023
fc40339
temp-ish? comment out some build.gradle stuff that stops it from working
erohmensing Oct 25, 2023
c99bee3
add java formatting (no prettier or license format)
erohmensing Oct 25, 2023
9612d56
separate commands into subfolders
erohmensing Oct 25, 2023
c93c3db
remove prettier from gradle file and add command to run prettier
erohmensing Oct 25, 2023
e7d4cea
add default ignore list which fixes prettier. for some reason i can't…
erohmensing Oct 25, 2023
7425563
add default ignore list which fixes prettier. for some reason i can't…
erohmensing Oct 25, 2023
5e08526
change clean command
erohmensing Oct 25, 2023
887f7ce
temp: add license check
erohmensing Oct 25, 2023
e815cd6
fix fix command
erohmensing Oct 25, 2023
e05ad0a
modify short license for python
erohmensing Oct 25, 2023
285cefd
modify short license again?
erohmensing Oct 25, 2023
86d358b
move command to own file
erohmensing Oct 25, 2023
b04fa71
remove bash -c and ls/tree
erohmensing Oct 25, 2023
116442c
run python format
erohmensing Oct 25, 2023
9ead19c
remove license stuff from gradle build file
erohmensing Oct 25, 2023
44c5064
clean up gradle ignores for format
erohmensing Oct 25, 2023
f929b9d
simplify gradle file
erohmensing Oct 25, 2023
dce7dc1
allow invoking without subcommand to call all commands
erohmensing Oct 25, 2023
8e87400
use smaller and supported docker images for python and node
erohmensing Oct 26, 2023
7ad4f1b
remove more spotless stuff from gradle
erohmensing Oct 30, 2023
86cd43f
remove format from gradle check workflow
erohmensing Oct 30, 2023
5d78648
bring python back to build.gradle file but without formatting deps
erohmensing Oct 30, 2023
4151726
test: new github action workflow
erohmensing Oct 30, 2023
488bd35
add dockerhub and sentry auth
erohmensing Oct 30, 2023
b08db8a
maybe its available on the runner?
erohmensing Oct 30, 2023
de086cd
use the xl babyyy
erohmensing Oct 30, 2023
fc5a391
all the tokens?
erohmensing Oct 30, 2023
e59f646
fix java command with clickpipelinecontext
erohmensing Oct 31, 2023
c21302e
fix rest of commands to use pipelinecontext
erohmensing Oct 31, 2023
80bf800
oops, don't explicitly set the fix context param, let it come in thro…
erohmensing Oct 31, 2023
d3aa826
share a dagger client when running all the commands
erohmensing Oct 31, 2023
7bd0ab4
add initial chaining structure
erohmensing Oct 31, 2023
f625e25
use lazy imports for the top level group and clean up args
erohmensing Oct 31, 2023
d78aa46
move invoked subcommand stuff to right area
erohmensing Oct 31, 2023
3fb30ba
separate out commands and get format check java working
erohmensing Oct 31, 2023
ff8cf9a
get check commands and chaining going
erohmensing Oct 31, 2023
ced122b
get fix commands and chaining going
erohmensing Oct 31, 2023
c2fe2b9
improve help
erohmensing Oct 31, 2023
faddea3
remove dagger client param
erohmensing Nov 2, 2023
9ac7cc0
fix pass pipeline context import
erohmensing Nov 2, 2023
b11b8db
add licenses to new files
erohmensing Nov 2, 2023
fc5e677
readme and version bump
erohmensing Nov 2, 2023
2074bad
remove code formatting checks from connector test
erohmensing Nov 2, 2023
f712879
fix commands should always exit 0
erohmensing Nov 3, 2023
d27082c
potentially temp: give check command sys.exit(1)
erohmensing Nov 3, 2023
c00f03d
run via chaining for now
erohmensing Nov 3, 2023
c9da69f
format
erohmensing Nov 3, 2023
58eca7a
bring back bulk commands and use in CI
erohmensing Nov 3, 2023
903b04c
fix java formatting failure, and also speed it up significantly
erohmensing Nov 3, 2023
bd09adf
re-add logic to remove spotlessCheck from gradle check
erohmensing Nov 3, 2023
7a6e5c3
check java
erohmensing Nov 3, 2023
73fb20c
add readme info
erohmensing Nov 5, 2023
ab94ab5
add examples
erohmensing Nov 5, 2023
930b053
run checks concurrently
erohmensing Nov 5, 2023
39ae844
remove formatting stuff from gradleTask base
erohmensing Nov 5, 2023
d79f056
java: feedback on includes
erohmensing Nov 5, 2023
ee16e72
don't await containers as we create them
erohmensing Nov 5, 2023
3276d48
refactor
erohmensing Nov 5, 2023
7fc97aa
remove formatting stuff from connectors test package requirements
erohmensing Nov 5, 2023
3126efb
fix imports in check/fix subcommands
erohmensing Nov 5, 2023
ac977ca
abstract check
erohmensing Nov 5, 2023
ad30f84
abstract fix
erohmensing Nov 5, 2023
7b126dd
merge fix
erohmensing Nov 5, 2023
9f4467d
merge check
erohmensing Nov 5, 2023
435e55b
split container building from running check/format
erohmensing Nov 6, 2023
2ea4c44
shared containers
erohmensing Nov 6, 2023
aa5ced4
shared actions
erohmensing Nov 6, 2023
769b792
remove unused imports
erohmensing Nov 6, 2023
8774791
split up and document container building:
erohmensing Nov 6, 2023
31514ed
install dependencies before mounting code. add skip_entrypoint=true
erohmensing Nov 6, 2023
60505e9
rename pipelines
erohmensing Nov 6, 2023
ba6ce1a
register all tasks without listing them, poetry install no root
erohmensing Nov 6, 2023
8a8c2ec
some cleanup/add an example of a direction we could go in
erohmensing Nov 6, 2023
29343bc
little things
erohmensing Nov 6, 2023
bfc44fc
put go and node images in constants
erohmensing Nov 6, 2023
90cc182
use amazoncoretto image for java
erohmensing Nov 6, 2023
3d57d94
log check output in a friendly way and exit 1 on errors
erohmensing Nov 6, 2023
ca9a668
list errors in ci
erohmensing Nov 6, 2023
c9c11ca
format
erohmensing Nov 6, 2023
be9bb2e
Remove dagger client in the context obj
bnchrch Nov 7, 2023
afe5cea
Make run_sub_commands_generic
bnchrch Nov 7, 2023
22b19f3
Add all command
bnchrch Nov 8, 2023
5067c3d
Merge branch 'master' into ella/format-commands
alafanechere Nov 8, 2023
a9cb03d
update format command signature
alafanechere Nov 8, 2023
8327acd
avoid pyton reserved function name in command name
alafanechere Nov 8, 2023
de813e5
check commands: decorator cleanup, all_languages uses pipeline_context
alafanechere Nov 8, 2023
67de99d
fix decorators, pipeline_context can't be used at the all level
alafanechere Nov 8, 2023
b05f0b7
Instantiate early
bnchrch Nov 9, 2023
dff2d49
Update fix command
bnchrch Nov 9, 2023
7772cf3
update format.yaml to run format check all --list-errors
alafanechere Nov 9, 2023
3f2ab69
update format.yml to cancel-in-progress
alafanechere Nov 9, 2023
34cb674
improve help message to suggest fix
alafanechere Nov 9, 2023
07b2c6d
do not use reserved function name for license
alafanechere Nov 9, 2023
e7b2b78
python image as const
alafanechere Nov 9, 2023
ee74dbf
always assign dagger_client to the same 'og' context
alafanechere Nov 9, 2023
f0b502d
format: introduce CommandResult, reuse step status, make concurrent c…
alafanechere Nov 9, 2023
49b44a1
Add sibling command helper
bnchrch Nov 10, 2023
720ec47
Fix fix command
bnchrch Nov 10, 2023
bda56e5
Merge branch 'master' into ella/format-commands
alafanechere Nov 10, 2023
a6a1d37
format additional files
alafanechere Nov 10, 2023
76f83ea
remove format from gradle.yml
alafanechere Nov 10, 2023
0bcf0fc
gradle: tweak spotless config
postamar Nov 10, 2023
c48e9c9
remove octavia-cli from gradle build
postamar Nov 10, 2023
749ffab
gradle: restore commented block in base-normalization
postamar Nov 10, 2023
139f809
fix base-normalization issue
postamar Nov 10, 2023
84ff3b5
Add auto format
bnchrch Nov 10, 2023
02ca702
Merge branch 'master' into ella/format-commands
alafanechere Nov 13, 2023
89f1b2c
bump git-auto-commit-action to v5
alafanechere Nov 13, 2023
8385bcf
to revert: test format
alafanechere Nov 13, 2023
969d23f
Automated Commit - Formatting Changes
alafanechere Nov 13, 2023
84fd85a
Revert "Automated Commit - Formatting Changes"
alafanechere Nov 13, 2023
9c34b9d
Automated Commit - Formatting Changes
alafanechere Nov 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 20 additions & 42 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Format Code (Python + Java)
name: Check for formatting errors

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Cancel any previous runs on the same branch if they are still in progress
cancel-in-progress: true

on:
workflow_dispatch:
Expand All @@ -10,8 +12,8 @@ on:
- master
pull_request:
jobs:
format-and-commit:
runs-on: ubuntu-latest
format-fix:
runs-on: "conn-prod-xlarge-runner"
name: "Apply All Formatting Rules"
timeout-minutes: 40
steps:
Expand All @@ -20,16 +22,16 @@ jobs:
with:
ref: ${{ github.head_ref }}
# Important that this is set so that CI checks are triggered again
# Without this we would be be forever waiting on required checks to pass
# Without this we would be forever waiting on required checks to pass
token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }}

# IMPORTANT! This is nessesary to make sure that a status is reported on the PR
# even if the workflow is skipped. If we used github actions filters, the workflow
# IMPORTANT! This is necessary to make sure that a status is reported on the PR
# even if the workflow is skipped. If we used GitHub Actions filters, the workflow
# would not be reported as skipped, but instead would be forever pending.
#
Comment on lines +28 to 30
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're not comfortable with this I think we should remove the changed-files action call and make the airbyte-ci command run on all PRs.
The format command would perform a no-op according the modified_files list and report a success status if only markdown files are modified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw this!

@alafanechere I dont think Run on all is the right approach.

If we do that means time to merge a doc only change is unessesarily longer as GHA spin up + Runner spin up + Dagger spin up + format run all add up to > 5mins

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. But In any case a GHA spin up + Runner spin up is still required as the changed-file action will run on our self hosted runner.

# I KNOW THIS SOUNDS CRAZY, BUT IT IS TRUE.
#
# Also it gets worse
# Also, it gets worse
#
# IMPORTANT! DO NOT CHANGE THE QUOTES AROUND THE GLOBS. THEY ARE REQUIRED.
# MAKE SURE TO TEST ANY SYNTAX CHANGES BEFORE MERGING.
Expand All @@ -42,59 +44,35 @@ jobs:
- '**/*'
- '!**/*.md'

- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"

- uses: actions/setup-python@v4
- name: Run airbyte-ci format fix
uses: ./.github/actions/run-dagger-pipeline
with:
python-version: "3.10"

- name: Set up CI Gradle Properties
run: |
mkdir -p ~/.gradle/
cat > ~/.gradle/gradle.properties <<EOF
org.gradle.jvmargs=-Xmx8g -Xss4m \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
org.gradle.workers.max=8
org.gradle.vfs.watch=false
EOF

- name: Format
if: steps.changes.outputs.format_any_changed == 'true'
uses: Wandalen/wretry.action@v1.0.42
with:
command: ./gradlew format --scan --info --stacktrace
attempt_limit: 3
attempt_delay: 5000 # in ms
context: "pull_request"
docker_hub_password: ${{ secrets.DOCKER_HUB_PASSWORD }}
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
subcommand: "format fix all"

# This is helpful in the case that we change a previously committed generated file to be ignored by git.
- name: Remove any files that have been gitignored
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@v4
uses: stefanzweifel/git-auto-commit-action@v5
# do not commit if master branch
if: github.ref != 'refs/heads/master'
with:
commit_message: Automated Commit - Formatting Changes
commit_user_name: Octavia Squidington III
commit_user_email: octavia-squidington-iii@users.noreply.github.com

- name: "Fail on Formatting Changes (Master)"
if: github.ref == 'refs/heads/master'
run: git --no-pager diff && test -z "$(git --no-pager diff)"

notify-failure-slack-channel:
name: "Notify Slack Channel on Build Failures"
runs-on: ubuntu-latest
needs:
- format-and-commit
- format-fix
if: ${{ failure() && github.ref == 'refs/heads/master' }}
steps:
- name: Checkout Airbyte
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ jobs:
with:
read-only: ${{ github.ref != 'refs/heads/master' }}
# TODO: be able to remove the skipSlowTests property
# TODO: remove the format task ASAP
arguments: --scan --no-daemon --no-watch-fs format check -DskipSlowTests=true
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

arguments: --scan --no-daemon --no-watch-fs check -DskipSlowTests=true

# In case of self-hosted EC2 errors, remove this block.
stop-check-runner:
Expand Down
2 changes: 2 additions & 0 deletions airbyte-cdk/python/airbyte_cdk/utils/analytics_message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.

import time
from typing import Any, Optional

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

from typing import Union

import dpath.util
Expand Down
30 changes: 28 additions & 2 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ At this point you can run `airbyte-ci` commands.
- [`connectors bump_version` command](#connectors-bump_version)
- [`connectors upgrade_base_image` command](#connectors-upgrade_base_image)
- [`connectors migrate_to_base_image` command](#connectors-migrate_to_base_image)
- [`format` command subgroup](#format-subgroup)
* [`format check` command](#format-check-command)
* [`format fix` command](#format-fix-command)
Comment on lines +104 to +105
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not actually a command technically, but, for readme's sake...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The DX is the best the way it is IMO, but conceptually, we're not actually "chaining" anything in the subcommands, we're just running multiple

- [`metadata` command subgroup](#metadata-command-subgroup)
- [`metadata validate` command](#metadata-validate-command)
* [Example](#example)
Expand Down Expand Up @@ -205,7 +208,6 @@ flowchart TD
entrypoint[[For each selected connector]]
subgraph static ["Static code analysis"]
qa[Run QA checks]
fmt[Run code format checks]
sem["Check version follows semantic versionning"]
incr["Check version is incremented"]
metadata_validation["Run metadata validation on metadata.yaml"]
Expand Down Expand Up @@ -369,6 +371,29 @@ Migrate source-openweather to use the base image: `airbyte-ci connectors --name=
| --------------------- | ----------------------------------------------------------- |
| `PULL_REQUEST_NUMBER` | The GitHub pull request number, used in the changelog entry |

### <a id="format-subgroup"></a>`format` command subgroup

Available commands:
* `airbyte-ci format check all`
* `airbyte-ci format fix all`

### Examples
- Check for formatting errors in the repository: `airbyte-ci format check all`
- Fix formatting for only python files: `airbyte-ci format fix python`

### <a id="format-check-command"></a>`format check all` command

This command runs formatting checks, but does not format the code in place. It will exit 1 as soon as a failure is encountered. To fix errors, use `airbyte-ci format fix all`.

Running `airbyte-ci format check` will run checks on all different types of code. Run `airbyte-ci format check --help` for subcommands to check formatting for only certain types of files.

### <a id="format-fix-command"></a>`format fix all` command

This command runs formatting checks and reformats any code that would be reformatted, so it's recommended to stage changes you might have before running this command.

Running `airbyte-ci format fix all` will format all of the different types of code. Run `airbyte-ci format fix --help` for subcommands to format only certain types of files.


### <a id="metadata-validate-command-subgroup"></a>`metadata` command subgroup

Available commands:
Expand Down Expand Up @@ -408,7 +433,8 @@ This command runs the Python tests for a airbyte-ci poetry package.
## Changelog
| Version | PR | Description |
| ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| 2.5.9 | [#32427](https://github.com/airbytehq/airbyte/pull/32427) | Re-enable caching for source-postgres |
| 2.6.0 | [#31831](https://github.com/airbytehq/airbyte/pull/31831) | Add `airbyte-ci format` commands, remove connector-specific formatting check |
| 2.5.9 | [#32427](https://github.com/airbytehq/airbyte/pull/32427) | Re-enable caching for source-postgres |
| 2.5.8 | [#32402](https://github.com/airbytehq/airbyte/pull/32402) | Set Dagger Cloud token for airbyters only |
| 2.5.7 | [#31628](https://github.com/airbytehq/airbyte/pull/31628) | Add ClickPipelineContext class |
| 2.5.6 | [#32139](https://github.com/airbytehq/airbyte/pull/32139) | Test coverage report on Python connector UnitTest. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def should_use_remote_secrets(use_remote_secrets: Optional[bool]) -> bool:
lazy_subcommands={
"build": "pipelines.airbyte_ci.connectors.build_image.commands.build",
"test": "pipelines.airbyte_ci.connectors.test.commands.test",
"list": "pipelines.airbyte_ci.connectors.list.commands.list",
"list": "pipelines.airbyte_ci.connectors.list.commands.list_connectors",
"publish": "pipelines.airbyte_ci.connectors.publish.commands.publish",
"bump_version": "pipelines.airbyte_ci.connectors.bump_version.commands.bump_version",
"migrate_to_base_image": "pipelines.airbyte_ci.connectors.migrate_to_base_image.commands.migrate_to_base_image",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from rich.text import Text


@click.command(cls=DaggerPipelineCommand, help="List all selected connectors.")
@click.command(cls=DaggerPipelineCommand, help="List all selected connectors.", name="list")
@click.pass_context
async def list(
async def list_connectors(
ctx: click.Context,
):
selected_connectors = sorted(ctx.obj["selected_connectors_with_modified_files"], key=lambda x: x.technical_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
ConnectorLanguage.PYTHON: python_connectors.run_all_tests,
ConnectorLanguage.LOW_CODE: python_connectors.run_all_tests,
ConnectorLanguage.JAVA: java_connectors.run_all_tests,
},
"run_code_format_checks": {
ConnectorLanguage.PYTHON: python_connectors.run_code_format_checks,
ConnectorLanguage.LOW_CODE: python_connectors.run_code_format_checks,
# ConnectorLanguage.JAVA: java_connectors.run_code_format_checks
},
}
}


Expand Down Expand Up @@ -65,22 +60,6 @@ async def run_qa_checks(context: ConnectorContext) -> List[StepResult]:
return [await QaChecks(context).run()]


async def run_code_format_checks(context: ConnectorContext) -> List[StepResult]:
"""Run the code format checks according to the connector language.

Args:
context (ConnectorContext): The current connector context.

Returns:
List[StepResult]: The results of the code format checks steps.
"""
if _run_code_format_checks := LANGUAGE_MAPPING["run_code_format_checks"].get(context.connector.language):
return await _run_code_format_checks(context)
else:
context.logger.warning(f"No code format checks defined for connector language {context.connector.language}!")
return []


async def run_all_tests(context: ConnectorContext) -> List[StepResult]:
"""Run all the tests steps according to the connector language.

Expand Down Expand Up @@ -111,10 +90,7 @@ async def run_connector_test_pipeline(context: ConnectorContext, semaphore: anyi
async with semaphore:
async with context:
async with asyncer.create_task_group() as task_group:
tasks = [
task_group.soonify(run_all_tests)(context),
task_group.soonify(run_code_format_checks)(context),
]
tasks = [task_group.soonify(run_all_tests)(context)]
if not context.code_tests_only:
tasks += [
task_group.soonify(run_metadata_validation)(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,11 @@
from pipelines.airbyte_ci.connectors.build_image.steps.python_connectors import BuildConnectorImages
from pipelines.airbyte_ci.connectors.context import ConnectorContext
from pipelines.airbyte_ci.connectors.test.steps.common import AcceptanceTests, CheckBaseImageIsUsed
from pipelines.consts import LOCAL_BUILD_PLATFORM, PYPROJECT_TOML_FILE_PATH
from pipelines.consts import LOCAL_BUILD_PLATFORM
from pipelines.dagger.actions import secrets
from pipelines.models.steps import Step, StepResult, StepStatus


class CodeFormatChecks(Step):
"""A step to run the code format checks on a Python connector using Black, Isort and Flake."""

title = "Code format checks"

RUN_BLACK_CMD = ["python", "-m", "black", f"--config=/{PYPROJECT_TOML_FILE_PATH}", "--check", "."]
RUN_ISORT_CMD = ["python", "-m", "isort", f"--settings-file=/{PYPROJECT_TOML_FILE_PATH}", "--check-only", "--diff", "."]
RUN_FLAKE_CMD = ["python", "-m", "pflake8", f"--config=/{PYPROJECT_TOML_FILE_PATH}", "."]

async def _run(self) -> StepResult:
"""Run a code format check on the container source code.

We call black, isort and flake commands:
- Black formats the code: fails if the code is not formatted.
- Isort checks the import orders: fails if the import are not properly ordered.
- Flake enforces style-guides: fails if the style-guide is not followed.

Args:
context (ConnectorContext): The current test context, providing a connector object, a dagger client and a repository directory.
step (Step): The step in which the code format checks are run. Defaults to Step.CODE_FORMAT_CHECKS
Returns:
StepResult: Failure or success of the code format checks with stdout and stderr.
"""
connector_under_test = pipelines.dagger.actions.python.common.with_python_connector_source(self.context)

formatter = (
connector_under_test.with_exec(["echo", "Running black"])
.with_exec(self.RUN_BLACK_CMD)
.with_exec(["echo", "Running Isort"])
.with_exec(self.RUN_ISORT_CMD)
.with_exec(["echo", "Running Flake"])
.with_exec(self.RUN_FLAKE_CMD)
)
return await self.get_step_result(formatter)


class PytestStep(Step, ABC):
"""An abstract class to run pytest tests and evaluate success or failure according to pytest logs."""

Expand Down Expand Up @@ -261,15 +225,3 @@ async def run_all_tests(context: ConnectorContext) -> List[StepResult]:
]

return step_results + [task.value for task in tasks]


async def run_code_format_checks(context: ConnectorContext) -> List[StepResult]:
"""Run the code format check steps for Python connectors.

Args:
context (ConnectorContext): The current connector context.

Returns:
List[StepResult]: Results of the code format checks.
"""
return [await CodeFormatChecks(context).run()]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

from typing import List

import dagger
from pipelines.helpers.utils import sh_dash_c


def run_check(
container: dagger.Container,
check_commands: List[str],
) -> dagger.Container:
"""Checks whether the repository is formatted correctly.
Args:
container: (dagger.Container): The container to run the formatting check in
check_commands (List[str]): The list of commands to run to check the formatting
"""
return container.with_exec(sh_dash_c(check_commands), skip_entrypoint=True)


async def run_format(
container: dagger.Container,
format_commands: List[str],
) -> dagger.Container:
"""Formats the repository.
Args:
container: (dagger.Container): The container to run the formatter in
format_commands (List[str]): The list of commands to run to format the repository
"""
format_container = container.with_exec(sh_dash_c(format_commands), skip_entrypoint=True)
return await format_container.directory("/src").export(".")


def mount_repo_for_formatting(
dagger_client: dagger.Client,
container: dagger.Container,
include: List[str],
) -> dagger.Container:
"""Mounts the relevant parts of the repository: the code to format and the formatting config
Args:
container: (dagger.Container): The container to mount the repository in
include (List[str]): The list of files to include in the container
"""
container = container.with_mounted_directory(
"/src",
dagger_client.host().directory(
".",
include=include,
),
).with_workdir("/src")

return container
Loading
Loading