|
4 | 4 | # Copyright (c) CERN, 2024. # |
5 | 5 | # ######################################### # |
6 | 6 |
|
7 | | -import sys |
8 | | -import platform |
9 | | -from gh import * |
| 7 | +from xaux.tools import dev_make_release_branch |
10 | 8 | # sys.tracebacklimit = 0 |
11 | 9 |
|
12 | | -class VersionError(OSError): |
13 | | - pass |
14 | | - |
15 | | - |
16 | | -# Check necessary setup and installs |
17 | | -assert_git_repo() |
18 | | -assert_poetry_installed() |
19 | | - |
20 | | - |
21 | | -# Check the script arguments |
22 | | -if len(sys.argv) != 2: |
23 | | - raise ValueError("This script needs exactly one argument: the new version number or a bump. " |
24 | | - "The latter can be: patch, minor, major.") |
25 | | -bump = sys.argv[1] |
26 | | - |
27 | | - |
28 | | -# Check our working directory is clean |
29 | | -git_assert_working_tree_clean() |
30 | | -branch = git_current_branch() |
31 | | -if branch != "main": |
32 | | - raise GitError("This script needs to be ran on the main branch.") |
33 | | -git_push() # Sync with the remote to be sure we don't delete an incomplete branch later |
34 | | -git_pull() |
35 | | -expected_ver = poetry_get_expected_version(bump) |
36 | | - |
37 | | - |
38 | | -# Check that we are not accidentally bumping a major version |
39 | | -major_ver = int(expected_ver.split('.')[0]) |
40 | | -if major_ver != 0: |
41 | | - raise VersionError("Bumping a major version! If this is really what you want, " |
42 | | - "then adapt make_release_branch.py manually.") |
43 | | - |
44 | | - |
45 | | -# Confirm version bump |
46 | | -branch = f"release/v{expected_ver}" |
47 | | -expected_ver = f"{expected_ver}rc0" |
48 | | -current_ver = poetry_get_version() |
49 | | -print(f"Bumping from {current_ver} to {expected_ver}.") |
50 | | -print("Type y to continue (or anything else to cancel):") |
51 | | -answer = input() |
52 | | -if answer not in ["y", "Y"]: |
53 | | - print("Cancelled.") |
54 | | - sys.exit(1) |
55 | | - |
56 | | - |
57 | | -# Create release branch |
58 | | -print("Creating release branch...") |
59 | | -git_switch(branch, create=True) |
60 | | - |
61 | | - |
62 | | -# Update version in the release branch |
63 | | -print("Poetry version bump...") |
64 | | -poetry_bump_version(expected_ver) |
65 | | -new_ver = poetry_get_version() |
66 | | -if new_ver != expected_ver: |
67 | | - raise VersionError(f"Fatal error: `poetry --dry-run` expected {expected_ver}, but result is {new_ver}..." |
68 | | - "Need to recover manually!") |
69 | | - |
70 | | - |
71 | | -# Adapt version files |
72 | | -for file, pattern in zip(["xcoll/general.py", "tests/test_version.py"], |
73 | | - ["__version__ = ", " assert __version__ == "]): |
74 | | - file_adapted = False |
75 | | - with Path(file).open("r") as fid: |
76 | | - lines = fid.readlines() |
77 | | - with Path(file).open("w") as fid: |
78 | | - for line in lines: |
79 | | - if line.startswith(pattern): |
80 | | - fid.write(f"{pattern}'{new_ver}'\n") |
81 | | - file_adapted = True |
82 | | - else: |
83 | | - fid.write(line) |
84 | | - if not file_adapted: |
85 | | - raise VersionError(f"Fatal error: could not adapt {file}...") |
86 | | - |
87 | | - |
88 | | -# Commit and push |
89 | | -git_add(['pyproject.toml', 'xcoll/general.py', 'tests/test_version.py']) |
90 | | -git_commit(f"Created release branch release/v{new_ver}.", no_verify=True) |
91 | | -git_push(set_upstream=True) |
92 | | - |
93 | | -print("All done!") |
94 | 10 |
|
| 11 | +dev_make_release_branch("xcoll") |
0 commit comments