|
| 1 | +import argparse |
| 2 | +import os |
| 3 | +import textwrap |
| 4 | + |
| 5 | +from git import Repo |
| 6 | + |
| 7 | + |
| 8 | +REDMINE_QUERY_URL = "https://pulp.plan.io/issues?set_filter=1&status_id=*&issue_id=" |
| 9 | +release_path = os.path.dirname(os.path.abspath(__file__)) |
| 10 | +plugin_path = release_path |
| 11 | +if ".travis" in release_path: |
| 12 | + plugin_path = os.path.dirname(release_path) |
| 13 | + |
| 14 | +version = {} |
| 15 | +with open(f"{plugin_path}/pulp_python/__init__.py") as fp: |
| 16 | + version_line = [line for line in fp.readlines() if "__version__" in line][0] |
| 17 | + exec(version_line, version) |
| 18 | +release_version = version["__version__"].replace(".dev", "") |
| 19 | + |
| 20 | +to_close = [] |
| 21 | +for filename in os.listdir(f"{plugin_path}/CHANGES"): |
| 22 | + if filename.split(".")[0].isdigit(): |
| 23 | + to_close.append(filename.split(".")[0]) |
| 24 | +issues = ",".join(to_close) |
| 25 | + |
| 26 | +helper = textwrap.dedent( |
| 27 | + """\ |
| 28 | + Start the release process. |
| 29 | +
|
| 30 | + Example: |
| 31 | + setup.py on plugin before script: |
| 32 | + version="2.0.dev" |
| 33 | + requirements = ["pulpcore>=3.4"] |
| 34 | +
|
| 35 | +
|
| 36 | + $ python .travis/realease.py minor 4.0 4.1 |
| 37 | +
|
| 38 | + setup.py on plugin after script: |
| 39 | + version="2.1.dev" |
| 40 | + requirements = ["pulpcore>=4.0,<4.1"] |
| 41 | +
|
| 42 | + """ |
| 43 | +) |
| 44 | +parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper) |
| 45 | + |
| 46 | +parser.add_argument( |
| 47 | + "release_type", type=str, help="Whether the release should be major, minor or patch.", |
| 48 | +) |
| 49 | + |
| 50 | +parser.add_argument( |
| 51 | + "--lower", type=str, required=False, help="Lower bound of pulpcore requirement.", |
| 52 | +) |
| 53 | + |
| 54 | +parser.add_argument( |
| 55 | + "--upper", type=str, required=False, help="Upper bound of pulpcore requirement.", |
| 56 | +) |
| 57 | + |
| 58 | +args = parser.parse_args() |
| 59 | + |
| 60 | +release_type = args.release_type |
| 61 | + |
| 62 | +if "pulpcore" not in release_path: |
| 63 | + lower_pulpcore_version = args.lower |
| 64 | + upper_pulpcore_version = args.upper |
| 65 | + |
| 66 | +print("\n\nHave you checked the output of: $towncrier --version x.y.z --draft") |
| 67 | +print(f"\n\nRepo path: {plugin_path}") |
| 68 | +repo = Repo(plugin_path) |
| 69 | +git = repo.git |
| 70 | + |
| 71 | +git.checkout("HEAD", b=f"release_{release_version}") |
| 72 | + |
| 73 | +# First commit: changelog |
| 74 | +os.system(f"towncrier --yes --version {release_version}") |
| 75 | +git.add("CHANGES.rst") |
| 76 | +git.add("CHANGES/*") |
| 77 | +git.commit("-m", f"Building changelog for {release_version}\n\n[noissue]") |
| 78 | + |
| 79 | +# Second commit: release version |
| 80 | +with open(f"{plugin_path}/requirements.txt", "rt") as setup_file: |
| 81 | + setup_lines = setup_file.readlines() |
| 82 | + |
| 83 | +with open(f"{plugin_path}/requirements.txt", "wt") as setup_file: |
| 84 | + for line in setup_lines: |
| 85 | + if "pulpcore" in line and "pulpcore" not in release_path: |
| 86 | + line = f"pulpcore>={lower_pulpcore_version},<{upper_pulpcore_version}\n" |
| 87 | + |
| 88 | + setup_file.write(line) |
| 89 | + |
| 90 | +os.system("bump2version release --allow-dirty") |
| 91 | + |
| 92 | +plugin_name = plugin_path.split("/")[-1] |
| 93 | +git.add(f"{plugin_path}/{plugin_name}/__init__.py") |
| 94 | +git.add(f"{plugin_path}/setup.py") |
| 95 | +git.add(f"{plugin_path}/requirements.txt") |
| 96 | +git.add(f"{plugin_path}/.bumpversion.cfg") |
| 97 | +git.commit("-m", f"Releasing {release_version}\n\n[noissue]") |
| 98 | + |
| 99 | +sha = repo.head.object.hexsha |
| 100 | +short_sha = git.rev_parse(sha, short=7) |
| 101 | + |
| 102 | +# Third commit: bump to .dev |
| 103 | +with open(f"{plugin_path}/requirements.txt", "wt") as setup_file: |
| 104 | + for line in setup_lines: |
| 105 | + if "pulpcore" in line and "pulpcore" not in release_path: |
| 106 | + line = f"pulpcore>={lower_pulpcore_version}\n" |
| 107 | + |
| 108 | + setup_file.write(line) |
| 109 | + |
| 110 | +os.system(f"bump2version {release_type} --allow-dirty") |
| 111 | + |
| 112 | +version = {} |
| 113 | +with open(f"{plugin_path}/pulp_python/__init__.py") as fp: |
| 114 | + version_line = [line for line in fp.readlines() if "__version__" in line][0] |
| 115 | + exec(version_line, version) |
| 116 | +new_dev_version = version["__version__"] |
| 117 | + |
| 118 | + |
| 119 | +git.add(f"{plugin_path}/{plugin_name}/__init__.py") |
| 120 | +git.add(f"{plugin_path}/setup.py") |
| 121 | +git.add(f"{plugin_path}/requirements.txt") |
| 122 | +git.add(f"{plugin_path}/.bumpversion.cfg") |
| 123 | +git.commit("-m", f"Bump to {new_dev_version}\n\n[noissue]") |
| 124 | + |
| 125 | +print(f"\n\nRedmine query of issues to close:\n{REDMINE_QUERY_URL}{issues}") |
| 126 | +print(f"Release commit == {short_sha}") |
| 127 | +print(f"All changes were committed on branch: release_{release_version}") |
0 commit comments