From 552603535439d05eb0ff46fdcc6d523ca436b353 Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Fri, 19 May 2023 13:52:28 +0100 Subject: [PATCH 1/5] ci: Automatically extract release notes Signed-off-by: Ankita Katiyar --- .github/workflows/check-release.yml | 30 +++++++------- tools/github_actions/extract_release_notes.py | 39 +++++++++++++++++++ 2 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 tools/github_actions/extract_release_notes.py diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index 386810bbd..a62dc4b93 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -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 @@ -90,4 +87,3 @@ jobs: with: packages-dir: ${{ needs.check-version.outputs.package_name }}/dist password: ${{ env.PYPI_TOKEN }} - diff --git a/tools/github_actions/extract_release_notes.py b/tools/github_actions/extract_release_notes.py new file mode 100644 index 000000000..94ae593fb --- /dev/null +++ b/tools/github_actions/extract_release_notes.py @@ -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 + + 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) + + 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) From 588d62552396282a0d9dba67bcd8fe94fb6930d2 Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Fri, 19 May 2023 14:19:21 +0100 Subject: [PATCH 2/5] fix lint Signed-off-by: Ankita Katiyar --- .github/workflows/check-release.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index a62dc4b93..51036d260 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -57,11 +57,11 @@ jobs: 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}}" + 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: softprops/action-gh-release@v1 with: From b11ac78639eb30d231fe4fc8c478e6a3340d7f7a Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Mon, 22 May 2023 10:29:50 +0100 Subject: [PATCH 3/5] Raise exceptions Signed-off-by: Ankita Katiyar --- tools/github_actions/extract_release_notes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/github_actions/extract_release_notes.py b/tools/github_actions/extract_release_notes.py index 94ae593fb..787a1db07 100644 --- a/tools/github_actions/extract_release_notes.py +++ b/tools/github_actions/extract_release_notes.py @@ -29,11 +29,12 @@ def extract_section(filename, heading): if __name__ == '__main__': if len(sys.argv) != 3: - sys.exit(1) + raise Exception("Usage: python extract_release_notes.py ") filename = sys.argv[1] heading = sys.argv[2] section = extract_section(filename, heading) - + if not section: + raise Exception(f"Section not found under the {heading} heading") with open("release_body.txt", "w") as text_file: text_file.write(section) From 16df36305904564de0b4895d566a16e6b06749ec Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Mon, 22 May 2023 10:31:19 +0100 Subject: [PATCH 4/5] Lint Signed-off-by: Ankita Katiyar --- tools/github_actions/extract_release_notes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/github_actions/extract_release_notes.py b/tools/github_actions/extract_release_notes.py index 787a1db07..b917227dd 100644 --- a/tools/github_actions/extract_release_notes.py +++ b/tools/github_actions/extract_release_notes.py @@ -5,9 +5,8 @@ def extract_section(filename, heading): with open(filename, 'r') as file: lines = file.readlines() - start_line = None - end_line = None - + start_line, end_line = None, None + for i, line in enumerate(lines): if line.startswith('# '): current_heading = line.strip('#').replace(':', '').strip() From b3757c421bc2c7ba8808eb6f58e116f50f77e212 Mon Sep 17 00:00:00 2001 From: Ankita Katiyar Date: Mon, 22 May 2023 10:37:58 +0100 Subject: [PATCH 5/5] Lint Signed-off-by: Ankita Katiyar --- tools/github_actions/extract_release_notes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/github_actions/extract_release_notes.py b/tools/github_actions/extract_release_notes.py index b917227dd..52a8516cb 100644 --- a/tools/github_actions/extract_release_notes.py +++ b/tools/github_actions/extract_release_notes.py @@ -6,7 +6,7 @@ def extract_section(filename, heading): lines = file.readlines() start_line, end_line = None, None - + for i, line in enumerate(lines): if line.startswith('# '): current_heading = line.strip('#').replace(':', '').strip()