|
18 | 18 | ALLOWED_MANIFEST_FILES = ("browser/extensions/newtab/manifest.json",) |
19 | 19 |
|
20 | 20 |
|
21 | | -async def run( |
22 | | - github_client: GithubClient, |
23 | | - public_artifact_dir: str, |
24 | | - branch: str, |
25 | | - info: dict, |
26 | | -) -> list[LandoAction]: |
27 | | - file = info["file"] |
| 21 | +def _validate_file(file: str) -> None: |
28 | 22 | if file not in ALLOWED_MANIFEST_FILES: |
29 | 23 | raise TaskVerificationError(f"{file} is not in extension manifest version bump allowlist") |
30 | 24 |
|
| 25 | + |
| 26 | +async def _fetch_file(github_client: GithubClient, file: str, branch: str) -> str: |
31 | 27 | try: |
32 | 28 | log.info(f"fetching {file} from github") |
33 | 29 | orig_files = await github_client.get_files([file], branch) |
34 | 30 | except TransportError as e: |
35 | 31 | raise LandoscriptError(f"couldn't retrieve {file} from github") from e |
36 | | - |
37 | 32 | orig = orig_files.get(file) |
38 | 33 | if not orig: |
39 | 34 | raise LandoscriptError(f"{file} does not exist!") |
| 35 | + return orig |
40 | 36 |
|
41 | | - log.info(f"{file} contents:") |
42 | | - log_file_contents(orig) |
43 | 37 |
|
| 38 | +def _bump_manifest_version(orig: str, file: str) -> tuple[str, str] | None: |
44 | 39 | manifest = json.loads(orig) |
45 | | - version_str = manifest["version"] |
46 | | - cur = BaseVersion.parse(version_str) |
47 | | - next_ = cur.bump("patch_number") |
48 | | - |
49 | | - log.info(f"{file}: bumping {cur} -> {next_}") |
50 | | - |
| 40 | + cur = BaseVersion.parse(manifest["version"]) |
| 41 | + next_ = cur.bump("minor_number") |
51 | 42 | modified = re.sub( |
52 | 43 | r'("version":\s*")' + re.escape(str(cur)) + r'"', |
53 | 44 | rf'\g<1>{next_}"', |
54 | 45 | orig, |
55 | 46 | ) |
56 | 47 | if orig == modified: |
57 | | - raise LandoscriptError(f"{file}: version replacement produced no change, this should be impossible") |
| 48 | + log.warning(f"{file}: version replacement produced no change, skipping") |
| 49 | + return None |
| 50 | + return modified, str(next_) |
58 | 51 |
|
59 | | - log.info(f"{file}: new contents are:") |
60 | | - log_file_contents(modified) |
61 | 52 |
|
| 53 | +def _build_commit(orig: str, modified: str, file: str, next_version: str, public_artifact_dir: str) -> LandoAction: |
62 | 54 | diff = diff_contents(orig, modified, file) |
63 | | - |
64 | 55 | with open(os.path.join(public_artifact_dir, "extension-manifest-version-bump.diff"), "w+") as f: |
65 | 56 | f.write(diff) |
66 | | - |
67 | 57 | log.info("adding version bump commit! diff contents are:") |
68 | 58 | log_file_contents(diff) |
| 59 | + commitmsg = f"No Bug - Bump newtab manifest.json version to {next_version} a=release CLOSED TREE DONTBUILD" |
| 60 | + return create_commit_action(commitmsg, diff) |
69 | 61 |
|
70 | | - commitmsg = f"No Bug - Bump newtab manifest.json version to {next_} a=release CLOSED TREE DONTBUILD" |
71 | | - return [create_commit_action(commitmsg, diff)] |
| 62 | + |
| 63 | +async def run( |
| 64 | + github_client: GithubClient, |
| 65 | + public_artifact_dir: str, |
| 66 | + branch: str, |
| 67 | + info: dict, |
| 68 | +) -> list[LandoAction]: |
| 69 | + file = info["file"] |
| 70 | + _validate_file(file) |
| 71 | + orig = await _fetch_file(github_client, file, branch) |
| 72 | + log.info(f"{file} contents:") |
| 73 | + log_file_contents(orig) |
| 74 | + result = _bump_manifest_version(orig, file) |
| 75 | + if result is None: |
| 76 | + return [] |
| 77 | + modified, next_version = result |
| 78 | + log.info(f"{file}: bumping to {next_version}") |
| 79 | + log.info(f"{file}: new contents are:") |
| 80 | + log_file_contents(modified) |
| 81 | + return [_build_commit(orig, modified, file, next_version, public_artifact_dir)] |
0 commit comments