Skip to content

Commit

Permalink
update airbyte-ci bump-version to push more minimal changes (#34339)
Browse files Browse the repository at this point in the history
I noticed that `airbyte-ci connectors bump-version ` changes more things than necessary. In particular, it reserialize json, which means we were losing comments and reordering the various keys. I moved to doing a search-and-replace. In addition, I also noticed that the changelog changes could be slightly improved: I'm not increasing the space for the version (so we can accomodate 0.21.53, or 0.125.2),  and adding a new line at the end of the file (which was flagged as a difference by `diff`
  • Loading branch information
stephane-airbyte committed Jan 23, 2024
1 parent 35234b2 commit b38b0e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ E.G.: running `pytest` on a specific test folder:

| Version | PR | Description |
| ------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| 3.5.3 | [#34339](https://github.com/airbytehq/airbyte/pull/34339) | only do minimal changes on a connector version_bump |
| 3.5.2 | [#34381](https://github.com/airbytehq/airbyte/pull/34381) | Bind a sidecar docker host for `airbyte-ci test` |
| 3.5.1 | [#34321](https://github.com/airbytehq/airbyte/pull/34321) | Upgrade to Dagger 0.9.6 . |
| 3.5.0 | [#33313](https://github.com/airbytehq/airbyte/pull/33313) | Pass extra params after Gradle tasks. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
import datetime
from copy import deepcopy
from typing import TYPE_CHECKING

import semver
from dagger import Container, Directory
from pipelines.airbyte_ci.connectors.context import ConnectorContext
from pipelines.airbyte_ci.connectors.reports import ConnectorReport, Report
from pipelines.airbyte_ci.metadata.pipeline import MetadataValidation
from pipelines.helpers import git
from pipelines.helpers.connectors import metadata_change_helpers
from pipelines.models.steps import Step, StepResult, StepStatus
Expand Down Expand Up @@ -87,7 +87,7 @@ def add_changelog_entry(self, og_doc_content: str) -> str:
line_index_for_new_entry = self.find_line_index_for_new_entry(og_doc_content)
new_entry = f"| {self.new_version} | {today} | [{self.pull_request_number}](https://github.com/airbytehq/airbyte/pull/{self.pull_request_number}) | {self.changelog_entry} |"
lines.insert(line_index_for_new_entry, new_entry)
return "\n".join(lines)
return "\n".join(lines) + "\n"


class BumpDockerImageTagInMetadata(Step):
Expand All @@ -105,17 +105,13 @@ def __init__(
self.new_version = new_version

@staticmethod
def get_metadata_with_bumped_version(previous_version: str, new_version: str, current_metadata: dict) -> dict:
updated_metadata = deepcopy(current_metadata)
updated_metadata["data"]["dockerImageTag"] = new_version
# Bump strict versions
if current_metadata["data"].get("registries", {}).get("cloud", {}).get("dockerImageTag") == previous_version:
updated_metadata["data"]["registries"]["cloud"]["dockerImageTag"] = new_version
return updated_metadata
def get_metadata_with_bumped_version(previous_version: str, new_version: str, metadata_str: str) -> str:
return metadata_str.replace("dockerImageTag: " + previous_version, "dockerImageTag: " + new_version)

async def _run(self) -> StepResult:
metadata_path = self.context.connector.metadata_file_path
current_metadata = await metadata_change_helpers.get_current_metadata(self.repo_dir, metadata_path)
current_metadata_str = await metadata_change_helpers.get_current_metadata_str(self.repo_dir, metadata_path)
current_version = metadata_change_helpers.get_current_version(current_metadata)
if current_version is None:
return StepResult(
Expand All @@ -124,11 +120,16 @@ async def _run(self) -> StepResult:
stdout="Can't retrieve the connector current version.",
output_artifact=self.repo_dir,
)
updated_metadata = self.get_metadata_with_bumped_version(current_version, self.new_version, current_metadata)
repo_dir_with_updated_metadata = metadata_change_helpers.get_repo_dir_with_updated_metadata(
self.repo_dir, metadata_path, updated_metadata
updated_metadata_str = self.get_metadata_with_bumped_version(current_version, self.new_version, current_metadata_str)
repo_dir_with_updated_metadata = metadata_change_helpers.get_repo_dir_with_updated_metadata_str(
self.repo_dir, metadata_path, updated_metadata_str
)

metadata_validation_results = await MetadataValidation(self.context).run()
# Exit early if the metadata file is invalid.
if metadata_validation_results.status is not StepStatus.SUCCESS:
return metadata_validation_results

return StepResult(
self,
StepStatus.SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ async def get_current_metadata(repo_dir: Directory, metadata_path: Path) -> dict
return yaml.safe_load(await repo_dir.file(str(metadata_path)).contents())


async def get_current_metadata_str(repo_dir: Directory, metadata_path: Path) -> str:
return await repo_dir.file(str(metadata_path)).contents()


def get_repo_dir_with_updated_metadata(repo_dir: Directory, metadata_path: Path, updated_metadata: dict) -> Directory:
return repo_dir.with_new_file(str(metadata_path), contents=yaml.safe_dump(updated_metadata))


def get_repo_dir_with_updated_metadata_str(repo_dir: Directory, metadata_path: Path, updated_metadata_str: str) -> Directory:
return repo_dir.with_new_file(str(metadata_path), contents=updated_metadata_str)


def get_current_version(current_metadata: dict) -> str:
return current_metadata.get("data", {}).get("dockerImageTag")
2 changes: 1 addition & 1 deletion airbyte-ci/connectors/pipelines/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 = "pipelines"
version = "3.5.2"
version = "3.5.3"
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
authors = ["Airbyte <contact@airbyte.io>"]

Expand Down

0 comments on commit b38b0e6

Please sign in to comment.