Skip to content

Commit 665065c

Browse files
committed
change bump_version.py per advice from @coderabbitai
1 parent 8d5d2ff commit 665065c

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

.github/workflows/bump_version.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
"""This script automated the release process for all of the packages in this repository.
1+
"""This script automates the release process for all of the packages in this repository.
22
In order, this script does the following:
33
44
1. Bump version number in manifest files according to given required arg (see `--help`).
55
This alters the Cargo.toml in repo root and the package.json files in node-binding.
66
7-
Requires `yarn` (see https://yarnpkg.com) and `napi` (see https://napi.rs) installed
8-
to bump node-binding versions.
7+
Requires `yarn` (see https://yarnpkg.com) and `napi` (see https://napi.rs) to be
8+
installed to bump node-binding versions.
99
1010
2. Updates the CHANGELOG.md
1111
12-
Requires `git-cliff` installed (see https://git-cliff.org)
12+
Requires `git-cliff` (see https://git-cliff.org) to be installed
1313
to regenerate the change logs from git history.
1414
1515
NOTE: `git cliff` uses GITHUB_TOKEN env var to access GitHub's REST API for
@@ -20,14 +20,14 @@
2020
4. Creates a GitHub Release and uses the section from the CHANGELOG about the new tag
2121
as a release description.
2222
23-
Requires `gh-cli` installed (see https://cli.github.com) to create the release and
24-
push the tag.
23+
Requires `gh-cli` (see https://cli.github.com) to be installed to create the release
24+
and push the tag.
2525
2626
NOTE: This step also tags the commit from step 3.
2727
When a tag is pushed to the remote, the CI builds are triggered and
2828
2929
- release assets are uploaded to the Github Release corresponding to the new tag
30-
- packages are published for npm, pip and cargo
30+
- packages are published for npm, pip, and cargo
3131
3232
NOTE: In a CI run, the GH_TOKEN env var to authenticate access.
3333
Locally, you can use `gh login` to interactively authenticate the user account.
@@ -43,7 +43,7 @@
4343
)
4444
VER_REPLACE = 'version = "%d.%d.%d%s" # auto'
4545
COMPONENTS = ("major", "minor", "patch", "rc")
46-
VERSION_LOG = re.compile(rb"^## \[\d+\.\d+\.\d+(?:\-rc)?\d*\]")
46+
VERSION_LOG = re.compile(r"^## \[\d+\.\d+\.\d+(?:\-rc)?\d*\]")
4747

4848

4949
class Updater:
@@ -77,25 +77,25 @@ def replace(match: re.Match[str]) -> str:
7777

7878

7979
def get_release_notes(tag: str = Updater.new_version):
80-
title, buf = ("", b"")
80+
title, buf = "", ""
8181
log_file = Path(__file__).parent.parent.parent / "CHANGELOG.md"
82-
tag_buf = f"[{tag}]".encode(encoding="utf-8")
83-
with open(str(log_file), "rb") as log:
82+
tag_pattern = f"[{tag}]"
83+
with open(str(log_file), "r", encoding="utf-8") as logs:
8484
found_notes = False
85-
for line in log.readlines():
85+
for line in logs:
8686
matched = VERSION_LOG.match(line)
8787
if matched is not None:
88-
if tag_buf in matched.group(0):
89-
title = tag + line[matched.end() :].decode(encoding="utf-8")
88+
if tag_pattern in matched.group(0):
89+
title = tag + line[matched.end() :]
9090
found_notes = True
9191
else:
9292
found_notes = False
93-
elif line.startswith(b"[unreleased]: ") and found_notes:
93+
elif line.startswith("[unreleased]: ") and found_notes:
9494
found_notes = False
9595
elif found_notes:
9696
buf += line
97-
elif line.startswith(tag_buf + b": "):
98-
buf += line.replace(tag_buf, b"Full commit diff", 1)
97+
elif line.startswith(tag_pattern + ": "):
98+
buf += line.replace(tag_pattern, "Full commit diff", 1)
9999
return title.rstrip(), buf.strip()
100100

101101

@@ -133,8 +133,11 @@ def main():
133133
try:
134134
subprocess.run(["git", "push"], check=True)
135135
except subprocess.CalledProcessError as exc:
136-
raise RuntimeError("Failed to push commit for version bump") from exc
137-
136+
raise RuntimeError(
137+
"""Failed to push commit for version bump. Please ensure that
138+
- You have the necessary permissions and are authenticated properly.
139+
- All other commits on the branch have ben pushed already."""
140+
) from exc
138141
title, notes = get_release_notes()
139142
print("Pushed commit to 'Bump version to", tag, "'")
140143
gh_cmd = [
@@ -145,7 +148,7 @@ def main():
145148
"--title",
146149
title,
147150
"--notes",
148-
notes.decode("utf-8"),
151+
notes,
149152
]
150153
if Updater.component == "rc":
151154
gh_cmd.append("--prerelease")

0 commit comments

Comments
 (0)