Skip to content

Commit 51fe4e4

Browse files
committed
Update changelog generation
1 parent 8e1a6a5 commit 51fe4e4

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

‎.github/workflows/release.yaml‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,50 @@ jobs:
100100
echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT
101101
echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT
102102
103+
- name: Update changelog
104+
if: steps.version.outputs.is_prerelease == 'false'
105+
env:
106+
VERSION: ${{ steps.version.outputs.version }}
107+
run: |
108+
python3 - <<'EOF'
109+
import os, pathlib, re, subprocess
110+
111+
version = os.environ["VERSION"]
112+
changelog = pathlib.Path("docs/source/changelog.rst")
113+
114+
# Last non-prerelease tag (tags are exactly Major.minor.patch)
115+
tags = subprocess.check_output(
116+
["git", "tag", "-l", "[0-9]*.[0-9]*.[0-9]*", "--sort=-v:refname"],
117+
text=True).strip().splitlines()
118+
if not tags:
119+
print("Error: no previous release tag found")
120+
exit(1)
121+
last_tag = tags[0]
122+
123+
# Commit subjects since the last release, oldest first
124+
subjects = subprocess.check_output(
125+
["git", "log", "--no-merges", "--reverse", "--pretty=format:%s", f"{last_tag}..HEAD"],
126+
text=True).strip().splitlines()
127+
128+
lines = [version, "------", ""]
129+
for s in subjects:
130+
m = re.match(r"^(.*?) \(#(\d+)\)$", s)
131+
if m:
132+
lines.append(f"- {m.group(1)}")
133+
lines.append(f" `# {m.group(2)} https://github.com/xtensor-stack/xtensor/pull/{m.group(2)}`")
134+
else:
135+
lines.append(f"- {s}")
136+
137+
text = changelog.read_text()
138+
marker = "=========\n\n"
139+
head, sep, tail = text.partition(marker)
140+
if not sep:
141+
print("Error: changelog header not found")
142+
exit(1)
143+
changelog.write_text(head + sep + "\n".join(lines) + "\n\n" + tail)
144+
print(f"Added {len(subjects)} commits to changelog for version {version}")
145+
EOF
146+
103147
- name: Update version in header file
104148
run: |
105149
BASE_VERSION="${{ steps.version.outputs.base_version }}"
@@ -113,7 +157,7 @@ jobs:
113157
sed -i "s/^#define XTENSOR_VERSION_PATCH [0-9]*/#define XTENSOR_VERSION_PATCH $NEW_PATCH/" include/xtensor/core/xtensor_config.hpp
114158
115159
git config --local user.name "GitHub Action"
116-
git add include/xtensor/core/xtensor_config.hpp
160+
git add include/xtensor/core/xtensor_config.hpp docs/source/changelog.rst
117161
git commit -m "Release version ${{ steps.version.outputs.version }}"
118162
else
119163
echo "Skipping header file update for prerelease"

0 commit comments

Comments
 (0)