Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions landoscript/src/landoscript/actions/version_bump.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
import logging
import os.path
import re
import typing
from dataclasses import dataclass
from typing import Optional

from gql.transport.exceptions import TransportError
from mozilla_version.gecko import GeckoVersion
Expand All @@ -21,6 +24,7 @@
ALLOWED_BUMP_FILES = (
"browser/config/version.txt",
"browser/config/version_display.txt",
"browser/extensions/newtab/manifest.json",
"config/milestone.txt",
"mobile/android/version.txt",
"mail/config/version.txt",
Expand All @@ -30,8 +34,8 @@

@dataclass(frozen=True)
class VersionBumpInfo:
next_version: str
files: list[str]
next_version: Optional[str] = None


async def run(
Expand Down Expand Up @@ -85,9 +89,17 @@ async def run(
log.info(f"{file}: Version bumping skipped due to unchanged values")
continue

modified = orig.replace(str(cur), str(next_))
if file.endswith(".json"):
modified = re.sub(
r'("version":\s*")' + re.escape(str(cur)) + r'"',
rf'\g<1>{next_}"',
orig,
)
else:
modified = orig.replace(str(cur), str(next_))
if orig == modified:
raise LandoscriptError("file not modified, this should be impossible")
log.warning(f"{file}: version replacement produced no change, skipping")
continue

log.info(f"{file}: successfully bumped! new contents are:")
log_file_contents(modified)
Expand Down Expand Up @@ -119,6 +131,12 @@ def extract_path(diff_text):


def get_cur_and_next_version(filename, orig_contents, next_version, munge_next_version):
if filename.endswith(".json"):
manifest = json.loads(orig_contents)
cur = BaseVersion.parse(manifest["version"])
next_ = cur.bump("minor_number")
return cur, next_

VersionClass: BaseVersion = find_what_version_parser_to_use(filename)
lines = [line for line in orig_contents.splitlines() if line and not line.startswith("#")]
cur = VersionClass.parse(lines[-1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
}
},
"required": [
"next_version",
"files"
]
},
Expand Down
64 changes: 64 additions & 0 deletions landoscript/tests/test_version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,68 @@ def test_no_overlaps_in_version_classes():

def test_all_bump_files_have_version_class():
for bump_file in ALLOWED_BUMP_FILES:
# JSON manifests use BaseVersion directly and bypass the version class lookup
if bump_file.endswith(".json"):
continue
assert any([bump_file.startswith(path) for path in _VERSION_CLASS_PER_BEGINNING_OF_PATH])


MANIFEST_FILE = "browser/extensions/newtab/manifest.json"


def _manifest(version):
import json as _json
return _json.dumps({"manifest_version": 2, "name": "New Tab", "version": version}, indent=2)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"initial_version,expected_version",
[
pytest.param("151.0.0", "151.1.0", id="initial_after_merge_day"),
pytest.param("151.1.0", "151.2.0", id="normal_minor_bump"),
],
)
async def test_json_manifest_bump(aioresponses, github_installation_responses, context, initial_version, expected_version):
payload = {
"actions": ["version_bump"],
"lando_repo": "repo_name",
"version_bump_info": {
"files": [MANIFEST_FILE],
},
}
setup_github_graphql_responses(aioresponses, get_files_payload({MANIFEST_FILE: _manifest(initial_version)}))
await run_test(
aioresponses,
github_installation_responses,
context,
payload,
["version_bump"],
assert_func=lambda req: assert_success(
req,
["Automatic version bump", "NO BUG", "a=release", "CLOSED TREE"],
{MANIFEST_FILE: f' "version": "{initial_version}"'},
{MANIFEST_FILE: f' "version": "{expected_version}"'},
),
)


@pytest.mark.asyncio
async def test_json_manifest_file_not_found(aioresponses, github_installation_responses, context):
payload = {
"actions": ["version_bump"],
"lando_repo": "repo_name",
"version_bump_info": {
"files": [MANIFEST_FILE],
},
}
setup_github_graphql_responses(aioresponses, get_files_payload({MANIFEST_FILE: None}))
await run_test(
aioresponses,
github_installation_responses,
context,
payload,
["version_bump"],
err=LandoscriptError,
errmsg="does not exist",
)