Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Automatically extract release notes for GitHub Releases #212

Merged
merged 8 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,21 @@ jobs:
run: |
export plugin=${{ needs.check-version.outputs.package_name }}
make package
- name: Extract release notes from ${{needs.check-version.outputs.package_name}}/RELEASE.md
id: extract
run: |
python tools/github_actions/extract_release_notes.py \
"${{needs.check-version.outputs.package_name}}/RELEASE.md" \
"Release ${{needs.check-version.outputs.package_version}}"
- name: Create GitHub Release
uses: actions/github-script@v6
uses: softprops/action-gh-release@v1
with:
github-token: ${{ secrets.GH_TAGGING_TOKEN }}
script: |
const package_name = "${{ needs.check-version.outputs.package_name }}"
const package_version = "${{ needs.check-version.outputs.package_version }}"
const response = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `${package_name}-${package_version}`,
target_commitish: 'main',
name: `${package_name}-${package_version}`,
body: `Release ${package_version}`,
draft: false,
prerelease: false,
});
return response.data;
tag_name: ${{needs.check-version.outputs.package_name}}-${{needs.check-version.outputs.package_version}}
name: ${{needs.check-version.outputs.package_name}}-${{needs.check-version.outputs.package_version}}
body_path: release_body.txt
draft: false
prerelease: false
token: ${{ secrets.GH_TAGGING_TOKEN }}
- name: Set PyPI token
run: |
if [ "${{ needs.check-version.outputs.PACKAGE_NAME }}" == "kedro-airflow" ]; then
Expand All @@ -90,4 +87,3 @@ jobs:
with:
packages-dir: ${{ needs.check-version.outputs.package_name }}/dist
password: ${{ env.PYPI_TOKEN }}

39 changes: 39 additions & 0 deletions tools/github_actions/extract_release_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys


def extract_section(filename, heading):
with open(filename, 'r') as file:
lines = file.readlines()

start_line = None
end_line = None
ankatiyar marked this conversation as resolved.
Show resolved Hide resolved

for i, line in enumerate(lines):
if line.startswith('# '):
current_heading = line.strip('#').replace(':', '').strip()
if current_heading == heading:
start_line = i
elif start_line is not None:
end_line = i
break

if start_line is not None:
if end_line is None:
end_line = len(lines)
section_lines = lines[start_line + 1:end_line]
section = ''.join(section_lines).strip()
return section
else:
return None


if __name__ == '__main__':
if len(sys.argv) != 3:
sys.exit(1)
ankatiyar marked this conversation as resolved.
Show resolved Hide resolved

filename = sys.argv[1]
heading = sys.argv[2]
section = extract_section(filename, heading)

with open("release_body.txt", "w") as text_file:
text_file.write(section)