From 9b4db1efbfc09d6d7d081f0d9d98b0acfc421022 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Wed, 2 Oct 2024 15:08:20 -0700 Subject: [PATCH 1/3] Create a GitHub release for each action release Must make sure this release is not marked as `latest` or else it will interfere with the CLI bundle releases also included in this repo. --- .github/workflows/post-release-mergeback.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/post-release-mergeback.yml b/.github/workflows/post-release-mergeback.yml index 3e3e802502..7ba29251fa 100644 --- a/.github/workflows/post-release-mergeback.yml +++ b/.github/workflows/post-release-mergeback.yml @@ -150,3 +150,14 @@ jobs: --body "${pr_body}" \ --assignee "${GITHUB_ACTOR}" \ --draft + + - name: Create the GitHub release + env: + VERSION: "${{ steps.getVersion.outputs.version }}" + run: | + # Do not mark this release as latest. The most recent CLI release must be marked as latest. + gh release create \ + "${VERSION}" \ + --latest=false \ + -t "${VERSION}" \ + -F CHANGELOG.md From d545e9b4a6667220efa96caf11b292cb75e1c4d0 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Wed, 9 Oct 2024 20:36:47 -0700 Subject: [PATCH 2/3] Add a partial changelog when releasing --- .github/workflows/post-release-mergeback.yml | 17 +++++++-- .github/workflows/script/prepare_changelog.py | 37 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/script/prepare_changelog.py diff --git a/.github/workflows/post-release-mergeback.yml b/.github/workflows/post-release-mergeback.yml index 7ba29251fa..2e00139b50 100644 --- a/.github/workflows/post-release-mergeback.yml +++ b/.github/workflows/post-release-mergeback.yml @@ -151,13 +151,24 @@ jobs: --assignee "${GITHUB_ACTOR}" \ --draft + + - name: Prepare the partial Changelog + env: + VERSION: "${{ steps.getVersion.outputs.version }}" + PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" + run: | + # Prepare the partial changelog for the release notes + python .github/workflows/script/prepare_changelog.py CHANGELOG.md "$VERSION"> $PARTIAL_CHANGELOG + - name: Create the GitHub release env: VERSION: "${{ steps.getVersion.outputs.version }}" + PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Do not mark this release as latest. The most recent CLI release must be marked as latest. gh release create \ - "${VERSION}" \ + "$VERSION" \ --latest=false \ - -t "${VERSION}" \ - -F CHANGELOG.md + -t "$VERSION" \ + -F "$PARTIAL_CHANGELOG" diff --git a/.github/workflows/script/prepare_changelog.py b/.github/workflows/script/prepare_changelog.py new file mode 100644 index 0000000000..316936a6db --- /dev/null +++ b/.github/workflows/script/prepare_changelog.py @@ -0,0 +1,37 @@ +import os +import sys + +EMPTY_CHANGELOG = 'No changes.\n\n' + +# Prepare the changelog for the new release +# This function will extract the part of the changelog that +# we want to include in the new release. +def extract_changelog_snippet(changelog_file, version_tag): + output = '' + if (not os.path.exists(changelog_file)): + output = EMPTY_CHANGELOG + + else: + with open('CHANGELOG.md', 'r') as f: + lines = f.readlines() + + # Include everything up to, but excluding the second heading + found_first_section = False + for i, line in enumerate(lines): + if line.startswith('## '): + if found_first_section: + break + found_first_section = True + output += line + + output += f"See the full [CHANGELOG.md](https://github.com/github/codeql-action/blob/{version_tag}/CHANGELOG.md) for more information." + + return output + + +if len(sys.argv) < 3: + raise Exception('Expecting argument: changelog_file version_tag') +changelog_file = sys.argv[1] +version_tag = sys.argv[2] + +print(extract_changelog_snippet(changelog_file, version_tag)) From 2b89f7bcf6936f603aea1a9f74e665772f8ed4ed Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Thu, 10 Oct 2024 07:50:04 -0700 Subject: [PATCH 3/3] Create the changelog before creating the mergeback branch --- .github/workflows/post-release-mergeback.yml | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/post-release-mergeback.yml b/.github/workflows/post-release-mergeback.yml index 2e00139b50..29aefc401f 100644 --- a/.github/workflows/post-release-mergeback.yml +++ b/.github/workflows/post-release-mergeback.yml @@ -108,6 +108,17 @@ jobs: # - `--force` since we're overwriting the `vN` tag git push origin --atomic --force refs/tags/"${VERSION}" refs/tags/"${major_version_tag}" + - name: Prepare partial Changelog + env: + PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" + VERSION: "${{ steps.getVersion.outputs.version }}" + run: | + python .github/workflows/script/prepare_changelog.py CHANGELOG.md "$VERSION" > $PARTIAL_CHANGELOG + + echo "::group::Partial CHANGELOG" + cat $PARTIAL_CHANGELOG + echo "::endgroup::" + - name: Create mergeback branch if: ${{ steps.check.outputs.exists != 'true' && endsWith(github.ref_name, steps.getVersion.outputs.latest_release_branch) }} env: @@ -151,24 +162,15 @@ jobs: --assignee "${GITHUB_ACTOR}" \ --draft - - - name: Prepare the partial Changelog - env: - VERSION: "${{ steps.getVersion.outputs.version }}" - PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" - run: | - # Prepare the partial changelog for the release notes - python .github/workflows/script/prepare_changelog.py CHANGELOG.md "$VERSION"> $PARTIAL_CHANGELOG - - name: Create the GitHub release env: - VERSION: "${{ steps.getVersion.outputs.version }}" PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" + VERSION: "${{ steps.getVersion.outputs.version }}" GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Do not mark this release as latest. The most recent CLI release must be marked as latest. gh release create \ "$VERSION" \ --latest=false \ - -t "$VERSION" \ - -F "$PARTIAL_CHANGELOG" + --title "$VERSION" \ + --notes-file "$PARTIAL_CHANGELOG"