Skip to content

Commit 646c9a2

Browse files
committed
fix(ci): trust generated agentic CI PRs
Signed-off-by: Andre Manoel <amanoel@nvidia.com>
1 parent d14c9b3 commit 646c9a2

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/dco-assistant.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,45 @@ jobs:
2525
if: github.repository_owner == 'NVIDIA-NeMo'
2626
runs-on: ubuntu-latest
2727
steps:
28+
- name: Check trusted Agentic CI PR
29+
id: trusted-agentic-ci
30+
env:
31+
GH_TOKEN: ${{ github.token }}
32+
EVENT_NAME: ${{ github.event_name }}
33+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
34+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
35+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
36+
PR_BODY: ${{ github.event.pull_request.body }}
37+
ISSUE_NUMBER: ${{ github.event.issue.number }}
38+
REPO: ${{ github.repository }}
39+
run: |
40+
TRUSTED=false
41+
42+
if [ "$EVENT_NAME" = "issue_comment" ] && [ -n "$ISSUE_NUMBER" ]; then
43+
PR_JSON=$(gh api "repos/${REPO}/pulls/${ISSUE_NUMBER}" 2>/dev/null || true)
44+
if [ -n "$PR_JSON" ]; then
45+
PR_AUTHOR=$(printf '%s' "$PR_JSON" | jq -r '.user.login')
46+
HEAD_REPO=$(printf '%s' "$PR_JSON" | jq -r '.head.repo.full_name')
47+
HEAD_REF=$(printf '%s' "$PR_JSON" | jq -r '.head.ref')
48+
PR_BODY=$(printf '%s' "$PR_JSON" | jq -r '.body // ""')
49+
fi
50+
fi
51+
52+
printf '%s' "$PR_BODY" > /tmp/pr-body-raw.txt
53+
# Commit authors can be spoofed; trust only PR metadata GitHub controls.
54+
if { [ "$PR_AUTHOR" = "github-actions[bot]" ] || [ "$PR_AUTHOR" = "agentic-ci" ]; } && \
55+
[ "$HEAD_REPO" = "$REPO" ] && \
56+
[[ "$HEAD_REF" == agentic-ci/* ]] && \
57+
grep -q '<!-- agentic-ci ' /tmp/pr-body-raw.txt; then
58+
TRUSTED=true
59+
fi
60+
61+
echo "trusted=${TRUSTED}" >> "$GITHUB_OUTPUT"
62+
2863
- name: "DCO Assistant"
29-
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the DCO document and I hereby sign the DCO.') || github.event_name == 'pull_request_target'
64+
if: >-
65+
steps.trusted-agentic-ci.outputs.trusted != 'true'
66+
&& ((github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the DCO document and I hereby sign the DCO.') || github.event_name == 'pull_request_target')
3067
uses: contributor-assistant/github-action@ca4a40a7d1004f18d9960b404b97e5f30a505a08
3168
env:
3269
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr-linked-issue.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,23 @@ jobs:
3636
env:
3737
GH_TOKEN: ${{ github.token }}
3838
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
39+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
40+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
41+
PR_BODY: ${{ github.event.pull_request.body }}
42+
REPO: ${{ github.repository }}
3943
run: |
4044
USER="$PR_AUTHOR"
4145
46+
printf '%s' "$PR_BODY" > /tmp/pr-body-raw.txt
47+
# Commit authors can be spoofed; trust only PR metadata GitHub controls.
48+
if { [ "$USER" = "github-actions[bot]" ] || [ "$USER" = "agentic-ci" ]; } && \
49+
[ "$HEAD_REPO" = "$REPO" ] && \
50+
[[ "$HEAD_REF" == agentic-ci/* ]] && \
51+
grep -q '<!-- agentic-ci ' /tmp/pr-body-raw.txt; then
52+
echo "is_collaborator=true" >> "$GITHUB_OUTPUT"
53+
exit 0
54+
fi
55+
4256
# Bots that are always allowed (match DCO allowlist pattern).
4357
if [ "$USER" = "dependabot[bot]" ]; then
4458
echo "is_collaborator=true" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)