Skip to content

Commit 964a652

Browse files
committed
chore(build-conf): automate version update in docs
1 parent 0ffc14a commit 964a652

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

releaserc.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[semantic_release]
2+
assets = ["README.md", "LICENSE"]
3+
build_command = """python3 ./scripts/bump_version.py"""
24
commit_parser = "angular"
35

46
[semantic_release.changelog]

scripts/bump_version.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
from pathlib import Path
4+
from re import compile as RegExp
5+
from os import getenv
6+
7+
PROJ_DIR = Path(__file__).resolve().parent.parent
8+
README_FILE = PROJ_DIR / "README.md"
9+
10+
psr_regex = RegExp(r"(uses:.*python-semantic-release)@v\d+\.\d+\.\d+")
11+
uploader_action_regex = RegExp(r"(uses:.*upload-to-gh-release)@v\d+\.\d+\.\d+")
12+
new_version = getenv("NEW_VERSION")
13+
14+
if not new_version:
15+
print("NEW_VERSION environment variable is not set")
16+
exit(1)
17+
18+
readme_lines = README_FILE.read_text().splitlines()
19+
20+
for regex in [psr_regex, uploader_action_regex]:
21+
readme_lines = list(map(
22+
lambda line, regex=regex: regex.sub(r'\1@v'+new_version, line),
23+
readme_lines
24+
))
25+
26+
print("Bumping version in readme to", new_version)
27+
README_FILE.write_text(str.join("\n", readme_lines) + '\n')

0 commit comments

Comments
 (0)