Skip to content

Commit 0f4c457

Browse files
author
Martin Møldrup
committed
Try to fix issue with reading changelog for specific version
1 parent ecaf481 commit 0f4c457

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

.github/workflows/release.yaml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,17 @@ jobs:
7272
steps:
7373
- uses: actions/checkout@v2
7474

75-
- name: Read Changelog
76-
id: changelog
75+
- name: Set up Python
76+
uses: actions/setup-python@v4
77+
with:
78+
python-version: "3.12"
79+
80+
- name: Get changelog and add to variable
7781
run: |
78-
if [ ! -f "CHANGELOG.md" ]; then
79-
echo "CHANGELOG.md file not found."
80-
exit 1
81-
fi
82-
CHANGELOG=$(awk '/^## \['${{ needs.details.outputs.new_version }}'\]/,/^## \[/' CHANGELOG.md | sed '1d;$d')
83-
if [ -z "$CHANGELOG" ]; then
84-
echo "Changelog for version ${{ needs.details.outputs.new_version }} not found."
85-
exit 1
86-
fi
87-
echo "Changelog read as: $CHANGELOG"
88-
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
82+
python scripts/read_changelog.py ${{ needs.details.outputs.new_version }} > specific_changelog.md
83+
echo "Changelog for ${{ needs.details.outputs.new_version }}:"
84+
cat specific_changelog.md
85+
echo "CHANGELOG=$(cat specific_changelog.md)" >> $GITHUB_ENV
8986
9087
setup_and_build:
9188
needs: [details, check_pypi]

scripts/get_changelog.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Python script for getting the change log entry from the CHANGELOG.md file."""
2+
import re
3+
import pathlib
4+
import argparse
5+
6+
parser = argparse.ArgumentParser(description="Get the change log entry for a version.")
7+
parser.add_argument("version", help="The version to get the change log entry for.")
8+
args = parser.parse_args()
9+
10+
version = args.version
11+
if not version:
12+
raise ValueError("No version provided.")
13+
14+
path = pathlib.Path(__file__).parent.parent.parent / "CHANGELOG.md"
15+
with path.open("r", encoding="utf-8") as file:
16+
lines = file.readlines()
17+
18+
version_str = f"## [{version}]"
19+
version_str_next = f"## ["
20+
change_log = []
21+
found = False
22+
for line in lines:
23+
if found:
24+
if line.startswith(version_str_next):
25+
break
26+
change_log.append(line)
27+
if line.startswith(version_str):
28+
found = True
29+
30+
if not change_log:
31+
raise ValueError(f"Version {version} not found in change log.")
32+
33+
print("".join(change_log))

0 commit comments

Comments
 (0)