-
Notifications
You must be signed in to change notification settings - Fork 0
386 lines (362 loc) · 17.1 KB
/
Copy pathmining-core.yml
File metadata and controls
386 lines (362 loc) · 17.1 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
name: Nightly Commit Mining
on:
schedule:
- cron: '0 2 * * *' # Every night at 2 AM
workflow_dispatch:
inputs:
batch_size:
description: 'Number of commits per run (default: 500)'
default: '500'
llm_provider:
description: 'LLM provider (gemini, openai, deepseek, qwen, llama, mistral; auto-detected if not set)'
default: ''
jobs:
mine:
runs-on: ubuntu-latest
timeout-minutes: 60
concurrency:
group: mining-state
cancel-in-progress: false
permissions:
contents: write # Required: commit state.json and deploy report to gh-pages
pull-requests: write # Required: create and auto-merge the state-update PR
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build Mining CLI
run: |
mvn install -N -q
mvn install -pl sandbox_common_core -DskipTests -q
mvn package -pl sandbox_mining_core -DskipTests -q
- name: Snapshot known rules before mining
run: |
if [ -f docs/mining-report/known-rules.json ]; then
cp docs/mining-report/known-rules.json "$RUNNER_TEMP/known-rules-before.json"
else
printf '{"version":1,"rules":[]}' > "$RUNNER_TEMP/known-rules-before.json"
fi
- name: Run Commit Mining
continue-on-error: true
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GEMINI_MODEL: gemini-2.5-flash
GEMINI_DEBUG: 'true'
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_MODEL: ${{ secrets.OPENAI_MODEL }}
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
DEEPSEEK_MODEL: ${{ secrets.DEEPSEEK_MODEL }}
DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }}
QWEN_MODEL: ${{ secrets.QWEN_MODEL }}
LLAMA_API_KEY: ${{ secrets.LLAMA_API_KEY }}
LLAMA_MODEL: ${{ secrets.LLAMA_MODEL }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
MISTRAL_MODEL: ${{ secrets.MISTRAL_MODEL }}
run: |
java -jar sandbox_mining_core/target/sandbox-mining-core.jar \
--config .github/refactoring-mining/repos.yml \
--state .github/refactoring-mining/state.json \
--sandbox-root . \
--batch-size ${{ github.event.inputs.batch_size || '200' }} \
--commits-per-request 4 \
--output docs/mining-report/ \
${{ github.event.inputs.llm_provider != '' && format('--llm-provider {0}', github.event.inputs.llm_provider) || '' }}
- name: Reconcile staged mining candidates
if: always()
run: |
BEFORE_KNOWN="$RUNNER_TEMP/known-rules-before.json"
CURRENT_KNOWN="docs/mining-report/known-rules.json"
CANDIDATE_DIR="mining-candidates"
if [ ! -f "$CURRENT_KNOWN" ]; then
echo "No known-rules.json found after mining; skipping candidate reconciliation."
exit 0
fi
python3 - "$BEFORE_KNOWN" "$CURRENT_KNOWN" "$CANDIDATE_DIR" <<'PY'
import json
import pathlib
import sys
before_path = pathlib.Path(sys.argv[1])
known_path = pathlib.Path(sys.argv[2])
candidate_dir = pathlib.Path(sys.argv[3])
def load_rules(path):
if not path.exists():
return {"version": 1, "rules": []}
with path.open(encoding="utf-8") as handle:
return json.load(handle)
before = load_rules(before_path)
current = load_rules(known_path)
before_commits = {
rule.get("sourceCommit")
for rule in before.get("rules", [])
if rule.get("sourceCommit")
}
candidate_commits = set()
if candidate_dir.exists():
for candidate_path in candidate_dir.glob("*-candidate.json"):
try:
with candidate_path.open(encoding="utf-8") as handle:
candidate = json.load(handle)
commit = candidate.get("sourceCommit")
if commit:
candidate_commits.add(commit)
except Exception as exc:
print(f"Warning: could not read candidate {candidate_path}: {exc}", file=sys.stderr)
rules = current.get("rules", [])
kept = [
rule for rule in rules
if rule.get("sourceCommit") in before_commits
or rule.get("sourceCommit") in candidate_commits
]
removed = len(rules) - len(kept)
if removed:
current["rules"] = kept
with known_path.open("w", encoding="utf-8") as handle:
json.dump(current, handle, indent=2)
handle.write("\n")
print(
"Candidate reconciliation: "
f"kept {len(kept)} known rules, "
f"removed {removed} non-staged new rules, "
f"candidate commits {len(candidate_commits)}"
)
PY
- name: Post-run diagnostics
if: always()
run: |
STATS_FILE="docs/mining-report/statistics.json"
if [ -f "$STATS_FILE" ]; then
API_CALLS=$(python3 -c "import json; d=json.load(open('$STATS_FILE')); print(d.get('runMetadata',{}).get('apiCallsMade',0))" 2>/dev/null || echo "?")
DEFERRED=$(python3 -c "import json; d=json.load(open('$STATS_FILE')); print(d.get('runMetadata',{}).get('deferredCommits',0))" 2>/dev/null || echo "?")
PROCESSED=$(python3 -c "import json; d=json.load(open('$STATS_FILE')); print(d.get('totalProcessed',0))" 2>/dev/null || echo "?")
echo "### ⛏️ Mining Run Diagnostics" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| API Calls | $API_CALLS |" >> $GITHUB_STEP_SUMMARY
echo "| Commits Processed | $PROCESSED |" >> $GITHUB_STEP_SUMMARY
echo "| Deferred Commits | $DEFERRED |" >> $GITHUB_STEP_SUMMARY
if [ "$API_CALLS" = "0" ] && [ "$DEFERRED" != "0" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **Warning:** No API calls were made but there are deferred commits." >> $GITHUB_STEP_SUMMARY
echo "Possible causes: API key expired/missing, all diffs filtered out, or API rate-limited." >> $GITHUB_STEP_SUMMARY
fi
else
echo "### ⚠️ Mining Run Diagnostics" >> $GITHUB_STEP_SUMMARY
echo "statistics.json not found — mining may have failed before producing output." >> $GITHUB_STEP_SUMMARY
fi
- name: Commit State
id: commit_state
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .github/refactoring-mining/state.json
# Include known-rules.json if it was created/updated
if [ -f docs/mining-report/known-rules.json ]; then
git add docs/mining-report/known-rules.json
fi
# Include staged mining candidates if they were created/updated
CANDIDATE_DIR="mining-candidates"
if [ -d "$CANDIDATE_DIR" ]; then
git add "$CANDIDATE_DIR"/*.json 2>/dev/null || true
fi
# Include auto-generated .sandbox-hint files from HintFileUpdater
HINT_DIR="sandbox_common_core/src/main/resources/org/sandbox/jdt/triggerpattern/internal"
if [ -d "$HINT_DIR" ]; then
NEW_HINTS=$(git ls-files --others --exclude-standard "$HINT_DIR"/*.sandbox-hint 2>/dev/null || true)
if [ -n "$NEW_HINTS" ]; then
echo "Auto-generated hint files found:"
echo "$NEW_HINTS"
git add $HINT_DIR/*.sandbox-hint
fi
fi
if git diff --cached --quiet; then
echo "No state changes to commit."
echo "state_updated=false" >> "$GITHUB_OUTPUT"
exit 0
fi
BRANCH="mining/state-update"
git stash --include-untracked
git checkout -b "$BRANCH"
if ! git stash pop; then
echo "Failed to apply stashed changes; aborting state update." >&2
exit 1
fi
if [ ! -f .github/refactoring-mining/state.json ]; then
echo "state.json not found after applying stash; aborting." >&2
exit 1
fi
git add .github/refactoring-mining/state.json
if [ -f docs/mining-report/known-rules.json ]; then
git add docs/mining-report/known-rules.json
fi
# Re-add staged mining candidates after stash pop
if [ -d "$CANDIDATE_DIR" ]; then
git add "$CANDIDATE_DIR"/*.json 2>/dev/null || true
fi
# Re-add hint files after stash pop
if [ -d "$HINT_DIR" ]; then
git add $HINT_DIR/*.sandbox-hint 2>/dev/null || true
fi
git commit -m "mining: Update state + known rules + candidates $(date +%Y-%m-%d)"
git push origin "$BRANCH" --force
echo "state_updated=true" >> "$GITHUB_OUTPUT"
- name: Create Issues for new GREEN findings
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
EVALS_FILE="docs/mining-report/evaluations.json"
KNOWN_FILE="docs/mining-report/known-rules.json"
if [ ! -f "$EVALS_FILE" ]; then
echo "No evaluations file found; skipping issue creation."
exit 0
fi
# Extract GREEN+VALID evaluations not yet in known-rules.json
python3 -c "
import json, sys
evals = json.load(open('$EVALS_FILE'))
known_commits = set()
if __import__('os').path.exists('$KNOWN_FILE'):
known = json.load(open('$KNOWN_FILE'))
known_commits = {r.get('sourceCommit','') for r in known.get('rules',[])}
new_green = [e for e in evals
if e.get('trafficLight') == 'GREEN'
and e.get('dslValidationResult') == 'VALID'
and e.get('relevant', False)
and e.get('commitHash','') not in known_commits
and e.get('dslRule')]
# Limit to 5 issues per run to avoid issue spam during catch-up phases
for e in new_green[:5]:
print(json.dumps({
'summary': e.get('summary','Unknown'),
'category': e.get('category','Unknown'),
'dslRule': e.get('dslRule',''),
'targetHintFile': e.get('targetHintFile',''),
'commitHash': e.get('commitHash','')
}))
" 2>/dev/null | while IFS= read -r line; do
SUMMARY=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['summary'])")
CATEGORY=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['category'])")
DSL_RULE=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['dslRule'])")
TARGET=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['targetHintFile'])")
COMMIT=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['commitHash'])")
# Check if issue already exists
EXISTING=$(gh issue list --search "🟢 $CATEGORY — $SUMMARY" --json number -q '.[0].number' 2>/dev/null || true)
if [ -n "$EXISTING" ]; then
echo "Issue already exists for: $SUMMARY (#$EXISTING)"
continue
fi
gh issue create \
--title "🟢 New DSL Rule: $CATEGORY — $SUMMARY" \
--body "## DSL Rule
\`\`\`
$DSL_RULE
\`\`\`
## Target File
$TARGET
## Source
Commit: $COMMIT
Mining Run: #${{ github.run_number }}" \
--label "dsl-rule,green,automated" 2>/dev/null || echo "Could not create issue for: $SUMMARY"
done
- name: Create Issues for DSL Enhancement needs
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
KNOWN_FILE="docs/mining-report/known-rules.json"
if [ ! -f "$KNOWN_FILE" ]; then
echo "No known-rules.json found; skipping DSL enhancement issues."
exit 0
fi
# Extract rules with NEEDS_DSL_EXTENSION status, group by limitation
python3 -c "
import json, sys
known = json.load(open('$KNOWN_FILE'))
needs_ext = [r for r in known.get('rules', []) if r.get('status') == 'NEEDS_DSL_EXTENSION']
if not needs_ext:
sys.exit(0)
# Group by simple heuristic on summary
groups = {}
for r in needs_ext:
summary = (r.get('summary') or '').lower()
if 'bitwise' in summary or ' | ' in (r.get('dslRule') or ''):
key = 'Bitwise operators'
elif 'try-with' in summary or 'autocloseable' in summary:
key = 'Statement wrapping (try-with-resources)'
elif 'generic' in summary or 'type parameter' in summary:
key = 'Generics / type-parameterized matching'
elif 'arity' in summary or 'vararg' in summary:
key = 'Arity changes / varargs'
else:
key = 'Other DSL limitations'
groups.setdefault(key, []).append(r)
for key, rules in sorted(groups.items(), key=lambda x: -len(x[1])):
print(json.dumps({'limitation': key, 'count': len(rules)}))
" 2>/dev/null | while IFS= read -r line; do
LIMITATION=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['limitation'])")
COUNT=$(echo "$line" | python3 -c "import json,sys; print(json.load(sys.stdin)['count'])")
# Check if issue already exists
EXISTING=$(gh issue list --search "🔧 DSL Enhancement: $LIMITATION" --json number -q '.[0].number' 2>/dev/null || true)
if [ -n "$EXISTING" ]; then
echo "DSL enhancement issue already exists for: $LIMITATION (#$EXISTING)"
continue
fi
gh issue create \
--title "🔧 DSL Enhancement: $LIMITATION ($COUNT rules blocked)" \
--body "## DSL Limitation
**$LIMITATION**
## Impact
**$COUNT** discovered transformation rules cannot be implemented because of this DSL limitation.
## Action Needed
Extend the TriggerPattern DSL to support this pattern category.
_Auto-generated by mining workflow run #${{ github.run_number }}._" \
--label "dsl-enhancement,automated" 2>/dev/null || echo "Could not create issue for: $LIMITATION"
done
- name: Auto-merge state update
if: steps.commit_state.outputs.state_updated == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Close any existing PR from this branch first (keep the branch so we can reuse it)
EXISTING_PR=$(gh pr list --head "mining/state-update" --json number -q '.[0].number' 2>/dev/null || true)
if [ -n "$EXISTING_PR" ]; then
gh pr close "$EXISTING_PR" 2>/dev/null || true
fi
# Create new PR and merge it
gh pr create \
--base main \
--head "mining/state-update" \
--title "mining: Update state $(date +%Y-%m-%d)" \
--body "Automated state update from mining workflow run #${{ github.run_number }}. This PR is auto-merged to persist the mining progress so the next run continues where this one left off."
gh pr merge "mining/state-update" --squash --auto --delete-branch \
|| gh pr merge "mining/state-update" --squash --delete-branch
- name: Deploy Mining Report to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/mining-report
publish_branch: gh-pages
destination_dir: mining-report
keep_files: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: 'mining: evaluation run ${{ github.run_number }}'
- name: Report Deployed URL
if: always()
run: |
echo "### 🔗 Deployed Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "📊 [View Mining Report](https://carstenartur.github.io/sandbox/mining-report/)" >> $GITHUB_STEP_SUMMARY
- name: Upload Artifacts
uses: actions/upload-artifact@v7
if: always()
with:
name: mining-report-${{ github.run_number }}
path: |
docs/mining-report/
mining-candidates/
if-no-files-found: ignore