|
2 | 2 | # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
|
3 | 3 | #
|
4 | 4 |
|
| 5 | +from typing import TYPE_CHECKING |
| 6 | + |
5 | 7 | import asyncclick as click
|
| 8 | +import semver |
6 | 9 | from pipelines.airbyte_ci.connectors.bump_version.pipeline import run_connector_version_bump_pipeline
|
7 | 10 | from pipelines.airbyte_ci.connectors.context import ConnectorContext
|
8 | 11 | from pipelines.airbyte_ci.connectors.pipeline import run_connectors_pipelines
|
9 | 12 | from pipelines.cli.dagger_pipeline_command import DaggerPipelineCommand
|
10 | 13 |
|
| 14 | +if TYPE_CHECKING: |
| 15 | + from typing import Optional |
| 16 | + |
| 17 | + |
| 18 | +class BumpType(click.ParamType): |
| 19 | + name = "bump-type" |
| 20 | + |
| 21 | + def __init__(self) -> None: |
| 22 | + self.choices = ["patch", "minor", "major"] |
| 23 | + |
| 24 | + def convert(self, value: str, param: Optional[click.Parameter], ctx: Optional[click.Context]) -> str: |
| 25 | + if value in self.choices: |
| 26 | + return value |
| 27 | + if value.startswith("version:"): |
| 28 | + version_str = value.split("version:", 1)[1] |
| 29 | + if semver.VersionInfo.is_valid(version_str): |
| 30 | + return value |
| 31 | + self.fail(f"{value} is not a valid bump type. Valid choices are {self.choices} or 'version:<semver-version>'.", param, ctx) |
| 32 | + |
| 33 | + def __repr__(self) -> str: |
| 34 | + return "BumpType" |
| 35 | + |
11 | 36 |
|
12 | 37 | @click.command(cls=DaggerPipelineCommand, short_help="Bump a connector version and update its changelog.")
|
13 |
| -@click.argument("bump-type", type=click.Choice(["patch", "minor", "major"])) |
| 38 | +@click.argument("bump-type", type=BumpType()) |
14 | 39 | @click.argument("changelog-entry", type=str)
|
15 | 40 | @click.option("--pr-number", type=int, help="Pull request number.")
|
16 | 41 | @click.pass_context
|
|
0 commit comments