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

Create a GitHub release for each action release #2517

Merged
merged 3 commits into from
Oct 11, 2024
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
22 changes: 22 additions & 0 deletions .github/workflows/post-release-mergeback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,25 @@ jobs:
--body "${pr_body}" \
--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" \
--latest=false \
-t "$VERSION" \
-F "$PARTIAL_CHANGELOG"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Would it make sense to change the -F to the more explicit --notes-file?

Reveals the intent better, and if it's part of a script it might be more convenient for future readers of the code.

37 changes: 37 additions & 0 deletions .github/workflows/script/prepare_changelog.py
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this works is by appending lines until the a second H2 markdown header is found, as I understand it.

In the test run, the release notes it created contain the header [UNRELEASED]. I think that these headers are processed before the release, but does it make sense to have any sort of post-processing/manipulation of the header in case we come across the [UNRELEASED]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm...I'd originally thought that this was because I didn't start on a release branch, but now I'm not so sure. I'll have to take a deeper look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK...there were two things going on:

  1. The run was not on a release branch, so we don't see the actual version number. This is expected.
  2. However, I originally created the changelog too late in the process after the header was changed back to UNRELEASED.

I've now fixed 2. I also added a few cleanups.

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))
Loading