suite-py 1.41.10__py3-none-any.whl → 1.42.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- suite_py/__version__.py +1 -1
- suite_py/cli.py +6 -194
- suite_py/commands/check.py +0 -18
- suite_py/commands/merge_pr.py +1 -12
- suite_py/commands/open_pr.py +1 -6
- suite_py/commands/release.py +2 -248
- suite_py/lib/config.py +0 -1
- suite_py/lib/handler/captainhook_handler.py +0 -7
- suite_py/lib/handler/okta_handler.py +8 -4
- suite_py/lib/metrics.py +1 -1
- suite_py/lib/oauth.py +7 -3
- suite_py/lib/tokens.py +3 -7
- {suite_py-1.41.10.dist-info → suite_py-1.42.0.dist-info}/METADATA +4 -4
- {suite_py-1.41.10.dist-info → suite_py-1.42.0.dist-info}/RECORD +16 -26
- suite_py/commands/aggregator.py +0 -159
- suite_py/commands/batch_job.py +0 -215
- suite_py/commands/deploy.py +0 -207
- suite_py/commands/docker.py +0 -91
- suite_py/commands/generator.py +0 -238
- suite_py/commands/id.py +0 -60
- suite_py/commands/ip.py +0 -68
- suite_py/commands/secret.py +0 -204
- suite_py/lib/handler/drone_handler.py +0 -252
- suite_py/lib/handler/vault_handler.py +0 -28
- {suite_py-1.41.10.dist-info → suite_py-1.42.0.dist-info}/WHEEL +0 -0
- {suite_py-1.41.10.dist-info → suite_py-1.42.0.dist-info}/entry_points.txt +0 -0
suite_py/__version__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
__version__ = "1.
|
|
2
|
+
__version__ = "1.42.0"
|
suite_py/cli.py
CHANGED
|
@@ -53,8 +53,8 @@ from suite_py.lib.tokens import Tokens
|
|
|
53
53
|
|
|
54
54
|
# pylint: enable=wrong-import-position
|
|
55
55
|
|
|
56
|
-
ALLOW_NO_GIT_SUBCOMMAND = ["
|
|
57
|
-
ALLOW_NO_HOME_SUBCOMMAND = ["
|
|
56
|
+
ALLOW_NO_GIT_SUBCOMMAND = ["check", "set-token", "login"]
|
|
57
|
+
ALLOW_NO_HOME_SUBCOMMAND = ["check", "set-token", "login"]
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
def fetch_latest_version() -> Optional[str]:
|
|
@@ -146,12 +146,12 @@ def main(ctx, project, timeout, verbose):
|
|
|
146
146
|
if ctx.invoked_subcommand not in ALLOW_NO_GIT_SUBCOMMAND and not git.is_repo(
|
|
147
147
|
project
|
|
148
148
|
):
|
|
149
|
-
raise
|
|
149
|
+
raise ClickException(f"the folder {project} is not a git repo")
|
|
150
150
|
|
|
151
151
|
if ctx.invoked_subcommand not in ALLOW_NO_HOME_SUBCOMMAND and not os.path.basename(
|
|
152
152
|
project
|
|
153
153
|
) in os.listdir(config.user["projects_home"]):
|
|
154
|
-
raise
|
|
154
|
+
raise ClickException(
|
|
155
155
|
f"the folder {project} is not in {config.user['projects_home']}"
|
|
156
156
|
)
|
|
157
157
|
|
|
@@ -292,67 +292,12 @@ def release():
|
|
|
292
292
|
@release.command(
|
|
293
293
|
"create", help="Create a github release (and deploy it if GHA are used)"
|
|
294
294
|
)
|
|
295
|
-
@click.option(
|
|
296
|
-
"--deploy",
|
|
297
|
-
is_flag=True,
|
|
298
|
-
help="Trigger deploy with Drone CI after release creation (Github Actions based microservices will be automatically deployed on production)",
|
|
299
|
-
)
|
|
300
|
-
@click.pass_obj
|
|
301
|
-
@catch_exceptions
|
|
302
|
-
def cli_release_create(obj, deploy):
|
|
303
|
-
from suite_py.commands.release import Release
|
|
304
|
-
|
|
305
|
-
obj.call(Release, action="create", flags={"deploy": deploy}).run()
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
@release.command("deploy", help="Deploy a github release with Drone CI")
|
|
309
295
|
@click.pass_obj
|
|
310
296
|
@catch_exceptions
|
|
311
|
-
def
|
|
297
|
+
def cli_release_create(obj):
|
|
312
298
|
from suite_py.commands.release import Release
|
|
313
299
|
|
|
314
|
-
obj.call(Release, action="
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
@release.command("rollback", help="Rollback a deployment")
|
|
318
|
-
@click.pass_obj
|
|
319
|
-
@catch_exceptions
|
|
320
|
-
def cli_release_rollback(obj):
|
|
321
|
-
from suite_py.commands.release import Release
|
|
322
|
-
|
|
323
|
-
obj.call(Release, "rollback").run()
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
@main.command("deploy", help="Deploy master branch in production")
|
|
327
|
-
@click.pass_obj
|
|
328
|
-
@catch_exceptions
|
|
329
|
-
def cli_deploy(obj):
|
|
330
|
-
from suite_py.commands.deploy import Deploy
|
|
331
|
-
|
|
332
|
-
obj.call(Deploy).run()
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
@main.group("docker", help="Manage docker images")
|
|
336
|
-
def docker():
|
|
337
|
-
pass
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
@docker.command("release", help="Release new docker image")
|
|
341
|
-
@click.pass_obj
|
|
342
|
-
@catch_exceptions
|
|
343
|
-
def cli_docker_release(obj):
|
|
344
|
-
from suite_py.commands.docker import Docker
|
|
345
|
-
|
|
346
|
-
obj.call(Docker, action="release").run()
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
@docker.command("versions", help="List all available versions of specific image")
|
|
350
|
-
@click.pass_obj
|
|
351
|
-
@catch_exceptions
|
|
352
|
-
def cli_docker_versions(obj):
|
|
353
|
-
from suite_py.commands.docker import Docker
|
|
354
|
-
|
|
355
|
-
obj.call(Docker, action="versions").run()
|
|
300
|
+
obj.call(Release, action="create").run()
|
|
356
301
|
|
|
357
302
|
|
|
358
303
|
@main.command("status", help="Current status of a project")
|
|
@@ -373,75 +318,6 @@ def cli_check(obj):
|
|
|
373
318
|
obj.call(Check).run()
|
|
374
319
|
|
|
375
320
|
|
|
376
|
-
@main.command("id", help="Get the ID of the hosts where the task is running")
|
|
377
|
-
@click.argument("environment", type=click.Choice(("staging", "production")))
|
|
378
|
-
@click.pass_obj
|
|
379
|
-
@catch_exceptions
|
|
380
|
-
def cli_id(obj, environment):
|
|
381
|
-
from suite_py.commands.id import ID
|
|
382
|
-
|
|
383
|
-
obj.call(ID, environment=environment).run()
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
@main.command("ip", help="Get the IP addresses of the hosts where the task is running")
|
|
387
|
-
@click.argument("environment", type=click.Choice(("staging", "production")))
|
|
388
|
-
@click.pass_obj
|
|
389
|
-
@catch_exceptions
|
|
390
|
-
def cli_ip(obj, environment):
|
|
391
|
-
from suite_py.commands.ip import IP
|
|
392
|
-
|
|
393
|
-
obj.call(IP, environment=environment).run()
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
@main.command("generator", help="Generate different files from templates")
|
|
397
|
-
@click.pass_obj
|
|
398
|
-
@catch_exceptions
|
|
399
|
-
def cli_generator(obj):
|
|
400
|
-
from suite_py.commands.generator import Generator
|
|
401
|
-
|
|
402
|
-
obj.call(Generator).run()
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
@main.group(
|
|
406
|
-
"aggregator",
|
|
407
|
-
help="Manage CNAMEs of aggregators in QA envs",
|
|
408
|
-
invoke_without_command=True,
|
|
409
|
-
)
|
|
410
|
-
@click.option(
|
|
411
|
-
"-l", "--list", "show_list", help="deprecated", required=False, count=True
|
|
412
|
-
)
|
|
413
|
-
@click.option("-c", "--change", "change", help="deprecated", required=False, count=True)
|
|
414
|
-
@click.pass_context
|
|
415
|
-
def aggregator(ctx, show_list, change):
|
|
416
|
-
if show_list == 1 or change == 1:
|
|
417
|
-
logger.error(
|
|
418
|
-
"suite-py aggregator [-c|-l] has been hard-deprecated. Use suite-py aggregator [list|change] instead."
|
|
419
|
-
)
|
|
420
|
-
sys.exit(0)
|
|
421
|
-
|
|
422
|
-
if ctx.invoked_subcommand is None:
|
|
423
|
-
logger.error("Missing command. Try suite-py aggregator --help for help.")
|
|
424
|
-
sys.exit(0)
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
@aggregator.command("list", help="List all aggregators with the current record")
|
|
428
|
-
@click.pass_obj
|
|
429
|
-
@catch_exceptions
|
|
430
|
-
def cli_aggregator_list(obj):
|
|
431
|
-
from suite_py.commands.aggregator import Aggregator
|
|
432
|
-
|
|
433
|
-
obj.call(Aggregator, action="list").run()
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
@aggregator.command("change", help="Change aggregator record")
|
|
437
|
-
@click.pass_obj
|
|
438
|
-
@catch_exceptions
|
|
439
|
-
def cli_aggregator_change(obj):
|
|
440
|
-
from suite_py.commands.aggregator import Aggregator
|
|
441
|
-
|
|
442
|
-
obj.call(Aggregator, action="list").run()
|
|
443
|
-
|
|
444
|
-
|
|
445
321
|
@main.command("login", help="manage login against Auth0")
|
|
446
322
|
@click.pass_obj
|
|
447
323
|
@catch_exceptions
|
|
@@ -451,70 +327,6 @@ def login(obj):
|
|
|
451
327
|
obj.call(Login).run()
|
|
452
328
|
|
|
453
329
|
|
|
454
|
-
@main.group(
|
|
455
|
-
"secret", help="Manage secrets grants in multiple countries (aws-vault needed)"
|
|
456
|
-
)
|
|
457
|
-
def secret():
|
|
458
|
-
pass
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
@secret.command("create", help="Create a new secret")
|
|
462
|
-
@click.option("-b", "--base-profile", "base_profile", required=False)
|
|
463
|
-
@click.option("-f", "--secret-file", "secret_file", required=False)
|
|
464
|
-
@click.pass_obj
|
|
465
|
-
@catch_exceptions
|
|
466
|
-
def cli_secret_create(obj, base_profile, secret_file):
|
|
467
|
-
from suite_py.commands.secret import Secret
|
|
468
|
-
|
|
469
|
-
obj.call(
|
|
470
|
-
Secret, action="create", base_profile=base_profile, secret_file=secret_file
|
|
471
|
-
).run()
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
@secret.command("grant", help="Grant permissions to an existing secret")
|
|
475
|
-
@click.option("-b", "--base-profile", "base_profile", required=False)
|
|
476
|
-
@click.option("-f", "--secret-file", "secret_file", required=False)
|
|
477
|
-
@click.pass_obj
|
|
478
|
-
@catch_exceptions
|
|
479
|
-
def cli_secret_grant(obj, base_profile, secret_file):
|
|
480
|
-
from suite_py.commands.secret import Secret
|
|
481
|
-
|
|
482
|
-
obj.call(
|
|
483
|
-
Secret, action="grant", base_profile=base_profile, secret_file=secret_file
|
|
484
|
-
).run()
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
@main.command("batch-job", help="Run batch job on kube")
|
|
488
|
-
@click.argument("environment", type=click.Choice(("staging", "production")))
|
|
489
|
-
@click.option(
|
|
490
|
-
"-c",
|
|
491
|
-
"--cpu",
|
|
492
|
-
"cpu_request",
|
|
493
|
-
required=True,
|
|
494
|
-
type=str,
|
|
495
|
-
help="Millicpu format. E.g: 1000m (=1CPU)",
|
|
496
|
-
)
|
|
497
|
-
@click.option(
|
|
498
|
-
"-m",
|
|
499
|
-
"--memory",
|
|
500
|
-
"memory_request",
|
|
501
|
-
required=True,
|
|
502
|
-
type=str,
|
|
503
|
-
help="Mebibytes or gibibyte format. E.g: 256Mi or 1Gi",
|
|
504
|
-
)
|
|
505
|
-
@click.pass_obj
|
|
506
|
-
@catch_exceptions
|
|
507
|
-
def cli_run_batch_job(obj, environment, cpu_request, memory_request):
|
|
508
|
-
from suite_py.commands.batch_job import BatchJob
|
|
509
|
-
|
|
510
|
-
obj.call(
|
|
511
|
-
BatchJob,
|
|
512
|
-
environment=environment,
|
|
513
|
-
cpu_request=cpu_request,
|
|
514
|
-
memory_request=memory_request,
|
|
515
|
-
).run()
|
|
516
|
-
|
|
517
|
-
|
|
518
330
|
@main.command("set-token", help="Create or update a service token")
|
|
519
331
|
@click.pass_obj
|
|
520
332
|
@catch_exceptions
|
suite_py/commands/check.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from suite_py.lib import logger, metrics
|
|
4
4
|
from suite_py.lib.handler import prompt_utils
|
|
5
|
-
from suite_py.lib.handler.drone_handler import DroneHandler
|
|
6
5
|
from suite_py.lib.handler.github_handler import GithubHandler
|
|
7
6
|
from suite_py.lib.handler.youtrack_handler import YoutrackHandler
|
|
8
7
|
from suite_py.lib.symbol import CHECKMARK, CROSSMARK
|
|
@@ -16,11 +15,9 @@ class Check:
|
|
|
16
15
|
self._youtrack = YoutrackHandler(config, tokens)
|
|
17
16
|
self._github = GithubHandler(tokens)
|
|
18
17
|
self._captainhook = captainhook
|
|
19
|
-
self._drone = DroneHandler(config, tokens)
|
|
20
18
|
|
|
21
19
|
self._checks = [
|
|
22
20
|
("Github", self._check_github),
|
|
23
|
-
("Drone", self._check_drone),
|
|
24
21
|
("Youtrack", self._check_youtrack),
|
|
25
22
|
("CaptainHook", self._check_captainhook),
|
|
26
23
|
("AWS", self._check_aws),
|
|
@@ -52,21 +49,6 @@ class Check:
|
|
|
52
49
|
self._invalid_or_missing_tokens.append("github")
|
|
53
50
|
return "missing_token"
|
|
54
51
|
|
|
55
|
-
def _check_drone(self):
|
|
56
|
-
if self._tokens.drone:
|
|
57
|
-
try:
|
|
58
|
-
drone_user = self._drone.get_user()
|
|
59
|
-
if "message" in drone_user and drone_user["message"] == "Unauthorized":
|
|
60
|
-
self._invalid_or_missing_tokens.append("drone")
|
|
61
|
-
return "invalid_token"
|
|
62
|
-
return "ok"
|
|
63
|
-
except Exception:
|
|
64
|
-
logger.debug("Error connecting to drone", exc_info=True)
|
|
65
|
-
return "unreachable"
|
|
66
|
-
else:
|
|
67
|
-
self._invalid_or_missing_tokens.append("drone")
|
|
68
|
-
return "missing_token"
|
|
69
|
-
|
|
70
52
|
def _check_youtrack(self):
|
|
71
53
|
if self._tokens.youtrack:
|
|
72
54
|
try:
|
suite_py/commands/merge_pr.py
CHANGED
|
@@ -7,7 +7,6 @@ from suite_py.lib import logger, metrics
|
|
|
7
7
|
from suite_py.lib.handler import git_handler as git
|
|
8
8
|
from suite_py.lib.handler import prompt_utils
|
|
9
9
|
from suite_py.lib.handler.captainhook_handler import CaptainHook
|
|
10
|
-
from suite_py.lib.handler.drone_handler import DroneHandler
|
|
11
10
|
from suite_py.lib.handler.git_handler import GitHandler
|
|
12
11
|
from suite_py.lib.handler.github_handler import GithubHandler
|
|
13
12
|
from suite_py.lib.handler.youtrack_handler import YoutrackHandler
|
|
@@ -22,7 +21,6 @@ class MergePR:
|
|
|
22
21
|
self._captainhook = captainhook
|
|
23
22
|
self._git = GitHandler(project, config)
|
|
24
23
|
self._github = GithubHandler(tokens)
|
|
25
|
-
self._drone = DroneHandler(config, tokens, repo=project)
|
|
26
24
|
|
|
27
25
|
@metrics.command("merge-pr")
|
|
28
26
|
def run(self):
|
|
@@ -56,13 +54,6 @@ class MergePR:
|
|
|
56
54
|
|
|
57
55
|
logger.info("Pull request merged on master!")
|
|
58
56
|
|
|
59
|
-
if self._drone.parse_yaml():
|
|
60
|
-
drone_build_number = self._drone.get_pr_build_number(merge_status.sha)
|
|
61
|
-
drone_build_url = self._drone.get_build_url(drone_build_number)
|
|
62
|
-
|
|
63
|
-
if drone_build_url:
|
|
64
|
-
logger.info(f"You can follow the build status at {drone_build_url}")
|
|
65
|
-
|
|
66
57
|
self._git.fetch()
|
|
67
58
|
if self._git.remote_branch_exists(branch_name):
|
|
68
59
|
self._git.delete_remote_branch(branch_name)
|
|
@@ -84,9 +75,7 @@ class MergePR:
|
|
|
84
75
|
logger.warning(
|
|
85
76
|
"There is no YouTrack issue in the branch name or the selected issue does not exist."
|
|
86
77
|
)
|
|
87
|
-
logger.warning(
|
|
88
|
-
"No card updated on YouTrack and no QA turned off automatically"
|
|
89
|
-
)
|
|
78
|
+
logger.warning("No card updated on YouTrack")
|
|
90
79
|
|
|
91
80
|
logger.info("All done!")
|
|
92
81
|
sys.exit()
|
suite_py/commands/open_pr.py
CHANGED
|
@@ -15,7 +15,6 @@ class OpenPR:
|
|
|
15
15
|
self._ask_review = ask_review
|
|
16
16
|
self._project = project
|
|
17
17
|
self._config = config
|
|
18
|
-
self._tokens = tokens
|
|
19
18
|
self._youtrack = YoutrackHandler(config, tokens)
|
|
20
19
|
self._git = GitHandler(project, config)
|
|
21
20
|
self._branch_name = self._git.current_branch_name()
|
|
@@ -25,11 +24,7 @@ class OpenPR:
|
|
|
25
24
|
def run(self):
|
|
26
25
|
if not self._git.remote_branch_exists(self._branch_name):
|
|
27
26
|
logger.warning(f"No branch named {self._branch_name} found on GitHub")
|
|
28
|
-
if prompt_utils.ask_confirm(
|
|
29
|
-
"Do you want to commit all the files and push them?"
|
|
30
|
-
):
|
|
31
|
-
self._git.add()
|
|
32
|
-
self._git.commit("Initial commit")
|
|
27
|
+
if prompt_utils.ask_confirm("Do you want to push your commits to github?"):
|
|
33
28
|
self._git.push(self._branch_name)
|
|
34
29
|
else:
|
|
35
30
|
logger.error("Please, run 'git push' manually")
|
suite_py/commands/release.py
CHANGED
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
import re
|
|
3
3
|
import sys
|
|
4
4
|
|
|
5
|
-
import semver
|
|
6
|
-
from halo import Halo
|
|
7
|
-
|
|
8
5
|
from suite_py.commands import common
|
|
9
6
|
from suite_py.lib import logger, metrics
|
|
10
7
|
from suite_py.lib.handler import git_handler as git
|
|
11
8
|
from suite_py.lib.handler import prompt_utils
|
|
12
9
|
from suite_py.lib.handler.changelog_handler import ChangelogHandler
|
|
13
|
-
from suite_py.lib.handler.drone_handler import DroneHandler
|
|
14
10
|
from suite_py.lib.handler.git_handler import GitHandler
|
|
15
11
|
from suite_py.lib.handler.github_handler import GithubHandler
|
|
16
12
|
from suite_py.lib.handler.version_handler import DEFAULT_VERSION, VersionHandler
|
|
@@ -19,10 +15,9 @@ from suite_py.lib.handler.youtrack_handler import YoutrackHandler
|
|
|
19
15
|
|
|
20
16
|
class Release:
|
|
21
17
|
# pylint: disable=too-many-instance-attributes
|
|
22
|
-
def __init__(self, action, project, captainhook, config, tokens
|
|
18
|
+
def __init__(self, action, project, captainhook, config, tokens):
|
|
23
19
|
self._action = action
|
|
24
20
|
self._project = project
|
|
25
|
-
self._flags = flags
|
|
26
21
|
self._config = config
|
|
27
22
|
self._tokens = tokens
|
|
28
23
|
self._changelog_handler = ChangelogHandler()
|
|
@@ -31,7 +26,6 @@ class Release:
|
|
|
31
26
|
self._github = GithubHandler(tokens)
|
|
32
27
|
self._repo = self._github.get_repo(project)
|
|
33
28
|
self._git = GitHandler(project, config)
|
|
34
|
-
self._drone = DroneHandler(config, tokens, repo=project)
|
|
35
29
|
self._version = VersionHandler(self._repo, self._git, self._github)
|
|
36
30
|
|
|
37
31
|
@metrics.command("release")
|
|
@@ -39,23 +33,8 @@ class Release:
|
|
|
39
33
|
self._stop_if_prod_locked()
|
|
40
34
|
self._git.fetch()
|
|
41
35
|
|
|
42
|
-
if self._flags:
|
|
43
|
-
if self._flags.get("deploy", False):
|
|
44
|
-
|
|
45
|
-
countries = _parse_available_countries(self._drone)
|
|
46
|
-
|
|
47
|
-
if len(countries) == 0:
|
|
48
|
-
logger.error(
|
|
49
|
-
"Can't determine which countries can be deployed. Try to run `suite-py deploy` instead."
|
|
50
|
-
)
|
|
51
|
-
sys.exit(1)
|
|
52
|
-
|
|
53
36
|
if self._action == "create":
|
|
54
37
|
self._create()
|
|
55
|
-
elif self._action == "deploy":
|
|
56
|
-
self._deploy()
|
|
57
|
-
else:
|
|
58
|
-
self._rollback()
|
|
59
38
|
|
|
60
39
|
def _stop_if_prod_locked(self):
|
|
61
40
|
request = self._captainhook.status(self._project, "production")
|
|
@@ -70,13 +49,6 @@ class Release:
|
|
|
70
49
|
)
|
|
71
50
|
sys.exit(-1)
|
|
72
51
|
|
|
73
|
-
def _get_release(self, tag):
|
|
74
|
-
with Halo(text="Loading...", spinner="dots", color="magenta"):
|
|
75
|
-
latest_release = self._github.get_latest_release_if_exists(self._repo)
|
|
76
|
-
if latest_release and latest_release.title == tag:
|
|
77
|
-
return latest_release
|
|
78
|
-
return None
|
|
79
|
-
|
|
80
52
|
def _create(self):
|
|
81
53
|
latest = self._version.get_latest_version()
|
|
82
54
|
|
|
@@ -99,7 +71,7 @@ class Release:
|
|
|
99
71
|
logger.info(f"\nCommits list:\n{message}\n")
|
|
100
72
|
|
|
101
73
|
if not prompt_utils.ask_confirm("Do you want to continue?"):
|
|
102
|
-
|
|
74
|
+
return
|
|
103
75
|
|
|
104
76
|
new_version = self._version.select_new_version(
|
|
105
77
|
latest, allow_prerelease=True
|
|
@@ -135,128 +107,6 @@ class Release:
|
|
|
135
107
|
|
|
136
108
|
self._create_release(new_version, message)
|
|
137
109
|
|
|
138
|
-
if "deploy" in self._flags and self._flags["deploy"]:
|
|
139
|
-
self._deploy(new_version)
|
|
140
|
-
|
|
141
|
-
def _deploy(self, version=""):
|
|
142
|
-
countries = _parse_available_countries(self._drone)
|
|
143
|
-
if len(countries) > 1:
|
|
144
|
-
while True:
|
|
145
|
-
countries = prompt_utils.ask_multiple_choices(
|
|
146
|
-
"Which countries do you want to deploy to?",
|
|
147
|
-
countries,
|
|
148
|
-
)
|
|
149
|
-
if countries:
|
|
150
|
-
break
|
|
151
|
-
logger.warning(
|
|
152
|
-
"You didn't select any country, press SPACEBAR to select countries to deploy to, then press ENTER to confirm!"
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
versions = {}
|
|
156
|
-
|
|
157
|
-
for country in countries:
|
|
158
|
-
versions[country] = {}
|
|
159
|
-
versions[country] = self._get_current_version(country)
|
|
160
|
-
|
|
161
|
-
if self._tags_drifted(versions):
|
|
162
|
-
logger.warning(
|
|
163
|
-
"NOTE: one or more countries runs older tags or tag hasn't been found."
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
if not version:
|
|
167
|
-
releases = self._extract_releases(versions)
|
|
168
|
-
if len(releases) == 0:
|
|
169
|
-
logger.error(f"No new release found for project {self._project}!")
|
|
170
|
-
sys.exit(0)
|
|
171
|
-
|
|
172
|
-
version = prompt_utils.ask_choices(
|
|
173
|
-
"Which version do you want to deploy?",
|
|
174
|
-
[{"name": f"{r.title}", "value": r.title} for r in releases],
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
if not prompt_utils.ask_confirm(
|
|
178
|
-
f"You're about to deploy {self._project} release {version} in {countries}, do you confirm?",
|
|
179
|
-
default=False,
|
|
180
|
-
):
|
|
181
|
-
sys.exit(0)
|
|
182
|
-
|
|
183
|
-
self._start_deploy(version, countries)
|
|
184
|
-
self._manage_youtrack_card(version, countries)
|
|
185
|
-
|
|
186
|
-
def _rollback(self):
|
|
187
|
-
countries = _parse_available_countries(self._drone)
|
|
188
|
-
country = prompt_utils.ask_choices(
|
|
189
|
-
"Which country do you want to rollback?",
|
|
190
|
-
countries,
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
if not country:
|
|
194
|
-
logger.error("You must select at least one country!")
|
|
195
|
-
self._rollback()
|
|
196
|
-
return
|
|
197
|
-
|
|
198
|
-
current = self._get_current_version(country)
|
|
199
|
-
releases = self._get_releases_before(current)
|
|
200
|
-
if not releases:
|
|
201
|
-
logger.error(f"No previous releases found for project {self._project}!")
|
|
202
|
-
sys.exit(-1)
|
|
203
|
-
version = prompt_utils.ask_choices(
|
|
204
|
-
"Which version do you want to roll back to?",
|
|
205
|
-
[{"name": f"{r.tag_name}", "value": r.tag_name} for r in releases],
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
if not prompt_utils.ask_confirm(
|
|
209
|
-
f"You're about to roll back {self._project} to version {version} in {country}, do you confirm?",
|
|
210
|
-
default=False,
|
|
211
|
-
):
|
|
212
|
-
sys.exit(0)
|
|
213
|
-
|
|
214
|
-
self._start_deploy(version, [country], rollback=True)
|
|
215
|
-
|
|
216
|
-
def _get_current_version(self, country):
|
|
217
|
-
try:
|
|
218
|
-
logger.info("Retrieving latest version, this may take some time...")
|
|
219
|
-
# get latest 10 tags
|
|
220
|
-
tags = self._github.get_tags(self._project)
|
|
221
|
-
# exclude tags that don't match semver notation
|
|
222
|
-
semver_tags = [t for t in tags if semver.VersionInfo.isvalid(t.name)][0:9]
|
|
223
|
-
|
|
224
|
-
builds = []
|
|
225
|
-
for tag in semver_tags:
|
|
226
|
-
for b in self._drone.get_builds_from_tag(tag.name):
|
|
227
|
-
if (
|
|
228
|
-
b["event"] == "promote"
|
|
229
|
-
and b["status"] == "success"
|
|
230
|
-
and b["deploy_to"] == f"deploy-{country}-production"
|
|
231
|
-
and "params" in b
|
|
232
|
-
and "DRONE_TAG" in b["params"]
|
|
233
|
-
):
|
|
234
|
-
builds.append(b)
|
|
235
|
-
|
|
236
|
-
if not builds:
|
|
237
|
-
raise Exception(
|
|
238
|
-
"Perhaps there were not any successful builds for latest 10 tags?"
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
# get latest build using build number as key
|
|
242
|
-
current_build = max(builds, key=lambda x: x["number"])
|
|
243
|
-
|
|
244
|
-
if not current_build:
|
|
245
|
-
logger.error(
|
|
246
|
-
f"Unable to determine current version for country {country}"
|
|
247
|
-
)
|
|
248
|
-
sys.exit(255)
|
|
249
|
-
|
|
250
|
-
v = semver.VersionInfo.parse(current_build["params"]["DRONE_TAG"])
|
|
251
|
-
logger.info(f"Current version for country {country}: {v}")
|
|
252
|
-
|
|
253
|
-
return v
|
|
254
|
-
except Exception as e:
|
|
255
|
-
logger.error(
|
|
256
|
-
f"An error has occurred retrieving current version during rollback. {e}\nPlease ask #team-platform-operations for help."
|
|
257
|
-
)
|
|
258
|
-
sys.exit(255)
|
|
259
|
-
|
|
260
110
|
def _create_release(self, new_version, message):
|
|
261
111
|
new_release = self._repo.create_git_release(
|
|
262
112
|
new_version,
|
|
@@ -266,49 +116,6 @@ class Release:
|
|
|
266
116
|
if new_release:
|
|
267
117
|
logger.info(f"The release has been created! Link: {new_release.html_url}")
|
|
268
118
|
|
|
269
|
-
if self._drone.parse_yaml():
|
|
270
|
-
build_number = self._drone.get_build_number_from_tag(new_version)
|
|
271
|
-
if build_number:
|
|
272
|
-
drone_url = self._drone.get_build_url(build_number)
|
|
273
|
-
logger.info(f"You can follow the build status here: {drone_url}")
|
|
274
|
-
|
|
275
|
-
def _start_deploy(self, version, countries, rollback=False):
|
|
276
|
-
for country in countries:
|
|
277
|
-
if rollback:
|
|
278
|
-
promotion = self._drone.promote_production(
|
|
279
|
-
version,
|
|
280
|
-
f"deploy-{country}-production",
|
|
281
|
-
f"DRONE_TAG={version}&ROLLBACK=true",
|
|
282
|
-
)
|
|
283
|
-
else:
|
|
284
|
-
promotion = self._drone.promote_production(
|
|
285
|
-
version,
|
|
286
|
-
f"deploy-{country}-production",
|
|
287
|
-
f"DRONE_TAG={version}",
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
if "number" not in promotion:
|
|
291
|
-
logger.warning(f"Unable to promote drone build. Response: {promotion}")
|
|
292
|
-
return
|
|
293
|
-
|
|
294
|
-
logger.info("Drone build started successfully!")
|
|
295
|
-
logger.info(
|
|
296
|
-
f"You can follow the build status here: {self._drone.get_build_url(promotion['number'])}"
|
|
297
|
-
)
|
|
298
|
-
|
|
299
|
-
if rollback:
|
|
300
|
-
self._post_rollback()
|
|
301
|
-
|
|
302
|
-
def _get_releases_since(self, threshold):
|
|
303
|
-
releases = self._repo.get_releases().get_page(0)
|
|
304
|
-
|
|
305
|
-
return [rel for rel in releases if threshold.compare(rel.tag_name) == -1][0:4]
|
|
306
|
-
|
|
307
|
-
def _get_releases_before(self, threshold):
|
|
308
|
-
releases = self._repo.get_releases().get_page(0)
|
|
309
|
-
|
|
310
|
-
return [rel for rel in releases if threshold.compare(rel.tag_name) == 1][0:4]
|
|
311
|
-
|
|
312
119
|
def _manage_youtrack_card(self, version, countries):
|
|
313
120
|
release_state = self._config.youtrack["release_state"]
|
|
314
121
|
|
|
@@ -368,16 +175,6 @@ class Release:
|
|
|
368
175
|
pass
|
|
369
176
|
return repos_status
|
|
370
177
|
|
|
371
|
-
def _post_rollback(self):
|
|
372
|
-
logger.warning("--- !!!! ---")
|
|
373
|
-
logger.warning("Remember to revert git commit(s) if needed!")
|
|
374
|
-
|
|
375
|
-
if prompt_utils.ask_confirm(
|
|
376
|
-
"Do you want to lock production?",
|
|
377
|
-
default=True,
|
|
378
|
-
):
|
|
379
|
-
self._captainhook.lock_project(self._project, "production")
|
|
380
|
-
|
|
381
178
|
def _tags_drifted(self, versions):
|
|
382
179
|
for country, version in versions.items():
|
|
383
180
|
for c, v in versions.items():
|
|
@@ -387,31 +184,6 @@ class Release:
|
|
|
387
184
|
return True
|
|
388
185
|
return False
|
|
389
186
|
|
|
390
|
-
def _extract_releases(self, versions):
|
|
391
|
-
r = []
|
|
392
|
-
for _, version in versions.items():
|
|
393
|
-
releases = None
|
|
394
|
-
if version:
|
|
395
|
-
releases = self._get_releases_since(version)
|
|
396
|
-
else:
|
|
397
|
-
releases = self._get_releases_since(
|
|
398
|
-
semver.VersionInfo.parse("0.1.0")
|
|
399
|
-
) # default
|
|
400
|
-
|
|
401
|
-
if releases:
|
|
402
|
-
# check if releases already exist in the list, if not: append
|
|
403
|
-
if not self._is_release_duplicated(r, releases):
|
|
404
|
-
r = r + releases
|
|
405
|
-
|
|
406
|
-
return r
|
|
407
|
-
|
|
408
|
-
def _is_release_duplicated(self, current, releases):
|
|
409
|
-
for c in current:
|
|
410
|
-
for rel in releases:
|
|
411
|
-
if c.title == rel.title:
|
|
412
|
-
return True
|
|
413
|
-
return False
|
|
414
|
-
|
|
415
187
|
|
|
416
188
|
def _check_migrations_deploy(commits):
|
|
417
189
|
if not commits:
|
|
@@ -429,21 +201,3 @@ def _check_migrations_deploy(commits):
|
|
|
429
201
|
"Are you sure you want to continue?", default=False
|
|
430
202
|
):
|
|
431
203
|
sys.exit()
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
def _parse_available_countries(drone):
|
|
435
|
-
pipelines = drone.parse_yaml()
|
|
436
|
-
|
|
437
|
-
if pipelines is None:
|
|
438
|
-
logger.error("The file .drone.yml was not found. Unable to continue.")
|
|
439
|
-
sys.exit(1)
|
|
440
|
-
|
|
441
|
-
countries = []
|
|
442
|
-
REGEX = re.compile(r"deploy-([a-z]+)-.*")
|
|
443
|
-
for pipeline in pipelines:
|
|
444
|
-
if "name" in pipeline:
|
|
445
|
-
c = REGEX.findall(pipeline["name"])
|
|
446
|
-
if len(c) > 0 and c[0] is not None and c[0] not in countries:
|
|
447
|
-
countries.append(c[0])
|
|
448
|
-
|
|
449
|
-
return countries
|
suite_py/lib/config.py
CHANGED
|
@@ -40,7 +40,6 @@ class Config:
|
|
|
40
40
|
conf["user"].setdefault("captainhook_timeout", 30)
|
|
41
41
|
conf["user"].setdefault("captainhook_url", "https://captainhook.prima.it")
|
|
42
42
|
conf["user"].setdefault("use_commits_in_pr_body", False)
|
|
43
|
-
conf["user"].setdefault("delete_qa_after_merge", True)
|
|
44
43
|
conf["user"].setdefault("frequent_reviewers_max_number", 5)
|
|
45
44
|
|
|
46
45
|
conf["youtrack"].setdefault("add_reviewers_tags", True)
|