-
Notifications
You must be signed in to change notification settings - Fork 43
163 lines (146 loc) · 6.19 KB
/
auto-fix-issues.yml
File metadata and controls
163 lines (146 loc) · 6.19 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
name: Auto Fix Issues
on:
schedule:
- cron: '*/10 * * * *'
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number (empty = pick oldest)'
required: false
permissions:
contents: write
pull-requests: write
issues: write
jobs:
check:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.pick.outputs.matrix }}
steps:
- id: pick
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
ISSUE_NUMBER: ${{ inputs.issue_number || '' }}
run: |
REPO="${{ github.repository }}"
# Collect issues
if [ -n "$ISSUE_NUMBER" ]; then
ISSUES=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json number,title,body -q '[.]')
else
ISSUES=$(gh issue list --repo "$REPO" --label auto-fix --state open --limit 10 --json number,title,body)
fi
COUNT=$(echo "$ISSUES" | jq 'length')
if [ "$COUNT" -eq 0 ]; then
echo "No auto-fix issues"
echo "matrix=" >> "$GITHUB_OUTPUT"
exit 0
fi
# Collect open auto-fix PRs and their changed file paths
OPEN_PRS=$(gh pr list --repo "$REPO" --label auto-fix --state open \
--json number,headRefName,files --jq '[.[] | {number, branch: .headRefName, paths: [.files[].path]}]' 2>/dev/null || echo '[]')
# For each issue, check if an existing PR touches the same doc category
# Category = first two path segments under docs/en/ (e.g. docs/en/sql-reference, docs/en/guides)
MATRIX="[]"
for row in $(echo "$ISSUES" | jq -c '.[]'); do
NUM=$(echo "$row" | jq -r '.number')
TITLE=$(echo "$row" | jq -r '.title')
BODY=$(echo "$row" | jq -r '.body')
# Guess the doc category from issue title/body keywords
CATEGORY=""
TEXT=$(echo "${TITLE} ${BODY}" | tr '[:upper:]' '[:lower:]')
if echo "$TEXT" | grep -qE 'function|func[ _-]'; then
CATEGORY="docs/en/sql-reference/20-sql-functions"
elif echo "$TEXT" | grep -qE 'command|statement|ddl|dml|dql'; then
CATEGORY="docs/en/sql-reference/10-sql-commands"
elif echo "$TEXT" | grep -qE 'sql.reference|sql-reference'; then
CATEGORY="docs/en/sql-reference"
elif echo "$TEXT" | grep -qE 'guide|load|unload|stage|warehouse|security'; then
CATEGORY="docs/en/guides"
fi
# Find existing PR with overlapping category
EXISTING_BRANCH=""
EXISTING_PR=""
if [ -n "$CATEGORY" ]; then
MATCH=$(echo "$OPEN_PRS" | jq -c --arg cat "$CATEGORY" \
'[.[] | select(.paths[] | startswith($cat))] | first // empty')
if [ -n "$MATCH" ] && [ "$MATCH" != "null" ]; then
EXISTING_BRANCH=$(echo "$MATCH" | jq -r '.branch')
EXISTING_PR=$(echo "$MATCH" | jq -r '.number')
echo "Issue #${NUM} matches existing PR #${EXISTING_PR} (branch: ${EXISTING_BRANCH})"
fi
fi
# Mark in-progress
gh issue edit "$NUM" --repo "$REPO" --add-label auto-fix-in-progress --remove-label auto-fix
ENTRY=$(echo "$row" | jq -c --arg eb "$EXISTING_BRANCH" --arg ep "$EXISTING_PR" \
'. + {existing_branch: $eb, existing_pr: $ep}')
MATRIX=$(echo "$MATRIX" | jq -c --argjson e "$ENTRY" '. + [$e]')
done
if [ "$(echo "$MATRIX" | jq 'length')" -eq 0 ]; then
echo "matrix=" >> "$GITHUB_OUTPUT"
else
echo "matrix=$(echo "$MATRIX" | jq -c '{include: .}')" >> "$GITHUB_OUTPUT"
fi
fix:
needs: check
if: needs.check.outputs.matrix != ''
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.check.outputs.matrix) }}
max-parallel: 1
steps:
- uses: actions/checkout@v4
- name: Checkout databend source
uses: actions/checkout@v4
with:
repository: databendlabs/databend
path: _databend
sparse-checkout: src
fetch-depth: 1
- name: Fetch databend release tags
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
run: |
gh release list --repo databendlabs/databend --limit 50 \
--json tagName,publishedAt --jq '.[] | "\(.tagName) \(.publishedAt)"' \
> _databend/RELEASES.txt
- name: Install evot
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
run: |
for TAG in $(gh release list --repo evotai/evot --limit 10 --json tagName --jq '.[].tagName'); do
if gh release download "$TAG" --repo evotai/evot --pattern "evot-*-x86_64-unknown-linux-gnu.tar.gz" 2>/dev/null; then
echo "Downloaded evot from $TAG"
break
fi
done
tar -xzf evot-*.tar.gz && chmod +x bin/evot
mkdir -p ~/.evotai/lib
cp lib/*.node ~/.evotai/lib/
echo "$PWD/bin" >> "$GITHUB_PATH"
- name: Write evot.env
run: |
mkdir -p ~/.evotai
cat > ~/.evotai/evot.env << ENVEOF
EVOT_LLM_PROVIDER=anthropic
EVOT_LLM_ANTHROPIC_BASE_URL=${{ secrets.EVOT_LLM_ANTHROPIC_BASE_URL }}
EVOT_LLM_ANTHROPIC_API_KEY=${{ secrets.EVOT_LLM_ANTHROPIC_API_KEY }}
EVOT_LLM_ANTHROPIC_MODEL=${{ secrets.EVOT_LLM_ANTHROPIC_MODEL }}
EVOT_LLM_OPENAI_BASE_URL=${{ secrets.EVOT_LLM_OPENAI_BASE_URL }}
EVOT_LLM_OPENAI_API_KEY=${{ secrets.EVOT_LLM_OPENAI_API_KEY }}
EVOT_LLM_OPENAI_MODEL=${{ secrets.EVOT_LLM_OPENAI_MODEL }}
ENVEOF
sed -i 's/^[[:space:]]*//' ~/.evotai/evot.env
- name: Run
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bash .github/scripts/auto-fix.sh
env:
REPO: ${{ github.repository }}
ISSUE_JSON: ${{ toJson(matrix) }}
EXISTING_BRANCH: ${{ matrix.existing_branch }}
EXISTING_PR: ${{ matrix.existing_pr }}
GENERATOR_MODEL: ''
REVIEWER_MODEL: gpt-5.4
EVOT_ID: auto-fix-ci
GH_TOKEN: ${{ secrets.GH_PAT }}