-
Notifications
You must be signed in to change notification settings - Fork 1
Add bump, for now as an option #17
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
Open
sebastienbeau
wants to merge
1
commit into
v2
Choose a base branch
from
v2-add-optional-bump
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/usr/bin/env python3 | ||
| # pylint: disable=print-used | ||
|
|
||
| import logging | ||
| import os | ||
|
|
||
| from click_odoo_contrib.update import main | ||
|
|
||
| from odoo import release, sql_db | ||
| from odoo.modules import module | ||
| from odoo.modules.registry import Registry | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
| TOP_MODULE_PATH = "/odoo/local-src/custom_all" | ||
|
|
||
| FAKE_VERSION = f"{release.major_version}.9999.9.9" | ||
|
|
||
| ori_load_information_from_description_file = ( | ||
| module.load_information_from_description_file | ||
| ) | ||
|
|
||
|
|
||
| # As odoo only run migration script when the version change | ||
| # We patch odoo when loading the manifest to increment virtually the version when | ||
| # a "pending" migration script exist | ||
| # The version is always set to the number X.X.9999.9.9 | ||
| # Note: odoo natively support to process the migration in the directory 0.0.0 | ||
| # so we do not need to hack this part | ||
| def load_information_from_description_file(module_name, mod_path=None): | ||
| info = ori_load_information_from_description_file(module_name, mod_path=mod_path) | ||
| if not mod_path: | ||
| mod_path = module.get_module_path(module_name, downloaded=True) | ||
| if "local-src" in mod_path: | ||
| if os.path.exists(f"{mod_path}/migrations/0.0.0"): | ||
| files = os.listdir(f"{mod_path}/migrations/0.0.0") | ||
| if files != [".keep"]: | ||
| # If we have real file in 0.0.0 | ||
| info["version"] = FAKE_VERSION | ||
| return info | ||
|
|
||
|
|
||
| module.load_information_from_description_file = load_information_from_description_file | ||
|
|
||
|
|
||
| # Process before-XXX.sql script in custom_all/migrations/{version}/ | ||
|
|
||
|
|
||
| def add_sql_migration(todo, version): | ||
| path = f"{TOP_MODULE_PATH}/migrations/{version}" | ||
| for filename in os.listdir(path): | ||
| if filename.startswith("before") and filename[-4:] == ".sql": | ||
| file_path = f"{path}/{filename}" | ||
| todo.append((file_path, open(file_path).read())) | ||
|
|
||
|
|
||
| def get_before_request(cr): | ||
| cr.execute("SELECT latest_version FROM ir_module_module WHERE name='custom_all'") | ||
| todo = [] | ||
| db_version = cr.fetchone() | ||
| if not db_version: | ||
| _logger.error("No version found for custom_all, skip begin script") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it misses a |
||
| db_version = db_version[0] | ||
| migr_path = f"{TOP_MODULE_PATH}/migrations" | ||
| if os.path.exists(migr_path): | ||
| versions = os.listdir(migr_path) | ||
| versions.sort() | ||
| if versions and versions[0] == "0.0.0": | ||
| # always run pending version add the end | ||
| versions.append(versions.pop(0)) | ||
| # Run all version that are superior to the db version | ||
| # And run version of 0.0.0 if FAKE_VERSION is not applied | ||
| for version in versions: | ||
| if version > db_version or version == "0.0.0" and FAKE_VERSION > db_version: | ||
| add_sql_migration(todo, version) | ||
| return todo | ||
|
|
||
|
|
||
| ori_new = Registry.new | ||
|
|
||
|
|
||
| @classmethod | ||
| def new(cls, db_name, force_demo=False, status=None, update_module=False): | ||
| conn = sql_db.db_connect(db_name) | ||
| with conn.cursor() as cr: | ||
| for file_path, requests in get_before_request(cr): | ||
| _logger.info( | ||
| "Execute before sql request \n=== %s \n%s===\n", file_path, requests | ||
| ) | ||
| cr.execute(requests) | ||
| return ori_new( | ||
| db_name, force_demo=force_demo, status=status, update_module=update_module | ||
| ) | ||
|
|
||
|
|
||
| Registry.new = new | ||
|
|
||
|
|
||
| # Call native click-odoo-update | ||
|
|
||
| if __name__ == "__main__": # pragma: no cover | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||
| #!/usr/bin/env python3 | ||||||||||||
| # pylint: disable=print-used | ||||||||||||
|
|
||||||||||||
| import ast | ||||||||||||
| import os | ||||||||||||
| import subprocess | ||||||||||||
| from datetime import datetime | ||||||||||||
|
|
||||||||||||
| import click | ||||||||||||
|
|
||||||||||||
| ODOO_VERSION = "14.0" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| @click.command() | ||||||||||||
| def main(): | ||||||||||||
| subprocess.run("git pull", shell=True, check=True) | ||||||||||||
| version = datetime.now().strftime(f"{ODOO_VERSION}.%y%m.%d.0") | ||||||||||||
| with open("odoo/local-src/custom_all/__manifest__.py") as f: | ||||||||||||
| data = ast.literal_eval(f.read()) | ||||||||||||
| last_version = data["version"] | ||||||||||||
|
|
||||||||||||
| # increment last digit if needed | ||||||||||||
| if last_version >= version: | ||||||||||||
| odoo_version, zero, year_month, day, inc = last_version.split(".") | ||||||||||||
| inc = str(int(inc) + 1) | ||||||||||||
| version = ".".join([odoo_version, zero, year_month, day, inc]) | ||||||||||||
|
|
||||||||||||
| # increment modules versions | ||||||||||||
| for module_name in os.listdir("odoo/local-src"): | ||||||||||||
| module_path = f"odoo/local-src/{module_name}" | ||||||||||||
| manifest_path = f"{module_path}/__manifest__.py" | ||||||||||||
| # Check if it's an odoo module | ||||||||||||
| if os.path.exists(manifest_path): | ||||||||||||
| update_version = False | ||||||||||||
| # in case of pending migration script increment it | ||||||||||||
| if os.path.exists(f"{module_path}/migrations/0.0.0"): | ||||||||||||
| files = os.listdir(f"{module_path}/migrations/0.0.0") | ||||||||||||
| if files != [".keep"]: | ||||||||||||
| subprocess.run( | ||||||||||||
| f"mkdir {module_path}/migrations/{version}", | ||||||||||||
| shell=True, | ||||||||||||
| check=True, | ||||||||||||
| ) | ||||||||||||
| subprocess.run( | ||||||||||||
| ( | ||||||||||||
| f"git mv {module_path}/migrations/0.0.0/* " | ||||||||||||
| f"{module_path}/migrations/{version}" | ||||||||||||
| ), | ||||||||||||
| shell=True, | ||||||||||||
| check=True, | ||||||||||||
| ) | ||||||||||||
| update_version = True | ||||||||||||
| if update_version or module_name == "custom_all": | ||||||||||||
| print(f"Update version of {module_name} to {version}") | ||||||||||||
| with open(manifest_path) as f: | ||||||||||||
| raw_data = f.read() | ||||||||||||
| data = ast.literal_eval(raw_data) | ||||||||||||
| with open(manifest_path, "w") as f: | ||||||||||||
| raw_data = raw_data.replace(data["version"], version) | ||||||||||||
| f.write(raw_data) | ||||||||||||
| subprocess.run(f"git add {manifest_path}", shell=True, check=True) | ||||||||||||
|
|
||||||||||||
| subprocess.run(f"git commit -m'Bump version {version}'", shell=True, check=True) | ||||||||||||
| subprocess.run(f"git tag {version}", shell=True, check=True) | ||||||||||||
| subprocess.run("git push origin --tag", shell=True, check=True) | ||||||||||||
| subprocess.run(f"git push origin {ODOO_VERSION}", shell=True, check=True) | ||||||||||||
|
Comment on lines
+64
to
+66
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| if __name__ == "__main__": | ||||||||||||
| main() | ||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add something like :
db_version = db_version and db_version[0] or FalseBecause the result of the sql query is
Noneif custom_all does not exists inir_module_module(which is fine)But it is
(None,)if it exists but is not installed. Which is evaluated asTrueand make the script to fail later.Of course the line
db_version = db_version[0]above should then be removed.@sebastienbeau