Skip to content

Pull request completed #1035

Pull request completed

Pull request completed #1035

# Split into another workflow to make it work with PRs from forked repos
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# Tried using just bundle size reusable workflow file/name, but doesn't work
name: Pull request completed
on:
workflow_run:
#👇 Keep in sync with pull request workflow
workflows: [Pull request]
types:
- completed
permissions:
# 👇 Needed for PR bundle size comment only
pull-requests: write
env:
#👇 Keep in sync with bundle size workflow
BUNDLE_SIZE_ARTIFACT_NAME_SUFFIX: -bundle-size
#👇 Keep in sync with bundle size workflow
BUNDLE_SIZE_COMMENT_ID_PREFIX: bundle-size-comment-
jobs:
load-config:
name: Load CI/CD configuration
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
example-apps-version-aliases: ${{ steps.load-config.outputs.example-apps-version-aliases }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Load CI/CD configuration
id: load-config
uses: ./.github/actions/config
bundle-size-pr-comment:
name: Bundle size - PR comment - Angular ${{ matrix.cli-version-alias }}
needs: load-config
if: github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
cli-version-alias: ${{ fromJSON(needs.load-config.outputs.example-apps-version-aliases) }}
steps:
- name: Download bundle size analysis results
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: ngx-meta${{ env.BUNDLE_SIZE_ARTIFACT_NAME_SUFFIX }}-${{ matrix.cli-version-alias }}
#👇 Need to specify it, otherwise, `run-id` argument won't be taken into account
# https://github.com/actions/download-artifact/tree/v4.1.4#:~:text=current%20workflow%20run.-,github%2Dtoken%3A,-%23%20The%20repository
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
# I wish there was something better than this 🙃
# https://github.com/orgs/community/discussions/25220
- name: Find associated pull request
id: pr
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
retries: 3
#👇 Default except 403, which is the rate limit sometimes raised
# https://github.com/davidlj95/ngx/actions/runs/8362399318/job/22892884496
# https://github.com/octokit/plugin-retry.js/blob/v7.0.3/src/index.ts#L14
retry-exempt-status-codes: 400,401,404,422,451
script: |
const response = await github.rest.search.issuesAndPullRequests({
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
per_page: 1,
})
const items = response.data.items
if (items.length < 1) {
console.error('No PRs found')
return
}
const pullRequestNumber = items[0].number
console.info("Pull request number is", pullRequestNumber)
return pullRequestNumber
- name: Find bundle size PR comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
if: steps.pr.outputs.result != ''
id: fc
with:
issue-number: ${{ steps.pr.outputs.result }}
comment-author: github-actions[bot]
body-includes: ${{ env.BUNDLE_SIZE_COMMENT_ID_PREFIX }}${{ matrix.cli-version-alias }}
- name: Update bundle size PR comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
if: steps.pr.outputs.result != ''
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.result }}
body-path: bundle-size-pr-comment.md
edit-mode: replace