/
stage-changelog-for-master.py.j2
51 lines (36 loc) · 1.19 KB
/
stage-changelog-for-master.py.j2
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
39
40
41
42
43
44
45
46
47
48
49
50
51
{% include 'header.j2' %}
import argparse
import os
import textwrap
from git import Repo
helper = textwrap.dedent(
"""\
Stage the changelog for a release on master branch.
Example:
$ python .github/workflows/scripts/stage-changelog-for-master.py 3.4.0
"""
)
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper)
parser.add_argument(
"release_version",
type=str,
help="The version string for the release.",
)
args = parser.parse_args()
release_version_arg = args.release_version
release_path = os.path.dirname(os.path.abspath(__file__))
plugin_path = release_path.split("/.github")[0]
print(f"\n\nRepo path: {plugin_path}")
repo = Repo(plugin_path)
changelog_commit = None
# Look for a commit with the requested release version
for commit in repo.iter_commits():
if f"Building changelog for {release_version_arg}\n" in commit.message:
changelog_commit = commit
break
if not changelog_commit:
raise RuntimeError("Changelog commit for {release_version_arg} was not found.")
git = repo.git
git.checkout("origin/master")
git.cherry_pick(changelog_commit.hexsha)
git.reset("origin/master")