Skip to content

Commit a9b274e

Browse files
authored
ci: Automatically extract release notes for GitHub Releases (kedro-org#212)
* ci: Automatically extract release notes Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com> * fix lint Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com> * Raise exceptions Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com> * Lint Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com> * Lint Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com> --------- Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
1 parent 4570cb0 commit a9b274e

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

.github/workflows/check-release.yml

+13-16
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,21 @@ jobs:
5656
run: |
5757
export plugin=${{ needs.check-version.outputs.package_name }}
5858
make package
59+
- name: Extract release notes from ${{needs.check-version.outputs.package_name}}/RELEASE.md
60+
id: extract
61+
run: |
62+
python tools/github_actions/extract_release_notes.py \
63+
"${{needs.check-version.outputs.package_name}}/RELEASE.md" \
64+
"Release ${{needs.check-version.outputs.package_version}}"
5965
- name: Create GitHub Release
60-
uses: actions/github-script@v6
66+
uses: softprops/action-gh-release@v1
6167
with:
62-
github-token: ${{ secrets.GH_TAGGING_TOKEN }}
63-
script: |
64-
const package_name = "${{ needs.check-version.outputs.package_name }}"
65-
const package_version = "${{ needs.check-version.outputs.package_version }}"
66-
const response = await github.rest.repos.createRelease({
67-
owner: context.repo.owner,
68-
repo: context.repo.repo,
69-
tag_name: `${package_name}-${package_version}`,
70-
target_commitish: 'main',
71-
name: `${package_name}-${package_version}`,
72-
body: `Release ${package_version}`,
73-
draft: false,
74-
prerelease: false,
75-
});
76-
return response.data;
68+
tag_name: ${{needs.check-version.outputs.package_name}}-${{needs.check-version.outputs.package_version}}
69+
name: ${{needs.check-version.outputs.package_name}}-${{needs.check-version.outputs.package_version}}
70+
body_path: release_body.txt
71+
draft: false
72+
prerelease: false
73+
token: ${{ secrets.GH_TAGGING_TOKEN }}
7774
- name: Set PyPI token
7875
run: |
7976
if [ "${{ needs.check-version.outputs.PACKAGE_NAME }}" == "kedro-airflow" ]; then
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
3+
4+
def extract_section(filename, heading):
5+
with open(filename, 'r') as file:
6+
lines = file.readlines()
7+
8+
start_line, end_line = None, None
9+
10+
for i, line in enumerate(lines):
11+
if line.startswith('# '):
12+
current_heading = line.strip('#').replace(':', '').strip()
13+
if current_heading == heading:
14+
start_line = i
15+
elif start_line is not None:
16+
end_line = i
17+
break
18+
19+
if start_line is not None:
20+
if end_line is None:
21+
end_line = len(lines)
22+
section_lines = lines[start_line + 1:end_line]
23+
section = ''.join(section_lines).strip()
24+
return section
25+
else:
26+
return None
27+
28+
29+
if __name__ == '__main__':
30+
if len(sys.argv) != 3:
31+
raise Exception("Usage: python extract_release_notes.py <filename> <heading>")
32+
33+
filename = sys.argv[1]
34+
heading = sys.argv[2]
35+
section = extract_section(filename, heading)
36+
if not section:
37+
raise Exception(f"Section not found under the {heading} heading")
38+
with open("release_body.txt", "w") as text_file:
39+
text_file.write(section)

0 commit comments

Comments
 (0)