|
| 1 | +name: Update default CodeQL bundle |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [prereleased] |
| 6 | + |
| 7 | +jobs: |
| 8 | + update-bundle: |
| 9 | + if: startsWith(github.event.release.tag_name, 'codeql-bundle-') |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Dump environment |
| 13 | + run: env |
| 14 | + |
| 15 | + - name: Dump GitHub context |
| 16 | + env: |
| 17 | + GITHUB_CONTEXT: '${{ toJson(github) }}' |
| 18 | + run: echo "${GITHUB_CONTEXT}" |
| 19 | + |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Update git config |
| 23 | + run: | |
| 24 | + git config --global user.email "github-actions@github.com" |
| 25 | + git config --global user.name "github-actions[bot]" |
| 26 | +
|
| 27 | + - name: Update bundle |
| 28 | + uses: ./.github/actions/update-bundle |
| 29 | + |
| 30 | + - name: Rebuild Action |
| 31 | + run: npm run build |
| 32 | + |
| 33 | + - name: Commit and push changes |
| 34 | + env: |
| 35 | + RELEASE_TAG: "${{ github.event.release.tag_name }}" |
| 36 | + run: | |
| 37 | + git checkout -b "update-bundle/${RELEASE_TAG}" |
| 38 | + git commit -am "Update default bundle to ${RELEASE_TAG}" |
| 39 | + git push --set-upstream origin "update-bundle/${RELEASE_TAG}" |
| 40 | +
|
| 41 | + - name: Open pull request |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + cli_version=$(jq -r '.cliVersion' src/defaults.json) |
| 46 | + pr_url=$(gh pr create \ |
| 47 | + --title "Update default bundle to $cli_version" \ |
| 48 | + --body "This pull request updates the default CodeQL bundle, as used with \`tools: latest\` and on GHES, to $cli_version." \ |
| 49 | + --assignee "${GITHUB_ACTOR}" \ |
| 50 | + --draft \ |
| 51 | + ) |
| 52 | + echo "CLI_VERSION=$cli_version" >> $GITHUB_ENV |
| 53 | + echo "PR_URL=$pr_url" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + - name: Create changelog note |
| 56 | + shell: python |
| 57 | + run: | |
| 58 | + import os |
| 59 | + import re |
| 60 | +
|
| 61 | + # Get the PR number from the PR URL. |
| 62 | + pr_number = os.environ['PR_URL'].split('/')[-1] |
| 63 | + changelog_note = f"- Update default CodeQL bundle version to {os.environ['CLI_VERSION']}. [#{pr_number}]({os.environ['PR_URL']})" |
| 64 | +
|
| 65 | + # If the "[UNRELEASED]" section starts with "no user facing changes", remove that line. |
| 66 | + # Use perl to avoid having to escape the newline character. |
| 67 | +
|
| 68 | + with open('CHANGELOG.md', 'r') as f: |
| 69 | + changelog = f.read() |
| 70 | +
|
| 71 | + changelog = changelog.replace('## [UNRELEASED]\n\nNo user facing changes.', '## [UNRELEASED]\n') |
| 72 | +
|
| 73 | + # Add the changelog note to the bottom of the "[UNRELEASED]" section. |
| 74 | + changelog = re.sub(r'\n## (\d+\.\d+\.\d+)', f'{changelog_note}\n\n## \\1', changelog, count=1) |
| 75 | +
|
| 76 | + with open('CHANGELOG.md', 'w') as f: |
| 77 | + f.write(changelog) |
| 78 | +
|
| 79 | + - name: Push changelog note |
| 80 | + run: | |
| 81 | + git commit -am "Add changelog note" |
| 82 | + git push |
0 commit comments