forked from python-semantic-release/python-semantic-release
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump_version_in_docs.py
More file actions
38 lines (28 loc) · 1.18 KB
/
bump_version_in_docs.py
File metadata and controls
38 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# ruff: noqa: T201, allow print statements in non-prod scripts
from __future__ import annotations
from os import getenv
from pathlib import Path
from re import compile as RegExp # noqa: N812
PROJ_DIR = Path(__file__).resolve().parent.parent
DOCS_DIR = PROJ_DIR / "docs"
def update_github_actions_example(filepath: Path, new_version: str) -> None:
psr_regex = RegExp(r"(uses:.*python-semantic-release)@v\d+\.\d+\.\d+")
file_content_lines = filepath.read_text().splitlines()
for regex in [psr_regex]:
file_content_lines = list(
map(
lambda line, regex=regex: regex.sub(r"\1@v" + new_version, line),
file_content_lines,
)
)
print(f"Bumping version in {filepath} to", new_version)
filepath.write_text(str.join("\n", file_content_lines) + "\n")
if __name__ == "__main__":
new_version = getenv("NEW_VERSION")
if not new_version:
print("NEW_VERSION environment variable is not set")
exit(1)
update_github_actions_example(DOCS_DIR / "github-action.rst", new_version)
update_github_actions_example(
DOCS_DIR / "automatic-releases" / "github-actions.rst", new_version
)