Skip to content

Commit

Permalink
Merge pull request #2517 from github/aeisenberg/create-release
Browse files Browse the repository at this point in the history
Create a GitHub release for each action release
  • Loading branch information
Andrew Eisenberg authored and GitHub committed Oct 11, 2024
2 parents 0c3e006 + 2b89f7b commit ea2cd92
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/post-release-mergeback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -150,3 +161,16 @@ jobs:
--body "${pr_body}" \
--assignee "${GITHUB_ACTOR}" \
--draft
- name: Create the GitHub release
env:
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 \
--title "$VERSION" \
--notes-file "$PARTIAL_CHANGELOG"
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
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))

0 comments on commit ea2cd92

Please sign in to comment.