Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1786807 - [treescript] Correctly apply esr suffix in version-bump. #1102

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 15 additions & 13 deletions treescript/src/treescript/gecko/versionmanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os

import attr
from mozilla_version.gecko import FirefoxVersion, GeckoVersion, ThunderbirdVersion
from mozilla_version.mobile import MobileVersion

Expand Down Expand Up @@ -79,7 +80,7 @@ async def bump_version(config, task, repo_path):

This function takes its inputs from task by using the ``get_version_bump_info``
function from treescript.task. Using `next_version` and `files`, then
calls do_version_bump to perform the work.
calls do_version_bump to perform the work.1786807

Args:
config (dict): the running config
Expand Down Expand Up @@ -142,23 +143,24 @@ async def do_bump_version(repo_path, files, next_version, source_repo):
next_version = VersionClass.parse(saved_next_version)

try:
is_esr = curr_version.is_esr
curr_is_esr = curr_version.is_esr
next_is_esr = next_version.is_esr
except AttributeError: # Fenix does not expose the is_esr attribute
is_esr = False
curr_is_esr = next_is_esr = False

# XXX In the case of ESR, some files (like version.txt) show version numbers without `esr`
# at the end. next_version is usually provided without `esr` too.
# at the end.
# For release-version-bump, next_version is provided with `esr` by Shipit, wuth
# a list of files to bump. The esr suffix needs to be dropped from files
# that do not have it.
# For merge automation, `create_new_version` will keep the original suffix
# by default, or change it if new_suffix is set for the file. There should
# not be any cases where a suffix needs to be added or removed since create_new_version
# handled it already.
# That's why we do this late minute replacement and why we reset `next_version` at every
# cycle of the loop
if is_esr and not any(
(
next_version.is_esr, # No need to append esr again
# We don't want XX.Ya1esr nor XX.YbNesr
next_version.is_aurora_or_devedition,
next_version.is_beta,
)
):
next_version = VersionClass.parse("{}esr".format(next_version))
if next_is_esr and not curr_is_esr:
next_version = attr.evolve(next_version, is_esr=False)

if next_version < curr_version:
log.warning("Version bumping skipped due to conflicting values: " "(next version {} is < current version {})".format(next_version, curr_version))
Expand Down
49 changes: 24 additions & 25 deletions treescript/tests/test_gecko_versionmanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def config(tmpdir):
yield config_


@pytest.fixture(scope="function", params=("52.5.0", "52.0b3", "# foobar\n52.0a1", "60.1.3esr"))
@pytest.fixture(scope="function", params=("52.5.0", "52.0b3", "# foobar\n52.0a1", "60.1.3"))
def repo_context(tmpdir, config, request, mocker):
context = mocker.MagicMock()
context.repo = os.path.join(tmpdir, "repo")
Expand All @@ -47,9 +47,16 @@ def repo_context(tmpdir, config, request, mocker):
context.xtest_version = [line for line in request.param.splitlines() if not line.startswith("#")][0]
os.mkdir(context.repo)
os.mkdir(os.path.join(context.repo, "config"))
os.makedirs(os.path.join(context.repo, "browser", "config"))
version_file = os.path.join(context.repo, "config", "milestone.txt")
with open(version_file, "w") as f:
f.write(request.param)
display_version_file = os.path.join("browser", "config", "version.txt")
with open(os.path.join(context.repo, display_version_file), "w") as f:
f.write(context.xtest_version)
display_version_file = os.path.join("browser", "config", "version_display.txt")
with open(os.path.join(context.repo, display_version_file), "w") as f:
f.write(context.xtest_version)
yield context


Expand Down Expand Up @@ -92,24 +99,6 @@ def test_find_what_version_parser_to_use(file, source_repo, expectation, expecte
assert vmanip._find_what_version_parser_to_use(file, source_repo) == expected_result


@pytest.mark.asyncio
@pytest.mark.parametrize("new_version, should_append_esr", (("68.0", True), ("68.0b3", False)))
async def test_bump_version(mocker, repo_context, new_version, should_append_esr):
test_version = new_version
if repo_context.xtest_version.endswith("esr") and should_append_esr:
test_version = new_version + "esr"

relative_files = [os.path.join("config", "milestone.txt")]
bump_info = {"files": relative_files, "next_version": new_version}
mocked_bump_info = mocker.patch.object(vmanip, "get_version_bump_info")
mocked_bump_info.return_value = bump_info
vcs_mock = AsyncMock()
mocker.patch.object(vmanip, "vcs", new=vcs_mock)
await vmanip.bump_version(repo_context.config, repo_context.task, repo_context.repo)
assert test_version == vmanip.get_version(relative_files[0], repo_context.repo, "https://hg.mozilla.org/repo")
assert vcs_mock.commit.call_args_list[0][0][2] == "Automatic version bump CLOSED TREE NO BUG a=release"


@pytest.mark.asyncio
@pytest.mark.parametrize("new_version", ("68.0", "68.0b3"))
async def test_bump_version_DONTBUILD_true(mocker, repo_context, new_version):
Expand Down Expand Up @@ -161,6 +150,9 @@ async def test_bump_version_invalid_file(mocker, repo_context, new_version):
@pytest.mark.parametrize("new_version", ("68.0", "68.0b3", "68.9.10esr"))
async def test_bump_version_missing_file(mocker, repo_context, new_version):
# Test only creates config/milestone.txt
remove_file = os.path.join(repo_context.repo, "browser", "config", "version_display.txt")
os.remove(remove_file)

relative_files = [os.path.join("browser", "config", "version_display.txt"), os.path.join("config", "milestone.txt")]
bump_info = {"files": relative_files, "next_version": new_version}
mocked_bump_info = mocker.patch.object(vmanip, "get_version_bump_info")
Expand Down Expand Up @@ -188,10 +180,10 @@ async def test_bump_version_smaller_version(mocker, repo_context, new_version):


@pytest.mark.asyncio
@pytest.mark.parametrize("new_version,expect_version", (("60.2.0", "60.2.0esr"), ("68.0.1", "68.0.1esr"), ("68.9.10esr", "68.9.10esr")))
@pytest.mark.parametrize("new_version,expect_version", (("60.2.0esr", "60.2.0"), ("68.0.1esr", "68.0.1"), ("68.9.10esr", "68.9.10")))
async def test_bump_version_esr(mocker, repo_context, new_version, expect_version):
if not repo_context.xtest_version.endswith("esr"):
# XXX pytest.skip raised exceptions here for some reason.
# XXX pytest.skip raised exceptions here because betas don't turn into esrs
return

relative_files = [os.path.join("config", "milestone.txt")]
Expand All @@ -200,14 +192,21 @@ async def test_bump_version_esr(mocker, repo_context, new_version, expect_versio
mocked_bump_info.return_value = bump_info
vcs_mock = AsyncMock()
mocker.patch.object(vmanip, "vcs", new=vcs_mock)
display_version_file = os.path.join("browser", "config", "version_display.txt")
with open(os.path.join(repo_context.repo, display_version_file), "r+") as f:
f.seek(0, os.SEEK_END)
f.write("esr")

await vmanip.bump_version(repo_context.config, repo_context.task, repo_context.repo)
assert expect_version == vmanip.get_version(relative_files[0], repo_context.repo, "https://hg.mozilla.org/repo")
assert expect_version == vmanip.get_version(relative_files[1], repo_context.repo, "https://hg.mozilla.org/repo")
assert new_version == vmanip.get_version(relative_files[2], repo_context.repo, "https://hg.mozilla.org/repo")
vcs_mock.commit.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.parametrize("new_version,expect_esr_version", (("60.0", "60.0esr"), ("68.0.1", "68.0.1esr")))
async def test_bump_version_esr_dont_bump_non_esr(mocker, config, tmpdir, new_version, expect_esr_version):
@pytest.mark.parametrize("new_version", ("60.0", "68.0.1"))
async def test_bump_version_non_esr(mocker, config, tmpdir, new_version):
version = "52.0.1"
repo = os.path.join(tmpdir, "repo")
os.mkdir(repo)
Expand All @@ -218,7 +217,7 @@ async def test_bump_version_esr_dont_bump_non_esr(mocker, config, tmpdir, new_ve
f.write(version)
display_version_file = os.path.join("browser", "config", "version_display.txt")
with open(os.path.join(repo, display_version_file), "w") as f:
f.write(version + "esr")
f.write(version)

relative_files = [os.path.join("browser", "config", "version_display.txt"), os.path.join("config", "milestone.txt")]
bump_info = {"files": relative_files, "next_version": new_version}
Expand All @@ -232,7 +231,7 @@ async def test_bump_version_esr_dont_bump_non_esr(mocker, config, tmpdir, new_ve
vcs_mock = AsyncMock()
mocker.patch.object(vmanip, "vcs", new=vcs_mock)
await vmanip.bump_version(config, task, repo)
assert expect_esr_version == vmanip.get_version(display_version_file, repo, "https://hg.mozilla.org/repo")
assert new_version == vmanip.get_version(display_version_file, repo, "https://hg.mozilla.org/repo")
assert new_version == vmanip.get_version(version_file, repo, "https://hg.mozilla.org/repo")
vcs_mock.commit.assert_called_once()

Expand Down