File: pr-comments-bot.yml

package info (click to toggle)
iwyu 8.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,336 kB
  • sloc: cpp: 17,440; python: 6,416; ansic: 1,307; sh: 55; makefile: 29
file content (58 lines) | stat: -rw-r--r-- 1,688 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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) }"