Skip to content

Commit d545e9b

Browse files
committed
Add a partial changelog when releasing
1 parent 9b4db1e commit d545e9b

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

.github/workflows/post-release-mergeback.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,24 @@ jobs:
151151
--assignee "${GITHUB_ACTOR}" \
152152
--draft
153153
154+
155+
- name: Prepare the partial Changelog
156+
env:
157+
VERSION: "${{ steps.getVersion.outputs.version }}"
158+
PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md"
159+
run: |
160+
# Prepare the partial changelog for the release notes
161+
python .github/workflows/script/prepare_changelog.py CHANGELOG.md "$VERSION"> $PARTIAL_CHANGELOG
162+
154163
- name: Create the GitHub release
155164
env:
156165
VERSION: "${{ steps.getVersion.outputs.version }}"
166+
PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md"
167+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157168
run: |
158169
# Do not mark this release as latest. The most recent CLI release must be marked as latest.
159170
gh release create \
160-
"${VERSION}" \
171+
"$VERSION" \
161172
--latest=false \
162-
-t "${VERSION}" \
163-
-F CHANGELOG.md
173+
-t "$VERSION" \
174+
-F "$PARTIAL_CHANGELOG"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
4+
EMPTY_CHANGELOG = 'No changes.\n\n'
5+
6+
# Prepare the changelog for the new release
7+
# This function will extract the part of the changelog that
8+
# we want to include in the new release.
9+
def extract_changelog_snippet(changelog_file, version_tag):
10+
output = ''
11+
if (not os.path.exists(changelog_file)):
12+
output = EMPTY_CHANGELOG
13+
14+
else:
15+
with open('CHANGELOG.md', 'r') as f:
16+
lines = f.readlines()
17+
18+
# Include everything up to, but excluding the second heading
19+
found_first_section = False
20+
for i, line in enumerate(lines):
21+
if line.startswith('## '):
22+
if found_first_section:
23+
break
24+
found_first_section = True
25+
output += line
26+
27+
output += f"See the full [CHANGELOG.md](https://github.com/github/codeql-action/blob/{version_tag}/CHANGELOG.md) for more information."
28+
29+
return output
30+
31+
32+
if len(sys.argv) < 3:
33+
raise Exception('Expecting argument: changelog_file version_tag')
34+
changelog_file = sys.argv[1]
35+
version_tag = sys.argv[2]
36+
37+
print(extract_changelog_snippet(changelog_file, version_tag))

0 commit comments

Comments
 (0)