-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathsmoke-tests-label-from-coderabbit.yml
More file actions
113 lines (99 loc) · 6.64 KB
/
smoke-tests-label-from-coderabbit.yml
File metadata and controls
113 lines (99 loc) · 6.64 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Smoke Tests Label Manager - Automatically adds/removes 'smoke-tests:pending-analysis' label based on CodeRabbit analysis
# Created with Claude Code assistance
#
# Summary:
# ┌──────────────────────────────────────────────────────────────┬───────────────────────────────┬────────────────────────────────────────┐
# │ CodeRabbit Comment Contains │ Current Label │ Action │
# ├──────────────────────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────────────────┤
# │ "**Run smoke tests: True**" AND "## Test Execution Plan" │ None │ ✅ Add 'smoke-tests:pending-analysis' │
# │ "**Run smoke tests: True**" AND "## Test Execution Plan" │ Already has label │ ✅ No-op (safe) │
# │ "**Run smoke tests: False**" AND "## Test Execution Plan" │ Has label │ ✅ Remove label │
# │ "**Run smoke tests: False**" AND "## Test Execution Plan" │ None │ ✅ No action │
# │ New commit pushed (PR opened/sync/reopened) │ Has label │ ✅ Remove label │
# │ Missing "## Test Execution Plan" │ Any │ ⏭️ No action │
# │ Neither pattern │ Any │ ⏭️ No action │
# │ Comment not from CodeRabbit │ Any │ ⏭️ Does NOT run │
# └──────────────────────────────────────────────────────────────┴───────────────────────────────┴────────────────────────────────────────┘
#
# CodeRabbit comments trigger via: pull_request_review_comment (inline comments) or issue_comment (PR comments)
name: "Smoke Tests Label from CodeRabbit"
on:
# WARNING: pull_request_target runs with write permissions on base repo
# Safe here because we only manipulate labels without executing PR code
# NEVER add steps that checkout or execute code from the PR branch
# Event types: pull_request_target (reset), pull_request_review_comment/issue_comment (CodeRabbit)
pull_request_target:
types: [opened, synchronize, reopened]
pull_request_review_comment:
types: [created, edited]
issue_comment:
types: [created, edited]
permissions:
pull-requests: write
contents: read
jobs:
reset-on-push:
name: Reset label on push
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- name: Remove label
uses: actions-ecosystem/action-remove-labels@v1
continue-on-error: true
with:
number: ${{ github.event.pull_request.number }}
labels: smoke-tests:pending-analysis
github_token: ${{ secrets.GITHUB_TOKEN }}
manage-smoke-tests-label:
name: Manage label from CodeRabbit
# Only run for CodeRabbit comments
if: |
github.event_name != 'pull_request_target' &&
(
(github.event_name == 'issue_comment' &&
(github.event.comment.user.login == 'coderabbitai' || github.event.comment.user.login == 'coderabbitai[bot]')) ||
(github.event_name == 'pull_request_review_comment' &&
(github.event.comment.user.login == 'coderabbitai' || github.event.comment.user.login == 'coderabbitai[bot]'))
)
runs-on: ubuntu-latest
steps:
- name: Determine label action
id: flow
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
[ -z "$COMMENT_BODY" ] && { echo "ERROR: Empty comment body"; exit 1; }
# Strip <details> and <summary> blocks to avoid matching patterns in analysis chain scripts
COMMENT_STRIPPED=$(sed -e '/<details>/,/<\/details>/d' -e '/<summary>/,/<\/summary>/d' <<< "$COMMENT_BODY")
# Use line-anchored patterns to avoid matching meta-discussions about the workflow
# These patterns require the text to appear at the start of a line, matching the actual
# Test Execution Plan format instead of matching when CodeRabbit explains how it works
HAS_TEST_PLAN=$(grep -qE '^## Test Execution Plan' <<< "$COMMENT_STRIPPED" && echo "true" || echo "false")
HAS_RUN_TRUE=$(grep -qE '^\*\*Run smoke tests: True\*\*' <<< "$COMMENT_STRIPPED" && echo "true" || echo "false")
HAS_RUN_FALSE=$(grep -qE '^\*\*Run smoke tests: False\*\*' <<< "$COMMENT_STRIPPED" && echo "true" || echo "false")
FLOW_ADD="false"
FLOW_REMOVE="false"
if [ "$HAS_TEST_PLAN" = "true" ] && [ "$HAS_RUN_TRUE" = "true" ]; then
FLOW_ADD="true"
elif [ "$HAS_TEST_PLAN" = "true" ] && [ "$HAS_RUN_FALSE" = "true" ]; then
FLOW_REMOVE="true"
# Note: If both TRUE and FALSE are present, no action is taken (edge case)
fi
echo "flow_add=$FLOW_ADD" >> $GITHUB_OUTPUT
echo "flow_remove=$FLOW_REMOVE" >> $GITHUB_OUTPUT
- name: Add label
if: steps.flow.outputs.flow_add == 'true'
uses: actions-ecosystem/action-add-labels@v1
continue-on-error: true
with:
number: ${{ github.event.issue.number || github.event.pull_request.number }}
labels: smoke-tests:pending-analysis
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove label
if: steps.flow.outputs.flow_remove == 'true'
uses: actions-ecosystem/action-remove-labels@v1
continue-on-error: true
with:
number: ${{ github.event.issue.number || github.event.pull_request.number }}
labels: smoke-tests:pending-analysis
github_token: ${{ secrets.GITHUB_TOKEN }}