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

connectors-ci: better modified connectors detection logic #28855

Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aabbf8c
connectors-ci: improve modified connectors detection
alafanechere Jul 29, 2023
9e6004b
Merge branch 'master' into augustin/connectors-ci/better-modified-con…
alafanechere Jul 31, 2023
d58269d
update changelog
alafanechere Jul 31, 2023
3ba05c9
Merge branch 'master' into augustin/connectors-ci/better-modified-con…
alafanechere Aug 1, 2023
98b7c1e
rename get_all_released_connectors to get_all_connectors_in_repo
alafanechere Aug 1, 2023
0e15170
bump connector ops version
alafanechere Aug 1, 2023
a2166ff
selected connector intersection instead of union
alafanechere Aug 1, 2023
0b05dc1
move selection logic to a dedicated function
alafanechere Aug 1, 2023
4675b13
wip testing
alafanechere Aug 1, 2023
b37862e
remove ctx logging
alafanechere Aug 1, 2023
bc6a175
ref: centralize selection logic even more
alafanechere Aug 2, 2023
c39be98
more tests
alafanechere Aug 2, 2023
110a7a2
better repo filtering on tests
alafanechere Aug 2, 2023
d3b8110
add --metadata-only-changes on publish workflow
alafanechere Aug 2, 2023
96e6eaf
Merge branch 'master' into augustin/connectors-ci/better-modified-con…
alafanechere Aug 2, 2023
3627b04
Merge branch 'master' into augustin/connectors-ci/better-modified-con…
alafanechere Aug 2, 2023
0de7a48
DEMO - to revert
alafanechere Aug 2, 2023
1da9809
update CLI doc
alafanechere Aug 2, 2023
c181cf6
fix should_run
alafanechere Aug 2, 2023
351725f
DEMO - to revert
alafanechere Aug 2, 2023
a2fe34b
test
alafanechere Aug 2, 2023
cc07429
Revert "DEMO - to revert"
alafanechere Aug 2, 2023
e9d21b5
Revert "DEMO - to revert"
alafanechere Aug 2, 2023
26a68e5
perform connector name validation at click option parsing
alafanechere Aug 3, 2023
a6bfcdb
Merge branch 'master' into augustin/connectors-ci/better-modified-con…
alafanechere Aug 3, 2023
22ef805
fix connector ops version bumping
alafanechere Aug 3, 2023
be62801
fix connector ops version bumping
alafanechere Aug 3, 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
2 changes: 1 addition & 1 deletion .github/workflows/publish_connectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
slack_webhook_url: ${{ secrets.PUBLISH_ON_MERGE_SLACK_WEBHOOK }}
spec_cache_gcs_credentials: ${{ secrets.SPEC_CACHE_SERVICE_ACCOUNT_KEY_PUBLISH }}
subcommand: "connectors --concurrency=1 --execute-timeout=3600 --modified publish --main-release"
subcommand: "connectors --concurrency=1 --execute-timeout=3600 --metadata-changes-only publish --main-release"

- name: Publish connectors [manual]
id: publish-connectors
Expand Down
15 changes: 12 additions & 3 deletions airbyte-ci/connectors/connector_ops/connector_ops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def __repr__(self) -> str:

@functools.lru_cache(maxsize=2)
def get_local_dependency_paths(self, with_test_dependencies: bool = True) -> Set[Path]:
dependencies_paths = [self.code_directory]
dependencies_paths = []
if self.language == ConnectorLanguage.JAVA:
dependencies_paths += get_all_gradle_dependencies(
self.code_directory / "build.gradle", with_test_dependencies=with_test_dependencies
Expand Down Expand Up @@ -351,9 +351,18 @@ def get_changed_connectors(
return {Connector(get_connector_name_from_path(changed_file)) for changed_file in changed_source_connector_files}


def get_all_released_connectors() -> Set:
def get_all_connectors_in_repo() -> Set[Connector]:
"""Retrieve a set of all Connectors in the repo.
We globe the connectors folder for metadata.yaml files and construct Connectors from the directory name.

Returns:
A set of Connectors.
"""
repo = git.Repo(search_parent_directories=True)
repo_path = repo.working_tree_dir

return {
Connector(Path(metadata_file).parent.name)
for metadata_file in glob("airbyte-integrations/connectors/**/metadata.yaml", recursive=True)
for metadata_file in glob(f"{repo_path}/airbyte-integrations/connectors/**/metadata.yaml", recursive=True)
if SCAFFOLD_CONNECTOR_GLOB not in metadata_file
}
2 changes: 1 addition & 1 deletion airbyte-ci/connectors/connector_ops/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "connector_ops"
version = "0.2.1"
version = "0.2.3"
description = "Packaged maintained by the connector operations team to perform CI for connectors"
authors = ["Airbyte <contact@airbyte.io>"]

Expand Down
7 changes: 5 additions & 2 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Available commands:
| `--language` | True | | Select connectors with a specific language: `python`, `low-code`, `java`. Can be used multiple times to select multiple languages. |
| `--modified` | False | False | Run the pipeline on only the modified connectors on the branch or previous commit (depends on the pipeline implementation). |
| `--concurrency` | False | 5 | Control the number of connector pipelines that can run in parallel. Useful to speed up pipelines or control their resource usage. |
| `--metadata-change-only/--not-metadata-change-only` | False | `--not-metadata-change-only` | Only run the pipeline on connectors with changes on their metadata.yaml file. |


### <a id="connectors-list-command"></a>`connectors list` command
Retrieve the list of connectors satisfying the provided filters.
Expand Down Expand Up @@ -378,8 +380,9 @@ This command runs the Python tests for a airbyte-ci poetry package.

| Version | PR | Description |
|---------|-----------------------------------------------------------|----------------------------------------------------------------------------------------------|
| 0.3.2 | [#28789](https://github.com/airbytehq/airbyte/pull/28789) | Do not consider empty reports as successfull. |
| 0.3.1 | [#28938](https://github.com/airbytehq/airbyte/pull/28938) | Handle 5 status code on MetadataUpload as skipped |
| 0.3.3 | [#28855](https://github.com/airbytehq/airbyte/pull/28855) | Improve the selected connectors detection for connectors commands. |
| 0.3.2 | [#28789](https://github.com/airbytehq/airbyte/pull/28789) | Do not consider empty reports as successfull. |
| 0.3.1 | [#28938](https://github.com/airbytehq/airbyte/pull/28938) | Handle 5 status code on MetadataUpload as skipped |
| 0.3.0 | [#28869](https://github.com/airbytehq/airbyte/pull/28869) | Enable the Dagger terminal UI on local `airbyte-ci` execution |
| 0.2.3 | [#28907](https://github.com/airbytehq/airbyte/pull/28907) | Make dagger-in-dagger work for `airbyte-ci tests` command |
| 0.2.2 | [#28897](https://github.com/airbytehq/airbyte/pull/28897) | Sentry: Ignore error logs without exceptions from reporting |
Expand Down
15 changes: 12 additions & 3 deletions airbyte-ci/connectors/pipelines/pipelines/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from enum import Enum
from typing import TYPE_CHECKING, Any, ClassVar, List, Optional
from typing import TYPE_CHECKING, Any, ClassVar, List, Optional, Set

import anyio
import asyncer
from anyio import Path
from connector_ops.utils import console
from connector_ops.utils import Connector, console
from dagger import Container, DaggerError, QueryError
from jinja2 import Environment, PackageLoader, select_autoescape
from pipelines import sentry_utils
from pipelines.actions import remote_storage
from pipelines.consts import GCS_PUBLIC_DOMAIN, LOCAL_REPORTS_PATH_ROOT, PYPROJECT_TOML_FILE_PATH
from pipelines.utils import check_path_in_workdir, format_duration, get_exec_result
from pipelines.utils import METADATA_FILE_NAME, check_path_in_workdir, format_duration, get_exec_result
from rich.console import Group
from rich.panel import Panel
from rich.style import Style
Expand All @@ -36,6 +36,15 @@
from pipelines.contexts import PipelineContext


@dataclass(frozen=True)
class ConnectorWithModifiedFiles(Connector):
modified_files: Set[Path] = field(default_factory=list)

@property
def has_metadata_change(self) -> bool:
return any(path.name == METADATA_FILE_NAME for path in self.modified_files)


class CIContext(str, Enum):
"""An enum for Ci context values which can be ["manual", "pull_request", "nightly_builds"]."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
get_modified_files_in_branch,
get_modified_files_in_commit,
get_modified_files_in_pull_request,
transform_strs_to_paths,
)

from .groups.connectors import connectors
Expand Down Expand Up @@ -120,7 +121,9 @@ def airbyte_ci(
else:
ctx.obj["pull_request"] = None

ctx.obj["modified_files"] = get_modified_files(git_branch, git_revision, diffed_branch, is_local, ci_context, ctx.obj["pull_request"])
ctx.obj["modified_files"] = transform_strs_to_paths(
get_modified_files(git_branch, git_revision, diffed_branch, is_local, ci_context, ctx.obj["pull_request"])
)

if not is_local:
main_logger.info("Running airbyte-ci in CI mode.")
Expand All @@ -134,6 +137,7 @@ def airbyte_ci(
main_logger.info(f"Pipeline Start Timestamp: {pipeline_start_timestamp}")
main_logger.info(f"Modified Files: {ctx.obj['modified_files']}")


airbyte_ci.add_command(connectors)
airbyte_ci.add_command(metadata)
airbyte_ci.add_command(tests)
Expand Down
Loading