Skip to content

Commit 9a05a01

Browse files
committed
initial
1 parent b21f967 commit 9a05a01

27 files changed

Lines changed: 479 additions & 134 deletions

.pre-commit-config.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v2.7.4
4+
hooks:
5+
- id: pyupgrade
26
- repo: https://github.com/timothycrosley/isort
3-
rev: 5.6.4
7+
rev: 5.7.0
48
hooks:
59
- id: isort
6-
language_version: python3.7
7-
exclude: '/mibs'
810
- repo: https://github.com/python/black
911
rev: 20.8b1
1012
hooks:
1113
- id: black
12-
language_version: python3.7
13-
exclude: '/mibs'
1414
- repo: https://gitlab.com/pycqa/flake8
1515
rev: 3.8.4
1616
hooks:
@@ -22,5 +22,3 @@ repos:
2222
flake8-print,
2323
flake8-eradicate,
2424
]
25-
language_version: python3.7
26-
exclude: '/mibs'

README.md

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,6 @@
1-
# CloudShell package repo template
1+
# CloudShell TeamCity scripts
22

3-
[![Build status](https://github.com/QualiSystems/cloudshell-package-repo-template/workflows/CI/badge.svg?branch=master)](https://github.com/QualiSystems/cloudshell-package-repo-template/actions?query=branch%3Amaster)
4-
[![codecov](https://codecov.io/gh/QualiSystems/cloudshell-package-repo-template/branch/dev/graph/badge.svg)](https://codecov.io/gh/QualiSystems/cloudshell-package-repo-template)
3+
[![Build status](https://github.com/QualiSystems/cloudshell-tc-scripts/workflows/CI/badge.svg?branch=master)](https://github.com/QualiSystems/cloudshell-tc-scripts/actions?query=branch%3Amaster)
4+
[![codecov](https://codecov.io/gh/QualiSystems/cloudshell-tc-scripts/branch/master/graph/badge.svg)](https://codecov.io/gh/QualiSystems/cloudshell-tc-scripts)
55
[![PyPI version](https://badge.fury.io/py/cloudshell-template.svg)](https://badge.fury.io/py/cloudshell-template)
66
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
7-
8-
Use this template to create new shell packages.
9-
10-
## Description of services
11-
### tox
12-
[tox](https://pypi.org/project/tox/) is an open source tool we use to run tests in multiple virtual environments.
13-
* To run all tests described in tox.ini, just run `tox`.
14-
* To run a particular env use `tox -e env_name`.
15-
16-
### pre-commit
17-
[pre-commit](https://pypi.org/project/pre-commit/) is an open source library we use to manage pre-commit hooks.
18-
* Run all code linters with a command `pre-commit run --all-files`.
19-
* Add git hook with command `pre-commit install`.
20-
* To update versions of pre-commit hooks in config file run `pre-commit autoupdate`
21-
22-
We use these hooks:
23-
* **isort** sorts imports (config in tox.ini)
24-
* **black** reformats code to one style (config in pyproject.toml)
25-
* **flake8** checks code style (config in tox.ini). We use these plugins:
26-
* `flake8-docstring` to check docstrings
27-
* `flake8-builtins` to avoid using builtins as variable names
28-
* `flake8-comprehensions` to check list/dict comprehensions
29-
* `flake8-print` to ensure we don't leave prints in the code
30-
* `flake8-eradicate` to ensure we don't leave commented lines in the code
31-
32-
## Installation
33-
34-
### tox.ini
35-
* Set the `package-name` var regarding your package.
36-
* Set the python version in envlist.
37-
38-
### .travis.yml
39-
* Set the python version regarding tox.ini.
40-
41-
### pyproject.toml
42-
* Set the python version for black.
43-
44-
### setup.py
45-
* Set a name and description for the package.
46-
* Set the python version of the shell.
47-
48-
### README.md
49-
* Update links for build, coverage etc.
50-
* Add the line to README
51-
We use tox and pre-commit for testing. [Services description](https://github.com/QualiSystems/cloudshell-package-repo-template#description-of-services)

cloudshell/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

cloudshell/template/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

cloudshell/template/package.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pre-commit
22
tox
33
-r test_requirements.txt
4-
-r requirements.txt
4+
.

pyproject.toml

Lines changed: 0 additions & 17 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/__init__.py

Whitespace-only changes.

scripts/cli.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

Comments
 (0)