Skip to content

pr-comments-bot

pr-comments-bot #330

name: pr-comments-bot
# NOTE: this workflow does not run in a pull_request context, and thus
# GITHUB_TOKEN has slightly elevated permissions.
# That means we need to be particularly careful not to run untrusted code such
# as submitted in PRs.
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
on:
workflow_run:
workflows: [IWYU CI]
types:
- completed
defaults:
run:
shell: bash
jobs:
add-pr-comments:
# Only run if triggered from a successful PR build.
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-22.04
strategy:
fail-fast: true
steps:
- name: Install prerequisites
run: |
sudo apt update
sudo apt install -y \
curl \
jq
- name: Download PR comments payloads
uses: actions/download-artifact@v4
with:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
name: pr-comments
path: ./pr-comments
- name: Add dogfood PR comment if available
if: ${{ hashFiles('./pr-comments/iwyu-dogfood.md') != '' }}
env:
API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl \
-sS \
-L \
-X POST \
"$(cat ./pr-comments/api-url)" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $API_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
--data "{ \"body\": $(jq -R -s '.' ./pr-comments/iwyu-dogfood.md) }"