-
Notifications
You must be signed in to change notification settings - Fork 574
137 lines (115 loc) · 4.8 KB
/
claude-regression-tests.yml
File metadata and controls
137 lines (115 loc) · 4.8 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Claude Regression Tests"
on:
workflow_run:
workflows: ["Issue Bot"]
types:
- completed
concurrency:
group: claude-regression-tests-${{ github.event.workflow_run.head_branch || github.run_id }}
cancel-in-progress: true
jobs:
regression-tests:
name: "Generate regression tests"
if: >-
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 60
steps:
- name: "Get PR details and affected issues"
id: context
env:
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
PR_JSON: ${{ toJSON(github.event.workflow_run.pull_requests) }}
RUN_ID: ${{ github.event.workflow_run.id }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
REPO: ${{ github.repository }}
run: |
# Skip if last commit was our own (prevent feedback loop)
COMMIT_MSG=$(gh api "repos/$REPO/commits/$HEAD_SHA" --jq '.commit.message' 2>/dev/null || true)
if [[ "$COMMIT_MSG" == "Add regression test for #"* ]]; then
echo "Last commit was regression test addition, skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
PR_NUMBER=$(echo "$PR_JSON" | jq -r '.[0].number // empty')
if [ -z "$PR_NUMBER" ]; then
echo "No PR associated with this workflow run"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
PR_AUTHOR=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json author --jq '.author.login')
if [ "$PR_AUTHOR" != "phpstan-bot" ]; then
echo "PR author is $PR_AUTHOR, not phpstan-bot - skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Read the Issue Bot summary from workflow run logs
ISSUE_NUMBERS=$(gh run view "$RUN_ID" --repo "$REPO" --log 2>/dev/null \
| grep -oP '\[#\K\d+(?=\]\(https://github\.com/phpstan/phpstan/issues/)' \
| sort -un \
| tr '\n' ' ' \
| xargs)
if [ -z "$ISSUE_NUMBERS" ]; then
echo "No affected issues found in Issue Bot summary"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
PR_BRANCH=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json headRefName --jq '.headRefName')
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "branch=$PR_BRANCH" >> "$GITHUB_OUTPUT"
echo "issues=$ISSUE_NUMBERS" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "### Context" >> "$GITHUB_STEP_SUMMARY"
echo "PR: #$PR_NUMBER (branch: $PR_BRANCH)" >> "$GITHUB_STEP_SUMMARY"
echo "Affected issues: $ISSUE_NUMBERS" >> "$GITHUB_STEP_SUMMARY"
- name: "Checkout"
if: steps.context.outputs.skip != 'true'
uses: actions/checkout@v4
with:
ref: ${{ steps.context.outputs.branch }}
fetch-depth: 0
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
- name: "Install PHP"
if: steps.context.outputs.skip != 'true'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.4"
ini-file: development
extensions: mbstring
- name: "Install dependencies"
if: steps.context.outputs.skip != 'true'
uses: "ramsey/composer-install@v3"
- name: "Install Claude Code"
if: steps.context.outputs.skip != 'true'
run: npm install -g @anthropic-ai/claude-code
- name: "Generate regression tests"
if: steps.context.outputs.skip != 'true'
env:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
ISSUE_NUMBERS: ${{ steps.context.outputs.issues }}
run: |
git config user.name "phpstan-bot"
git config user.email "ondrej+phpstanbot@mirtes.cz"
for ISSUE_NUMBER in $ISSUE_NUMBERS; do
echo "Generating regression test for issue #$ISSUE_NUMBER"
echo "### Issue #$ISSUE_NUMBER" >> "$GITHUB_STEP_SUMMARY"
claude -p \
--model claude-opus-4-6 \
--output-format stream-json \
--verbose \
--dangerously-skip-permissions \
"/regression-test $ISSUE_NUMBER
Do not create a branch or push - this will be handled automatically."
done
- name: "Push"
if: steps.context.outputs.skip != 'true'
run: |
if [ "$(git rev-parse HEAD)" = "$(git rev-parse @{u})" ]; then
echo "No new commits to push"
exit 0
fi
git push