Skip to content

Commit df196ac

Browse files
authored
Merge pull request camptocamp#19 from simahawk/bumpversion
release.bump: update marabunta file
2 parents 5c17eb9 + 509cc83 commit df196ac

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

odoo_tools/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"pending_merge_rel_path": "pending-merges.d",
2020
# FIXME: will be VERSION?
2121
"version_file_rel_path": "odoo/VERSION",
22+
"marabunta_mig_file_rel_path": "odoo/migration.yml",
2223
}
2324

2425

odoo_tools/release.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import click
77

88
from .config import get_conf_key
9+
from .utils import yaml
910
from .utils.os_exec import run
11+
from .utils.path import build_path
1012

1113

1214
def parse_bumpversion_cfg(ini_content):
@@ -38,6 +40,37 @@ def make_towncrier_cmd(version):
3840
return "towncrier build --yes --version={}".format(version)
3941

4042

43+
class MarabuntFileHandler:
44+
def __init__(self, path_obj):
45+
self.path_obj = path_obj
46+
47+
def load(self):
48+
return yaml.yaml_load(self.path_obj.open())
49+
50+
def update(self, version, run_click_hook="pre"):
51+
data = self.load()
52+
versions = data["migration"]["versions"]
53+
version_item = [x for x in versions if x["version"] == version]
54+
if not version_item:
55+
version_item = {"version": version}
56+
versions.append(version_item)
57+
if not version_item.get("operations"):
58+
version_item["operations"] = {}
59+
operations = version_item["operations"]
60+
cmd = self._make_click_odoo_update_cmd()
61+
operations.setdefault(run_click_hook, []).append(cmd)
62+
yaml.update_yml_file(self.path_obj, data)
63+
64+
def _make_click_odoo_update_cmd(self):
65+
return "click-odoo-update"
66+
67+
68+
def update_marabunta_file(version):
69+
marabunta_file = build_path(get_conf_key("marabunta_mig_file_rel_path"))
70+
handler = MarabuntFileHandler(marabunta_file)
71+
handler.update(version)
72+
73+
4174
@click.group()
4275
def cli():
4376
pass
@@ -65,6 +98,8 @@ def bump(rel_type, new_version=None, dry_run=False, commit=False):
6598
cmd = make_towncrier_cmd(new_version)
6699
click.echo(f"Running: {cmd}")
67100
run(cmd)
101+
click.echo("Updating marabunta migration file")
102+
update_marabunta_file(new_version)
68103

69104

70105
if __name__ == '__main__':

tests/common.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def make_fake_project_root(
4949
marker_file=get_root_marker(),
5050
req_file="requirements.txt",
5151
proj_version="14.0.0.1.0",
52+
mock_marabunta_file=False,
5253
):
5354
data = FAKE_MANIFEST_DATA.copy()
5455
data.update(manifest or {})
@@ -66,6 +67,18 @@ def make_fake_project_root(
6667
with ver_file.open("w") as fd:
6768
fd.write(proj_version)
6869

70+
if mock_marabunta_file:
71+
fake_marabunta_file()
72+
73+
74+
def fake_marabunta_file(source_file_path=None):
75+
source_file_path = source_file_path or get_fixture_path("fake-marabunta.yml")
76+
if not os.path.exists("odoo"):
77+
os.mkdir("odoo")
78+
with source_file_path.open() as fd_source:
79+
with get_conf_key("marabunta_mig_file_rel_path").open("w") as fd_dest:
80+
fd_dest.write(fd_source.read())
81+
6982

7083
@contextmanager
7184
def fake_project_root(make_root=True, **kw):

tests/fixtures/fake-marabunta.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
migration:
2+
versions:
3+
- version: setup
4+
addons:
5+
upgrade:
6+
- foo
7+
- baz
8+
- version: 14.0.0.1.0

tests/test_release.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def test_make_towncrier_cmd():
2727

2828
def test_bump():
2929
ver_file = get_conf_key("version_file_rel_path")
30-
with fake_project_root(proj_version="14.0.0.1.0") as runner:
30+
with fake_project_root(
31+
proj_version="14.0.0.1.0", mock_marabunta_file=True
32+
) as runner:
3133
with ver_file.open() as fd:
3234
assert fd.read() == "14.0.0.1.0"
3335
# run init to get all files ready (eg: bumpversion)
@@ -67,7 +69,9 @@ def test_bump():
6769

6870

6971
def test_bump_changelog():
70-
with fake_project_root(proj_version="14.0.0.1.0") as runner:
72+
with fake_project_root(
73+
proj_version="14.0.0.1.0", mock_marabunta_file=True
74+
) as runner:
7175
# run init to get all files ready (eg: bumpversion)
7276
runner.invoke(init, catch_exceptions=False)
7377
changes = (
@@ -96,5 +100,28 @@ def test_bump_changelog():
96100
assert result.output.splitlines() == [
97101
"Running: bumpversion minor",
98102
"Running: towncrier build --yes --version=14.0.0.2.0",
103+
"Updating marabunta migration file",
104+
]
105+
assert result.exit_code == 0
106+
107+
108+
def test_bump_update_marabunta_file():
109+
with fake_project_root(
110+
proj_version="14.0.0.1.0", mock_marabunta_file=True
111+
) as runner:
112+
# run init to get all files ready (eg: bumpversion)
113+
runner.invoke(init, catch_exceptions=False)
114+
result = runner.invoke(
115+
release.bump, ["--type", "minor"], catch_exceptions=False
116+
)
117+
with get_conf_key("marabunta_mig_file_rel_path").open() as fd:
118+
content = fd.read()
119+
# TODO: improve these checks
120+
assert "14.0.0.2.0" in content
121+
assert "click-odoo-update" in content
122+
assert result.output.splitlines() == [
123+
"Running: bumpversion minor",
124+
"Running: towncrier build --yes --version=14.0.0.2.0",
125+
"Updating marabunta migration file",
99126
]
100127
assert result.exit_code == 0

0 commit comments

Comments
 (0)