From c9f82f2adf2d70438a2371b2d647a9e9bff8d64b Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 5 Nov 2025 11:22:38 +0000 Subject: [PATCH] Move python script to file --- .github/workflows/script/bundle_changelog.py | 19 +++++++++++++++++ .github/workflows/update-bundle.yml | 22 +------------------- 2 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/script/bundle_changelog.py diff --git a/.github/workflows/script/bundle_changelog.py b/.github/workflows/script/bundle_changelog.py new file mode 100644 index 000000000..71fa8c9c4 --- /dev/null +++ b/.github/workflows/script/bundle_changelog.py @@ -0,0 +1,19 @@ +import os +import re + +# Get the PR number from the PR URL. +pr_number = os.environ['PR_URL'].split('/')[-1] +changelog_note = f"- Update default CodeQL bundle version to {os.environ['CLI_VERSION']}. [#{pr_number}]({os.environ['PR_URL']})" + +# If the "[UNRELEASED]" section starts with "no user facing changes", remove that line. +# Use perl to avoid having to escape the newline character. +with open('CHANGELOG.md', 'r') as f: + changelog = f.read() + +changelog = changelog.replace('## [UNRELEASED]\n\nNo user facing changes.', '## [UNRELEASED]\n') + +# Add the changelog note to the bottom of the "[UNRELEASED]" section. +changelog = re.sub(r'\n## (\d+\.\d+\.\d+)', f'{changelog_note}\n\n## \\1', changelog, count=1) + +with open('CHANGELOG.md', 'w') as f: + f.write(changelog) diff --git a/.github/workflows/update-bundle.yml b/.github/workflows/update-bundle.yml index a8e9eb630..184c339ff 100644 --- a/.github/workflows/update-bundle.yml +++ b/.github/workflows/update-bundle.yml @@ -83,28 +83,8 @@ jobs: echo "PR_URL=$pr_url" | tee -a "$GITHUB_ENV" - name: Create changelog note - shell: python run: | - import os - import re - - # Get the PR number from the PR URL. - pr_number = os.environ['PR_URL'].split('/')[-1] - changelog_note = f"- Update default CodeQL bundle version to {os.environ['CLI_VERSION']}. [#{pr_number}]({os.environ['PR_URL']})" - - # If the "[UNRELEASED]" section starts with "no user facing changes", remove that line. - # Use perl to avoid having to escape the newline character. - - with open('CHANGELOG.md', 'r') as f: - changelog = f.read() - - changelog = changelog.replace('## [UNRELEASED]\n\nNo user facing changes.', '## [UNRELEASED]\n') - - # Add the changelog note to the bottom of the "[UNRELEASED]" section. - changelog = re.sub(r'\n## (\d+\.\d+\.\d+)', f'{changelog_note}\n\n## \\1', changelog, count=1) - - with open('CHANGELOG.md', 'w') as f: - f.write(changelog) + python .github/workflows/script/bundle_changelog.py - name: Push changelog note run: |