-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathaction.yml
More file actions
260 lines (239 loc) · 11.8 KB
/
Copy pathaction.yml
File metadata and controls
260 lines (239 loc) · 11.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: 'Smart E2E Selection'
description: 'Run AI-powered E2E test selection based on code changes'
inputs:
claude-api-key:
description: 'Anthropic Claude API key for AI analysis (primary provider)'
required: false
default: ''
openai-api-key:
description: 'OpenAI API key for AI analysis (fallback provider)'
required: false
default: ''
google-api-key:
description: 'Google Gemini API key for AI analysis (fallback provider)'
required: false
default: ''
github-token:
description: 'GitHub token for PR comments'
required: true
pr-number:
description: 'Pull request number for commenting'
required: true
repository:
description: 'Repository name (owner/repo) for commenting'
required: true
post-comment:
description: 'Whether to post a comment to the PR'
required: false
default: 'false'
base-ref:
description: 'PR base branch ref passed to the AI analysis script for diff comparison. When release/* or stable, AI selection is skipped and the full E2E suite is selected.'
required: false
default: ''
outputs:
ai_e2e_test_tags:
description: 'E2E test tags to run (JSON array format)'
value: ${{ steps.final-outputs.outputs.ai_e2e_test_tags }}
ai_confidence:
description: 'AI confidence score (0-100)'
value: ${{ steps.final-outputs.outputs.ai_confidence }}
ai_performance_test_tags:
description: "Performance test tags to run. Empty string '' = run all (conservative fallback). Literal '[]' = skip (AI found no relevant changes). '[\"@Tag\",...]' = run specific tags."
value: ${{ steps.final-outputs.outputs.ai_performance_test_tags }}
ai_performance_test_reasoning:
description: 'Reasoning for the performance test selection'
value: ${{ steps.final-outputs.outputs.ai_performance_test_reasoning }}
runs:
using: 'composite'
steps:
- name: Check skip-smart-e2e-selection label
id: check-skip-label
if: inputs.pr-number != ''
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
echo "SKIP=false" >> "$GITHUB_OUTPUT"
if gh pr view ${{ inputs.pr-number }} --repo ${{ inputs.repository }} --json labels --jq '.labels[].name' | grep -qx "skip-smart-e2e-selection"; then
echo "SKIP=true" >> "$GITHUB_OUTPUT"
echo "⏭️ SKIP=true due to 'skip-smart-e2e-selection' label on PR"
fi
- name: Check release or stable target branch (full E2E, no AI selection)
id: check-release-target
shell: bash
run: |
echo "SKIP=false" >> "$GITHUB_OUTPUT"
BASE='${{ inputs.base-ref }}'
if [[ -n "$BASE" && ( "$BASE" == release/* || "$BASE" == "stable" ) ]]; then
echo "SKIP=true" >> "$GITHUB_OUTPUT"
echo "⏭️ Base branch is release/* or stable — skipping AI E2E selection; full E2E suite will run"
fi
- name: Checkout for PR analysis
if: steps.check-skip-label.outputs.SKIP != 'true' && steps.check-release-target.outputs.SKIP != 'true'
uses: actions/checkout@v6
with:
fetch-depth: 1 # Shallow clone for speed; unshallowed below for diff comparison
- name: Disable sparse checkout and restore all files
if: steps.check-skip-label.outputs.SKIP != 'true' && steps.check-release-target.outputs.SKIP != 'true'
shell: bash
run: |
git sparse-checkout disable
git checkout HEAD -- .
- name: Fetch base branch for comparison
if: steps.check-skip-label.outputs.SKIP != 'true' && steps.check-release-target.outputs.SKIP != 'true'
shell: bash
run: |
# Unshallow the repository first (if it's shallow)
git fetch --unshallow 2>/dev/null || true
# Fetch the base branch for diff comparison (main or release/*)
git fetch origin "${{ inputs.base-ref || 'main' }}" 2>/dev/null || true
- name: Setup Node.js
if: steps.check-skip-label.outputs.SKIP != 'true' && steps.check-release-target.outputs.SKIP != 'true'
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
- name: Install minimal dependencies for AI analysis
if: steps.check-skip-label.outputs.SKIP != 'true' && steps.check-release-target.outputs.SKIP != 'true'
shell: bash
run: |
echo "📦 Installing only required packages for AI analysis..."
# Install to a separate location that won't be overwritten
mkdir -p /tmp/ai-deps
cd /tmp/ai-deps
npm init -y
npm install @anthropic-ai/sdk@0.71.0 openai@4.77.0 @google/generative-ai@0.24.1 esbuild-register@3.6.0 --no-audit --no-fund
echo "✅ AI analysis dependencies installed in /tmp/ai-deps"
- name: Copy AI dependencies to workspace
if: steps.check-skip-label.outputs.SKIP != 'true' && steps.check-release-target.outputs.SKIP != 'true'
shell: bash
run: |
echo "📋 Copying AI dependencies to workspace..."
# Create node_modules if it doesn't exist
mkdir -p node_modules
# Copy our pre-installed dependencies
cp -r /tmp/ai-deps/node_modules/* node_modules/
echo "✅ AI dependencies available in workspace"
- name: Run E2E AI analysis
id: ai-analysis
shell: bash
env:
E2E_CLAUDE_API_KEY: ${{ inputs.claude-api-key }}
E2E_OPENAI_API_KEY: ${{ inputs.openai-api-key }}
E2E_GEMINI_API_KEY: ${{ inputs.google-api-key }}
PR_NUMBER: ${{ inputs.pr-number }}
GH_TOKEN: ${{ inputs.github-token }}
GITHUB_REPOSITORY: ${{ inputs.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
BASE_REF: ${{ inputs.base-ref }}
run: |
echo "ai_e2e_test_tags=[\"ALL\"]" >> "$GITHUB_OUTPUT"
echo "ai_confidence=0" >> "$GITHUB_OUTPUT"
# Empty string = run all performance tests (conservative fallback).
# '[]' is reserved for "AI ran successfully and found no relevant changes".
echo "ai_performance_test_tags=" >> "$GITHUB_OUTPUT"
if [[ "${{ steps.check-skip-label.outputs.SKIP }}" == "true" ]]; then
echo "⏭️ Skipping AI analysis - skip-smart-e2e-selection label found"
echo "SKIPPED=true" >> "$GITHUB_OUTPUT"
echo "SKIP_REASON=skip-smart-e2e-selection label found" >> "$GITHUB_OUTPUT"
echo "ai_confidence=100" >> "$GITHUB_OUTPUT"
# Skip label → run all E2E (ALL) but do NOT launch the PR performance workflow.
# Performance tests are expensive and the skip label only opts out of AI selection,
# not into a full performance run. Use '[]' so run-performance-tests-pr is skipped.
echo "ai_performance_test_tags=[]" >> "$GITHUB_OUTPUT"
elif [[ "${{ steps.check-release-target.outputs.SKIP }}" == "true" ]]; then
echo "⏭️ Skipping AI analysis - PR targets a release or stable branch"
echo "SKIPPED=true" >> "$GITHUB_OUTPUT"
echo "SKIP_REASON=PR targets a release or stable branch (release/* or stable)" >> "$GITHUB_OUTPUT"
echo "ai_confidence=100" >> "$GITHUB_OUTPUT"
# Release/stable target → the scheduled performance workflow covers these branches.
# No need to also trigger the PR performance job.
echo "ai_performance_test_tags=[]" >> "$GITHUB_OUTPUT"
else
echo "✅ Running AI analysis for PR #$PR_NUMBER"
# The script will generate the GH output variables - don't fail if script errors
node .github/scripts/e2e-smart-selection.mjs || echo "⚠️ AI analysis script failed, using fallback"
fi
- name: Set final outputs with fallback
id: final-outputs
if: always()
shell: bash
env:
AI_E2E_TAGS: ${{ steps.ai-analysis.outputs.ai_e2e_test_tags }}
AI_CONFIDENCE: ${{ steps.ai-analysis.outputs.ai_confidence }}
AI_PERF_TAGS: ${{ steps.ai-analysis.outputs.ai_performance_test_tags }}
AI_PERF_REASONING: ${{ steps.ai-analysis.outputs.ai_performance_test_reasoning }}
run: |
if [[ -n "$AI_E2E_TAGS" ]]; then
printf 'ai_e2e_test_tags=%s\n' "$AI_E2E_TAGS" >> "$GITHUB_OUTPUT"
else
echo 'ai_e2e_test_tags=["ALL"]' >> "$GITHUB_OUTPUT"
fi
printf 'ai_confidence=%s\n' "$AI_CONFIDENCE" >> "$GITHUB_OUTPUT"
# Performance test tags: empty string = run all (fallback); '[]' = skip (AI found no changes)
printf 'ai_performance_test_tags=%s\n' "$AI_PERF_TAGS" >> "$GITHUB_OUTPUT"
# Performance test reasoning (multi-line — must use heredoc format)
{
echo 'ai_performance_test_reasoning<<GHEOF'
echo "$AI_PERF_REASONING"
echo 'GHEOF'
} >> "$GITHUB_OUTPUT"
- name: Display AI Analysis Outputs
if: always()
shell: bash
env:
PERF_REASONING: ${{ steps.final-outputs.outputs.ai_performance_test_reasoning }}
run: |
echo "📊 Final GitHub Action Outputs:"
echo "================================"
echo "ai_e2e_test_tags: ${{ steps.final-outputs.outputs.ai_e2e_test_tags }}"
echo "ai_confidence: ${{ steps.final-outputs.outputs.ai_confidence }}"
echo "ai_performance_test_tags: ${{ steps.final-outputs.outputs.ai_performance_test_tags }}"
echo "ai_performance_test_reasoning: $PERF_REASONING"
echo "================================"
- name: Delete previous comments
if: inputs.post-comment == 'true' && inputs.pr-number != '' && inputs.github-token != ''
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
echo "🗑️ Deleting all existing Smart E2E selection comments..."
# Get comment IDs using the HTML marker for precise identification
ALL_COMMENT_IDS=$(gh api "repos/${{ inputs.repository }}/issues/${{ inputs.pr-number }}/comments" \
--jq '.[] | select(.body | contains("<!-- smart-e2e-selection -->")) | .id')
COMMENT_COUNT=$(echo "$ALL_COMMENT_IDS" | wc -l | tr -d ' ')
echo "📊 Found $COMMENT_COUNT comments"
if [ -n "$ALL_COMMENT_IDS" ] && [ "$COMMENT_COUNT" -gt 0 ]; then
echo "🗑️ Deleting all $COMMENT_COUNT comments..."
echo "$ALL_COMMENT_IDS" | while read -r COMMENT_ID; do
if [ -n "$COMMENT_ID" ]; then
echo " Deleting comment: $COMMENT_ID"
gh api "repos/${{ inputs.repository }}/issues/comments/$COMMENT_ID" \
--method DELETE > /dev/null 2>&1 || echo " ⚠️ Failed to delete comment $COMMENT_ID"
fi
done
echo "✨ Cleanup completed - deleted all $COMMENT_COUNT comments"
else
echo "📝 No Smart E2E selection comments found"
fi
- name: Create PR comment
if: inputs.post-comment == 'true' && inputs.pr-number != '' && inputs.github-token != ''
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
COMMENT_FILE="pr_comment.md"
TITLE="## 🔍 Smart E2E Test Selection"
FOOTER="[View GitHub Actions results](https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }})"
MARKER="<!-- smart-e2e-selection -->"
COMMENT_BODY=""
if [[ "${{ steps.ai-analysis.outputs.SKIPPED }}" == "true" ]]; then
SKIP_REASON="${{ steps.ai-analysis.outputs.SKIP_REASON }}"
COMMENT_BODY="⏭️ **Smart E2E selection skipped** - ${SKIP_REASON}"$'\n\n'"All E2E tests pre-selected."
elif [ -f "$COMMENT_FILE" ]; then
COMMENT_BODY=$(cat "$COMMENT_FILE")
else
COMMENT_BODY="⚠️ AI analysis was inconclusive. Selecting all E2E tests as a fallback, if applicable based on changed files."
fi
FULL_COMMENT="${TITLE}"$'\n'"${COMMENT_BODY}"$'\n\n'"${FOOTER}"$'\n'"${MARKER}"
gh pr comment ${{ inputs.pr-number }} --repo ${{ inputs.repository }} --body "$FULL_COMMENT"
echo "✅ Successfully created comment"