diff --git a/.github/workflows/script/bundle_changelog.py b/.github/workflows/script/bundle_changelog.py new file mode 100644 index 0000000000..8a7135f1e4 --- /dev/null +++ b/.github/workflows/script/bundle_changelog.py @@ -0,0 +1,18 @@ +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. +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 f2c3cd40cb..184c339fff 100644 --- a/.github/workflows/update-bundle.yml +++ b/.github/workflows/update-bundle.yml @@ -40,6 +40,11 @@ jobs: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: '3.12' + - name: Set up Node.js uses: actions/setup-node@v6 with: @@ -78,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: |