-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
airbyte-ci: Add pypi publishing logic (#34111)
- Loading branch information
Joe Reuter
authored
Jan 24, 2024
1 parent
c8d06f4
commit d289534
Showing
19 changed files
with
746 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/poetry/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# |
34 changes: 34 additions & 0 deletions
34
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/poetry/commands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
""" | ||
Module exposing the format commands. | ||
""" | ||
from __future__ import annotations | ||
|
||
import asyncclick as click | ||
from pipelines.cli.click_decorators import click_ignore_unused_kwargs, click_merge_args_into_context_obj | ||
from pipelines.cli.lazy_group import LazyGroup | ||
from pipelines.models.contexts.click_pipeline_context import ClickPipelineContext, pass_pipeline_context | ||
|
||
|
||
@click.group( | ||
name="poetry", | ||
help="Commands related to running poetry commands.", | ||
cls=LazyGroup, | ||
lazy_subcommands={ | ||
"publish": "pipelines.airbyte_ci.poetry.publish.commands.publish", | ||
}, | ||
) | ||
@click.option( | ||
"--package-path", | ||
help="The path to publish", | ||
type=click.STRING, | ||
required=True, | ||
) | ||
@click_merge_args_into_context_obj | ||
@pass_pipeline_context | ||
@click_ignore_unused_kwargs | ||
async def poetry(pipeline_context: ClickPipelineContext) -> None: | ||
pass |
3 changes: 3 additions & 0 deletions
3
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/poetry/publish/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# |
105 changes: 105 additions & 0 deletions
105
airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/poetry/publish/commands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
""" | ||
Module exposing the format commands. | ||
""" | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
import asyncclick as click | ||
from packaging import version | ||
from pipelines.airbyte_ci.steps.python_registry import PublishToPythonRegistry | ||
from pipelines.cli.confirm_prompt import confirm | ||
from pipelines.cli.dagger_pipeline_command import DaggerPipelineCommand | ||
from pipelines.consts import DEFAULT_PYTHON_PACKAGE_REGISTRY_URL | ||
from pipelines.models.contexts.click_pipeline_context import ClickPipelineContext, pass_pipeline_context | ||
from pipelines.models.contexts.python_registry_publish import PythonRegistryPublishContext | ||
from pipelines.models.steps import StepStatus | ||
|
||
|
||
async def _has_metadata_yaml(context: PythonRegistryPublishContext) -> bool: | ||
dir_to_publish = context.get_repo_dir(context.package_path) | ||
return "metadata.yaml" in await dir_to_publish.entries() | ||
|
||
|
||
def _validate_python_version(_ctx: dict, _param: dict, value: Optional[str]) -> Optional[str]: | ||
""" | ||
Check if an given version is valid. | ||
""" | ||
if value is None: | ||
return value | ||
try: | ||
version.Version(value) | ||
return value | ||
except version.InvalidVersion: | ||
raise click.BadParameter(f"Version {value} is not a valid version.") | ||
|
||
|
||
@click.command(cls=DaggerPipelineCommand, name="publish", help="Publish a Python package to a registry.") | ||
@click.option( | ||
"--python-registry-token", | ||
help="Access token", | ||
type=click.STRING, | ||
required=True, | ||
envvar="PYTHON_REGISTRY_TOKEN", | ||
) | ||
@click.option( | ||
"--registry-url", | ||
help="Which registry to publish to. If not set, the default pypi is used. For test pypi, use https://test.pypi.org/legacy/", | ||
type=click.STRING, | ||
default=DEFAULT_PYTHON_PACKAGE_REGISTRY_URL, | ||
) | ||
@click.option( | ||
"--publish-name", | ||
help="The name of the package to publish. If not set, the name will be inferred from the pyproject.toml file of the package.", | ||
type=click.STRING, | ||
) | ||
@click.option( | ||
"--publish-version", | ||
help="The version of the package to publish. If not set, the version will be inferred from the pyproject.toml file of the package.", | ||
type=click.STRING, | ||
callback=_validate_python_version, | ||
) | ||
@pass_pipeline_context | ||
@click.pass_context | ||
async def publish( | ||
ctx: click.Context, | ||
click_pipeline_context: ClickPipelineContext, | ||
python_registry_token: str, | ||
registry_url: str, | ||
publish_name: Optional[str], | ||
publish_version: Optional[str], | ||
) -> bool: | ||
context = PythonRegistryPublishContext( | ||
is_local=ctx.obj["is_local"], | ||
git_branch=ctx.obj["git_branch"], | ||
git_revision=ctx.obj["git_revision"], | ||
ci_report_bucket=ctx.obj["ci_report_bucket_name"], | ||
report_output_prefix=ctx.obj["report_output_prefix"], | ||
gha_workflow_run_url=ctx.obj.get("gha_workflow_run_url"), | ||
dagger_logs_url=ctx.obj.get("dagger_logs_url"), | ||
pipeline_start_timestamp=ctx.obj.get("pipeline_start_timestamp"), | ||
ci_context=ctx.obj.get("ci_context"), | ||
ci_gcs_credentials=ctx.obj["ci_gcs_credentials"], | ||
python_registry_token=python_registry_token, | ||
registry=registry_url, | ||
package_path=ctx.obj["package_path"], | ||
package_name=publish_name, | ||
version=publish_version, | ||
) | ||
|
||
dagger_client = await click_pipeline_context.get_dagger_client(pipeline_name=f"Publish {ctx.obj['package_path']} to python registry") | ||
context.dagger_client = dagger_client | ||
|
||
if await _has_metadata_yaml(context): | ||
confirm( | ||
"It looks like you are trying to publish a connector. In most cases, the `connectors` command group should be used instead. Do you want to continue?", | ||
abort=True, | ||
) | ||
|
||
publish_result = await PublishToPythonRegistry(context).run() | ||
|
||
return publish_result.status is StepStatus.SUCCESS |
Oops, something went wrong.