|
3 | 3 | import sys |
4 | 4 | import zipfile |
5 | 5 | from pathlib import Path |
6 | | -from time import sleep |
7 | 6 |
|
8 | 7 | from invoke import Context, Exit, task |
9 | 8 |
|
10 | 9 | from tasks.libs.ciproviders.github_api import GithubAPI |
11 | 10 | from tasks.libs.common.color import Color, color_message |
12 | 11 | from tasks.libs.common.go import download_go_dependencies |
| 12 | +from tasks.libs.common.retry import run_command_with_retry |
13 | 13 | from tasks.libs.common.utils import environ, get_gobin, gitlab_section, link_or_copy |
14 | 14 |
|
15 | 15 | TOOL_LIST = [ |
@@ -58,37 +58,11 @@ def install_tools(ctx: Context, max_retry: int = 3): |
58 | 58 | env['CC'] = os.getenv('DD_CC') |
59 | 59 | if os.getenv('DD_CXX'): |
60 | 60 | env['CXX'] = os.getenv('DD_CXX') |
61 | | - |
62 | | - pending = [(path, tool) for path, tools in TOOLS.items() for tool in tools] |
63 | | - for attempt in range(max_retry): |
64 | | - last = attempt == max_retry - 1 |
65 | | - |
66 | | - # Start all pending installs in parallel |
67 | | - promises = [] |
68 | | - for path, tool in pending: |
| 61 | + with environ(env): |
| 62 | + for path, tools in TOOLS.items(): |
69 | 63 | with ctx.cd(path): |
70 | | - promise = ctx.run(f"go install {tool}", asynchronous=True, warn=not last, env=env) |
71 | | - promises.append((path, tool, promise)) |
72 | | - |
73 | | - # Collect failures |
74 | | - pending = [] |
75 | | - for path, tool, promise in promises: |
76 | | - result = promise.join() |
77 | | - if result.exited is None or result.exited > 0: |
78 | | - pending.append((path, tool)) |
79 | | - |
80 | | - if pending and not last: |
81 | | - wait = 10**attempt |
82 | | - failed_names = [tool.rsplit('/', 1)[-1] for _, tool in pending] |
83 | | - print( |
84 | | - f"[{attempt + 1} / {max_retry}] {len(pending)} tool(s) failed, retrying in {wait}s: {failed_names}" |
85 | | - ) |
86 | | - sleep(wait) |
87 | | - |
88 | | - if pending: |
89 | | - failed_list = '\n'.join(f" {path}: {tool}" for path, tool in pending) |
90 | | - raise Exit(f"Failed to install tools:\n{failed_list}", code=1) |
91 | | - |
| 64 | + for tool in tools: |
| 65 | + run_command_with_retry(ctx, f"go install {tool}", max_retry=max_retry) |
92 | 66 | for bazelisk in Path(get_gobin(ctx)).glob('bazelisk*'): |
93 | 67 | link_or_copy(bazelisk, bazelisk.with_stem(bazelisk.stem.replace('isk', ''))) |
94 | 68 |
|
|
0 commit comments