Skip to content

Commit 9536d3f

Browse files
committed
implement version bump comment
1 parent ebbc948 commit 9536d3f

File tree

6 files changed

+292
-31
lines changed

6 files changed

+292
-31
lines changed

airbyte-ci/connectors/pipelines/pipelines/actions/environments.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def with_testing_dependencies(context: PipelineContext) -> Container:
8888
)
8989

9090

91-
def with_git(dagger_client, ci_github_access_token_secret, ci_git_user) -> Container:
91+
def with_git(dagger_client, ci_git_user: str = "octavia") -> Container:
9292
return (
9393
dagger_client.container()
9494
.from_("alpine:latest")
@@ -103,7 +103,6 @@ def with_git(dagger_client, ci_github_access_token_secret, ci_git_user) -> Conta
103103
]
104104
)
105105
)
106-
.with_secret_variable("GITHUB_TOKEN", ci_github_access_token_secret)
107106
.with_workdir("/ghcli")
108107
.with_exec(
109108
sh_dash_c(

airbyte-ci/connectors/pipelines/pipelines/commands/groups/connectors.py

+66-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from pipelines import main_logger
1616
from pipelines.bases import ConnectorWithModifiedFiles
1717
from pipelines.builds import run_connector_build_pipeline
18+
from pipelines.connector_changes.base_image_version_upgrade import run_connector_base_image_upgrade_pipeline
1819
from pipelines.connector_changes.format import run_connector_format_pipeline
19-
from pipelines.connector_changes.metadata_update import run_connector_base_image_upgrade_pipeline
20+
from pipelines.connector_changes.version_bump import run_connector_version_bump_pipeline
2021
from pipelines.contexts import ConnectorContext, ContextState, PublishConnectorContext
2122
from pipelines.github import update_global_commit_status_check_for_tests
2223
from pipelines.pipelines.connectors import run_connectors_pipelines
@@ -574,6 +575,70 @@ def upgrade_base_image(ctx: click.Context, commit_and_push: bool, export_to_host
574575
return True
575576

576577

578+
@connectors.command(cls=DaggerPipelineCommand, help="Upgrades the base image version used by the selected connectors..")
579+
@click.argument("bump-type", type=click.Choice(["patch", "minor", "major"]))
580+
@click.argument("pull-request-number", type=str)
581+
@click.argument("changelog-entry", type=str)
582+
@click.option("--commit-and-push", default=False)
583+
@click.option("--export-to-host", default=True)
584+
@click.option("--set-if-exists", default=True)
585+
@click.pass_context
586+
def bump_version(
587+
ctx: click.Context,
588+
bump_type: str,
589+
pull_request_number: str,
590+
changelog_entry: str,
591+
commit_and_push: bool,
592+
export_to_host: bool,
593+
set_if_exists: bool,
594+
) -> bool:
595+
"""Upgrades the base image version used by the selected connectors."""
596+
597+
if ctx.obj["is_local"] and commit_and_push:
598+
raise click.UsageError("You can't use the --commit-and-push option in local mode.")
599+
if ctx.obj["is_local"] and not export_to_host:
600+
main_logger.warning("Not using the --export-to-host option in local mode will not change anything on your local repo.")
601+
602+
connectors_contexts = [
603+
ConnectorContext(
604+
pipeline_name=f"Upgrade base image versions of connector {connector.technical_name}",
605+
connector=connector,
606+
is_local=ctx.obj["is_local"],
607+
git_branch=ctx.obj["git_branch"],
608+
git_revision=ctx.obj["git_revision"],
609+
ci_report_bucket=ctx.obj["ci_report_bucket_name"],
610+
report_output_prefix=ctx.obj["report_output_prefix"],
611+
use_remote_secrets=ctx.obj["use_remote_secrets"],
612+
gha_workflow_run_url=ctx.obj.get("gha_workflow_run_url"),
613+
dagger_logs_url=ctx.obj.get("dagger_logs_url"),
614+
pipeline_start_timestamp=ctx.obj.get("pipeline_start_timestamp"),
615+
ci_context=ctx.obj.get("ci_context"),
616+
ci_gcs_credentials=ctx.obj["ci_gcs_credentials"],
617+
ci_git_user=ctx.obj["ci_git_user"],
618+
ci_github_access_token=ctx.obj["ci_github_access_token"],
619+
open_report_in_browser=False,
620+
)
621+
for connector in ctx.obj["selected_connectors_with_modified_files"]
622+
]
623+
624+
anyio.run(
625+
run_connectors_pipelines,
626+
connectors_contexts,
627+
run_connector_version_bump_pipeline,
628+
"Version bump pipeline pipeline",
629+
ctx.obj["concurrency"],
630+
ctx.obj["dagger_logs_path"],
631+
ctx.obj["execute_timeout"],
632+
commit_and_push,
633+
export_to_host,
634+
bump_type,
635+
changelog_entry,
636+
pull_request_number,
637+
)
638+
639+
return True
640+
641+
577642
def log_selected_connectors(selected_connectors_with_modified_files: List[ConnectorWithModifiedFiles]) -> None:
578643
if selected_connectors_with_modified_files:
579644
selected_connectors_names = [c.technical_name for c in selected_connectors_with_modified_files]

airbyte-ci/connectors/pipelines/pipelines/connector_changes/metadata_update.py renamed to airbyte-ci/connectors/pipelines/pipelines/connector_changes/base_image_version_upgrade.py

+3-22
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
#
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
4-
from abc import abstractmethod
5-
from typing import Dict, Optional
4+
from typing import Optional
65

76
import yaml
87
from base_images import python
9-
from connector_ops.utils import METADATA_FILE_NAME, ConnectorLanguage
8+
from connector_ops.utils import ConnectorLanguage
109
from dagger import Container
1110
from pipelines.bases import ConnectorReport, StepResult, StepStatus
12-
from pipelines.connector_changes.common import ConnectorChangeStep
11+
from pipelines.connector_changes.common import MetadataUpdateStep
1312
from pipelines.contexts import ConnectorContext
1413

1514

16-
class MetadataUpdateStep(ConnectorChangeStep):
17-
@property
18-
def metadata_path(self) -> str:
19-
return str(self.context.connector.code_directory / METADATA_FILE_NAME)
20-
21-
async def get_current_metadata(self) -> Dict:
22-
return yaml.safe_load(await self.container_with_airbyte_repo.file(self.metadata_path).contents())
23-
24-
@abstractmethod
25-
async def get_updated_metadata(self) -> str:
26-
raise NotImplementedError()
27-
28-
async def get_container_with_updated_metadata(self, container_with_airbyte_repo: Container) -> Container:
29-
new_metadata = await self.get_updated_metadata()
30-
absolute_path_to_new_metadata = f"/airbyte/{self.context.connector.code_directory}/{METADATA_FILE_NAME}"
31-
return container_with_airbyte_repo.with_new_file(absolute_path_to_new_metadata, new_metadata)
32-
33-
3415
class UpgradeBaseImageMetadata(MetadataUpdateStep):
3516
title = "Upgrade the base image to the latest version in metadata.yaml"
3617
latest_python_version = python.VERSION_REGISTRY.latest_version.name_with_tag

airbyte-ci/connectors/pipelines/pipelines/connector_changes/common.py

+38-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
44
from abc import abstractmethod
5-
from typing import Optional
5+
from pathlib import Path
6+
from typing import Dict, List, Optional
67

8+
import yaml
9+
from connector_ops.utils import METADATA_FILE_NAME
710
from dagger import Container, Directory, Secret
811
from pipelines.actions import environments
912
from pipelines.bases import Step, StepResult
@@ -28,6 +31,10 @@ def __init__(
2831
self.push = push
2932
self.skip_ci = skip_ci
3033

34+
@property
35+
def modified_paths(self) -> List[str]:
36+
return [self.context.connector.code_directory]
37+
3138
async def get_airbyte_local_repo(self) -> Directory:
3239
return self.context.get_repo_dir()
3340

@@ -54,13 +61,14 @@ def commit_message(self) -> str:
5461
async def get_fresh_git_container(self, authenticated: bool = False) -> Container:
5562
if not authenticated:
5663
return (
57-
environments.with_git(self.dagger_client, self.context.ci_github_access_token_secret, self.context.ci_git_user)
64+
environments.with_git(self.dagger_client, self.context.ci_git_user)
5865
.with_mounted_directory("/airbyte", (await self.get_airbyte_repo()))
5966
.with_workdir("/airbyte")
6067
)
6168
else:
6269
return (
6370
await self.get_fresh_git_container(authenticated=False)
71+
.with_secret_variable("GITHUB_TOKEN", self.context.ci_github_access_token_secret)
6472
.with_secret_variable("AUTHENTICATED_REPO_URL", self.authenticated_repo_url)
6573
.with_exec(environments.sh_dash_c(["git remote set-url origin $AUTHENTICATED_REPO_URL"]))
6674
)
@@ -91,12 +99,37 @@ async def _run(self) -> StepResult:
9199
self.container_with_airbyte_repo = self.push(self.container_with_airbyte_repo)
92100
self.logger.info("Changes pushed.")
93101
if self.export_changes_to_host:
94-
await self.container_with_airbyte_repo.directory(str(self.context.connector.code_directory)).export(
95-
str(self.context.connector.code_directory)
96-
)
102+
for modified_path in self.modified_paths:
103+
if modified_path.is_dir():
104+
await self.container_with_airbyte_repo.directory(str(modified_path)).export(str(modified_path))
105+
else:
106+
await self.container_with_airbyte_repo.file(str(modified_path)).export(str(modified_path))
107+
97108
self.logger.info("Changes exported back to host.")
98109
return change_result
99110

100111
@abstractmethod
101112
async def make_connector_change(self, container_with_airbyte_repo) -> StepResult:
102113
raise NotImplementedError()
114+
115+
116+
class MetadataUpdateStep(ConnectorChangeStep):
117+
@property
118+
def modified_paths(self) -> List[Path]:
119+
return [self.context.connector.code_directory / METADATA_FILE_NAME]
120+
121+
@property
122+
def metadata_path(self) -> str:
123+
return str(self.context.connector.code_directory / METADATA_FILE_NAME)
124+
125+
async def get_current_metadata(self) -> Dict:
126+
return yaml.safe_load(await self.container_with_airbyte_repo.file(self.metadata_path).contents())
127+
128+
@abstractmethod
129+
async def get_updated_metadata(self) -> str:
130+
raise NotImplementedError()
131+
132+
async def get_container_with_updated_metadata(self, container_with_airbyte_repo: Container) -> Container:
133+
new_metadata = await self.get_updated_metadata()
134+
absolute_path_to_new_metadata = f"/airbyte/{self.context.connector.code_directory}/{METADATA_FILE_NAME}"
135+
return container_with_airbyte_repo.with_new_file(absolute_path_to_new_metadata, new_metadata)

0 commit comments

Comments
 (0)