diff --git a/docs/firebase-app-distribution/README.md b/docs/firebase-app-distribution/README.md index 37e5ce32..bebb4aae 100644 --- a/docs/firebase-app-distribution/README.md +++ b/docs/firebase-app-distribution/README.md @@ -7,12 +7,16 @@ firebase-app-distribution ### Usage ```bash firebase-app-distribution [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v] - --project-number PROJECT_NUMBER + (--project-id PROJECT_ID | --project-number PROJECT_NUMBER) [--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS] ACTION ``` -### Required arguments for command `firebase-app-distribution` +### Required mutually exclusive arguments for command `firebase-app-distribution` +##### `--project-id=PROJECT_ID` + + +Deprecated on version 0.53.5. Use `--project-number` instead. ##### `--project-number, -p=PROJECT_NUMBER` diff --git a/docs/firebase-app-distribution/get-latest-build-version.md b/docs/firebase-app-distribution/get-latest-build-version.md index cd0f1f73..d6279477 100644 --- a/docs/firebase-app-distribution/get-latest-build-version.md +++ b/docs/firebase-app-distribution/get-latest-build-version.md @@ -7,7 +7,7 @@ get-latest-build-version ### Usage ```bash firebase-app-distribution get-latest-build-version [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v] - --project-number PROJECT_NUMBER + (--project-id PROJECT_ID | --project-number PROJECT_NUMBER) [--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS] --app-id APP_ID ``` @@ -17,8 +17,12 @@ firebase-app-distribution get-latest-build-version [-h] [--log-stream STREAM] [- Application ID in Firebase. For example `1:228333310124:ios:5e439e0d0231a788ac8f09` -### Required arguments for command `firebase-app-distribution` +### Required mutually exclusive arguments for command `firebase-app-distribution` +##### `--project-id=PROJECT_ID` + + +Deprecated on version 0.53.5. Use `--project-number` instead. ##### `--project-number, -p=PROJECT_NUMBER` diff --git a/docs/firebase-app-distribution/releases.md b/docs/firebase-app-distribution/releases.md index feb30828..d4ae353d 100644 --- a/docs/firebase-app-distribution/releases.md +++ b/docs/firebase-app-distribution/releases.md @@ -7,12 +7,16 @@ releases ### Usage ```bash firebase-app-distribution releases [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v] - --project-number PROJECT_NUMBER + (--project-id PROJECT_ID | --project-number PROJECT_NUMBER) [--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS] ACTION ``` -### Required arguments for command `firebase-app-distribution` +### Required mutually exclusive arguments for command `firebase-app-distribution` +##### `--project-id=PROJECT_ID` + + +Deprecated on version 0.53.5. Use `--project-number` instead. ##### `--project-number, -p=PROJECT_NUMBER` diff --git a/docs/firebase-app-distribution/releases/list.md b/docs/firebase-app-distribution/releases/list.md index 82697708..a2ab9e93 100644 --- a/docs/firebase-app-distribution/releases/list.md +++ b/docs/firebase-app-distribution/releases/list.md @@ -7,7 +7,7 @@ list ### Usage ```bash firebase-app-distribution releases list [-h] [--log-stream STREAM] [--no-color] [--version] [-s] [-v] - --project-number PROJECT_NUMBER + (--project-id PROJECT_ID | --project-number PROJECT_NUMBER) [--credentials FIREBASE_SERVICE_ACCOUNT_CREDENTIALS] [--limit LIMIT] [--order-by ORDER_BY] @@ -34,12 +34,16 @@ Sort resources in the specified order. Default: `createTimeDesc` Whether to show the request response in JSON format -### Required arguments for command `firebase-app-distribution` +### Required mutually exclusive arguments for command `firebase-app-distribution` +##### `--project-id=PROJECT_ID` + + +Deprecated on version 0.53.5. Use `--project-number` instead. ##### `--project-number, -p=PROJECT_NUMBER` -Project ID in Firebase. For example `228333310124` +Project Number in Firebase. For example `228333310124` ### Optional arguments for command `firebase-app-distribution` ##### `--credentials, -c=FIREBASE_SERVICE_ACCOUNT_CREDENTIALS` diff --git a/src/codemagic/tools/firebase_app_distribution/arguments.py b/src/codemagic/tools/firebase_app_distribution/arguments.py index 49879d09..829a165a 100644 --- a/src/codemagic/tools/firebase_app_distribution/arguments.py +++ b/src/codemagic/tools/firebase_app_distribution/arguments.py @@ -4,13 +4,24 @@ from .argument_types import CredentialsArgument +select_project_group = cli.MutuallyExclusiveGroup( + name="select project", + required=True, +) + class FirebaseArgument(cli.Argument): + PROJECT_ID = cli.ArgumentProperties( + key="project_id", + flags=("--project-id",), + description=f'Deprecated on version 0.53.5. Use `{Colors.BRIGHT_BLUE("--project-number")}` instead.', + mutually_exclusive_group=select_project_group, + ) PROJECT_NUMBER = cli.ArgumentProperties( key="project_number", flags=("--project-number", "-p"), description=f'Project Number in Firebase. For example `{Colors.WHITE("228333310124")}`', - argparse_kwargs={"required": True}, + mutually_exclusive_group=select_project_group, ) FIREBASE_SERVICE_ACCOUNT_CREDENTIALS = cli.ArgumentProperties( key="credentials", diff --git a/src/codemagic/tools/firebase_app_distribution/firebase_app_distribution.py b/src/codemagic/tools/firebase_app_distribution/firebase_app_distribution.py index ea2c98dd..196ac66f 100644 --- a/src/codemagic/tools/firebase_app_distribution/firebase_app_distribution.py +++ b/src/codemagic/tools/firebase_app_distribution/firebase_app_distribution.py @@ -4,6 +4,7 @@ import argparse from typing import Dict +from typing import Optional from codemagic import cli from codemagic.google.firebase_client import FirebaseClient @@ -13,7 +14,11 @@ from .arguments import FirebaseArgument -@cli.common_arguments(FirebaseArgument.PROJECT_NUMBER, FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS) +@cli.common_arguments( + FirebaseArgument.PROJECT_ID, + FirebaseArgument.PROJECT_NUMBER, + FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS, +) class FirebaseAppDistribution( cli.CliApp, GetLatestBuildVersionAction, @@ -23,13 +28,25 @@ class FirebaseAppDistribution( Utility to list releases and retrieve the latest release build version number from Firebase """ - def __init__(self, credentials: Dict, project_number: str, **kwargs): + def __init__(self, credentials: Dict, project_number: Optional[str], project_id: Optional[str], **kwargs): super().__init__(**kwargs) self.client = FirebaseClient(credentials) + if not project_id and not project_number: + raise FirebaseArgument.PROJECT_NUMBER.raise_argument_error() + self._project_id = project_id self._project_number = project_number @property def project_number(self): + if not self._project_number: + message = ( + "Deprecation warning! " + 'Flag "--project-id" was deprecated in version 0.53.5 ' + "and is subject for removal in future releases. " + 'Use "--project-number" instead.' + ) + self.logger.warning(cli.Colors.YELLOW(message)) + return self._project_id return self._project_number @classmethod @@ -38,13 +55,10 @@ def from_cli_args(cls, cli_args: argparse.Namespace) -> FirebaseAppDistribution: if credentials_argument is None: raise FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS.raise_argument_error() - project_number_argument = FirebaseArgument.PROJECT_NUMBER.from_args(cli_args) - if project_number_argument is None: - raise FirebaseArgument.PROJECT_NUMBER.raise_argument_error() - return FirebaseAppDistribution( credentials_argument.value, - project_number_argument, + FirebaseArgument.PROJECT_NUMBER.from_args(cli_args), + FirebaseArgument.PROJECT_ID.from_args(cli_args), **cls._parent_class_kwargs(cli_args), ) diff --git a/tests/tools/test_firebase_app_distribution.py b/tests/tools/test_firebase_app_distribution.py index 4c9cf91a..1f000ffb 100644 --- a/tests/tools/test_firebase_app_distribution.py +++ b/tests/tools/test_firebase_app_distribution.py @@ -22,6 +22,7 @@ credentials_argument = FirebaseArgument.FIREBASE_SERVICE_ACCOUNT_CREDENTIALS project_number_argument = FirebaseArgument.PROJECT_NUMBER +project_id_argument = FirebaseArgument.PROJECT_ID @pytest.fixture @@ -42,6 +43,7 @@ def namespace_kwargs(): ns_kwargs = { credentials_argument.key: CredentialsArgument('{"type":"service_account"}'), project_number_argument.key: "228333310124", + project_id_argument.key: None, } for arg in FirebaseAppDistribution.CLASS_ARGUMENTS: if not hasattr(arg.type, "environment_variable_key"): @@ -158,7 +160,7 @@ def app_identifier(): @pytest.fixture def firebase_app_distribution(app_identifier): - return FirebaseAppDistribution({"type": "service_account"}, app_identifier.project_id) + return FirebaseAppDistribution({"type": "service_account"}, app_identifier.project_id, None) def test_list_releases(firebase_app_distribution, mock_releases_list, releases, app_identifier):