|
| 1 | +import sys |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +from scripts.pr_check.pr_check import verify_user_can_trigger_build |
| 7 | +from scripts.trigger_auto_tests.main import main |
| 8 | +from scripts.trigger_auto_tests.utils.cli_helpers import PathPath |
| 9 | + |
| 10 | + |
| 11 | +@click.group() |
| 12 | +def cli(): |
| 13 | + pass |
| 14 | + |
| 15 | + |
| 16 | +@cli.command( |
| 17 | + "trigger-auto-tests", |
| 18 | + help="Trigger Automated Tests on TeamCity for specified Shells and changed package", |
| 19 | +) |
| 20 | +@click.option( |
| 21 | + "--supported-shells", |
| 22 | + required=True, |
| 23 | + help='Specify as Shell names divided by ";"', |
| 24 | +) |
| 25 | +@click.option( |
| 26 | + "--automation-project-id", |
| 27 | + required=True, |
| 28 | + help="Project id for the Automated tests", |
| 29 | +) |
| 30 | +@click.option("--package-name", required=True, help="Updated package name") |
| 31 | +@click.option( |
| 32 | + "--package-path", |
| 33 | + required=True, |
| 34 | + type=PathPath(exists=True, file_okay=False), |
| 35 | + help="Path to the updated package", |
| 36 | +) |
| 37 | +@click.option( |
| 38 | + "--package-vcs-url", |
| 39 | + required=True, |
| 40 | + help="URL of the updated package VCS", |
| 41 | +) |
| 42 | +@click.option( |
| 43 | + "--package-commit-id", |
| 44 | + required=True, |
| 45 | + help="Commit id of the updated package that would be used", |
| 46 | +) |
| 47 | +@click.option("--tc-url", required=True, help="TeamCity URL") |
| 48 | +@click.option("--tc-user", required=True, help="TeamCity User") |
| 49 | +@click.option("--tc-password", required=True, help="TeamCity Password") |
| 50 | +def trigger_auto_tests( |
| 51 | + supported_shells: str, |
| 52 | + automation_project_id: str, |
| 53 | + package_name: str, |
| 54 | + package_path: Path, |
| 55 | + package_vcs_url: str, |
| 56 | + package_commit_id: str, |
| 57 | + tc_url: str, |
| 58 | + tc_user: str, |
| 59 | + tc_password: str, |
| 60 | +) -> bool: |
| 61 | + supported_shells = list(map(str.strip, supported_shells.split(";"))) |
| 62 | + is_success = main( |
| 63 | + supported_shells=supported_shells, |
| 64 | + automation_project_id=automation_project_id, |
| 65 | + package_name=package_name, |
| 66 | + package_path=package_path, |
| 67 | + package_vcs_url=package_vcs_url, |
| 68 | + package_commit_id=package_commit_id, |
| 69 | + tc_url=tc_url, |
| 70 | + tc_user=tc_user, |
| 71 | + tc_password=tc_password, |
| 72 | + ) |
| 73 | + if not is_success: |
| 74 | + sys.exit(1) |
| 75 | + return is_success |
| 76 | + |
| 77 | + |
| 78 | +@cli.command( |
| 79 | + "verify-user-can-trigger-build", |
| 80 | + help=( |
| 81 | + "Check that target branch of the PR is in the valid branches and that " |
| 82 | + "author of the PR is a member of the repo organization" |
| 83 | + ), |
| 84 | +) |
| 85 | +@click.option("--vcs-root-url", required=True, help="VCS URL") |
| 86 | +@click.option("--pr-number", required=True, help="PR number") |
| 87 | +@click.option("--target-branch", required=True, help="Target branch of the PR") |
| 88 | +@click.option( |
| 89 | + "--valid-branches", |
| 90 | + default="master", |
| 91 | + show_default=True, |
| 92 | + help=( |
| 93 | + "The target branches for which could be triggered builds. " |
| 94 | + "<branch-name>,<branch-name>" |
| 95 | + ), |
| 96 | +) |
| 97 | +@click.option( |
| 98 | + "--token", |
| 99 | + required=True, |
| 100 | + help=( |
| 101 | + "Token of the user that is a member of the organization, " |
| 102 | + "should be permission 'read:org'" |
| 103 | + ), |
| 104 | +) |
| 105 | +def verify_user_can_trigger( |
| 106 | + vcs_root_url: str, |
| 107 | + pr_number: str, |
| 108 | + target_branch: str, |
| 109 | + valid_branches: str, |
| 110 | + token: str, |
| 111 | +): |
| 112 | + verify_user_can_trigger_build( |
| 113 | + vcs_root_url=vcs_root_url, |
| 114 | + pr_number=pr_number, |
| 115 | + target_branch=target_branch, |
| 116 | + valid_branches=valid_branches, |
| 117 | + token=token, |
| 118 | + ) |
| 119 | + |
| 120 | + |
| 121 | +if __name__ == "__main__": |
| 122 | + cli() |
0 commit comments