Skip to content

Pull request completed #106

Pull request completed

Pull request completed #106

# 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 pull request workflow
BUNDLE_SIZE_ARTIFACT_NAME_PREFIX: ngx-meta-bundle-size-a
#👇 Keep in sync with bundle size reusable workflow
BUNDLE_SIZE_COMMENT_ID_PREFIX: bundle-size-comment-a
jobs:
bundle-size-pr-comment:
name: Bundle size - PR comment - Angular v${{ matrix.version }}
if: github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
version: [15, 16, 17]
steps:
- name: Download bundle size analysis results
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4
with:
name: ${{ env.BUNDLE_SIZE_ARTIFACT_NAME_PREFIX }}${{ matrix.version }}
#👇 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:
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@d5fe37641ad8451bdd80312415672ba26c86575e # v3
id: fc
with:
issue-number: ${{ steps.pr.outputs.result }}
comment-author: 'github-actions[bot]'
body-includes: ${{ env.BUNDLE_SIZE_COMMENT_ID_PREFIX }}${{ matrix.version }}
- name: Update bundle size PR comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.result }}
body-path: bundle-size-pr-comment.md
edit-mode: replace