Skip to content

Commit

Permalink
airbyte-ci: do not push latest tag for release candidates (airbytehq#…
Browse files Browse the repository at this point in the history
…44551)

## What
Closes airbytehq/airbyte-internal-issues#9403
When a connector is a release candidate it will have the `releases.isReleaseCandidate` flag set to `true` in its `metadata.yaml`.
We don't want to publish the `latest` tag when the connector is a RC.

## How
Tweak the publish pipeline to conditionnaly publish the latest tag according to the metadata content.
  • Loading branch information
alafanechere authored Aug 22, 2024
1 parent 41fb665 commit 66b39a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
5 changes: 3 additions & 2 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ Steps
#### Options

| Option | Required | Default | Mapped environment variable | Description |
|------------------|----------| ------- |-----------------------------|-------------------------------------------------------------|
| ---------------- | -------- | ------- | --------------------------- | ----------------------------------------------------------- |
| `--skip-step/-x` | False | | | Skip steps by id e.g. `-x llm_relationships -x publish_erd` |

### <a id="format-subgroup"></a>`format` command subgroup
Expand Down Expand Up @@ -842,7 +842,8 @@ airbyte-ci connectors --language=low-code migrate-to-manifest-only
## Changelog

| Version | PR | Description |
| ------- | ---------------------------------------------------------- |------------------------------------------------------------------------------------------------------------------------------|
| ------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 4.34.0 | [#44551](https://github.com/airbytehq/airbyte/pull/44551) | `connectors publish` do not push the `latest` tag when the current version is a release candidate. |
| 4.33.1 | [#44465](https://github.com/airbytehq/airbyte/pull/44465) | Ignore version check if only erd folder is changed |
| 4.33.0 | [#44377](https://github.com/airbytehq/airbyte/pull/44377) | Upload connector SBOM to metadata service bucket on publish. |
| 4.32.5 | [#44173](https://github.com/airbytehq/airbyte/pull/44173) | Bug fix for live tests' --should-read-with-state handling. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,26 @@ class PushConnectorImageToRegistry(Step):
def latest_docker_image_name(self) -> str:
return f"{self.context.docker_repository}:latest"

@property
def should_push_latest_tag(self) -> bool:
"""
We don't want to push the latest tag for release candidates or pre-releases.
Returns:
bool: True if the latest tag should be pushed, False otherwise.
"""
is_release_candidate = self.context.connector.metadata.get("releases", {}).get("isReleaseCandidate", False)
is_pre_release = self.context.pre_release
return not is_release_candidate and not is_pre_release

async def _run(self, built_containers_per_platform: List[Container], attempts: int = 3) -> StepResult:
try:
image_ref = await built_containers_per_platform[0].publish(
f"docker.io/{self.context.docker_image}",
platform_variants=built_containers_per_platform[1:],
forced_compression=ImageLayerCompression.Gzip,
)
if not self.context.pre_release:
if self.should_push_latest_tag:
image_ref = await built_containers_per_platform[0].publish(
f"docker.io/{self.latest_docker_image_name}",
platform_variants=built_containers_per_platform[1:],
Expand Down
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 = "4.33.1"
version = "4.34.0"
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
authors = ["Airbyte <[email protected]>"]

Expand Down
28 changes: 28 additions & 0 deletions airbyte-ci/connectors/pipelines/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,31 @@ async def test_run_connector_python_registry_publish_pipeline(

if expect_build_connector_called:
publish_pipeline.steps.run_connector_build.assert_called_once()


class TestPushConnectorImageToRegistry:
@pytest.mark.parametrize(
"is_pre_release, is_release_candidate, should_publish_latest",
[
(False, False, True),
(True, False, False),
(False, True, False),
(True, True, False),
],
)
async def test_publish_latest_tag(self, mocker, publish_context, is_pre_release, is_release_candidate, should_publish_latest):
publish_context.docker_image = "airbyte/source-pokeapi:0.0.0"
publish_context.docker_repository = "airbyte/source-pokeapi"
publish_context.pre_release = is_pre_release
publish_context.connector.metadata = {"releases": {"isReleaseCandidate": is_release_candidate}}
step = publish_pipeline.PushConnectorImageToRegistry(publish_context)
amd_built_container = mocker.Mock(publish=mocker.AsyncMock())
arm_built_container = mocker.Mock(publish=mocker.AsyncMock())
built_containers_per_platform = [amd_built_container, arm_built_container]
await step.run(built_containers_per_platform)
assert amd_built_container.publish.call_args_list[0][0][0] == "docker.io/airbyte/source-pokeapi:0.0.0"
if should_publish_latest:
assert amd_built_container.publish.await_count == 2, "Expected to publish the latest tag and the specific version tag"
assert amd_built_container.publish.call_args_list[1][0][0] == "docker.io/airbyte/source-pokeapi:latest"
else:
assert amd_built_container.publish.await_count == 1, "Expected to publish only the specific version tag"

0 comments on commit 66b39a4

Please sign in to comment.