-
Notifications
You must be signed in to change notification settings - Fork 8.5k
276 lines (231 loc) · 11.3 KB
/
py_autofix.yml
File metadata and controls
276 lines (231 loc) · 11.3 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
name: autofix.ci
on:
pull_request:
paths:
- "**/*.py"
- "src/lfx/src/lfx/components/**"
- "scripts/build_component_index.py"
env:
PYTHON_VERSION: "3.13"
jobs:
lint:
name: Run Ruff Check and Format
if: ${{ github.actor != 'github-actions[bot]' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 50
- name: "Setup Environment"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
python-version: ${{ env.PYTHON_VERSION }}
prune-cache: false
- run: uv run ruff check --fix-only .
- run: uv run ruff format . --config pyproject.toml
- name: Check if last commit is from autofix bot
id: check_autofix
run: |
set -euo pipefail
# Try to get author info from the event payload first
LAST_AUTHOR_NAME=""
LAST_AUTHOR_EMAIL=""
if [ -f "$GITHUB_EVENT_PATH" ]; then
LAST_AUTHOR_NAME=$(jq -r '.head_commit.author.name // .pull_request.head.user.login // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
LAST_AUTHOR_EMAIL=$(jq -r '.head_commit.author.email // .pull_request.head.user.email // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
fi
# Fallback to git to ensure we have exact last commit author if payload is incomplete
if [ -z "${LAST_AUTHOR_NAME}" ] || [ "${LAST_AUTHOR_NAME}" = "null" ]; then
LAST_AUTHOR_NAME=$(git log -1 --pretty=format:'%an' || echo "")
fi
if [ -z "${LAST_AUTHOR_EMAIL}" ] || [ "${LAST_AUTHOR_EMAIL}" = "null" ]; then
LAST_AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae' || echo "")
fi
echo "Detected Last Author: $LAST_AUTHOR_NAME <$LAST_AUTHOR_EMAIL>"
# Known bot names / emails used by autofix action (keep these)
BOT_NAMES=("autofix-ci" "autofix-ci[bot]" "autofix-ci[bot]@users.noreply.github.com")
BOT_EMAILS=("autofix-ci[bot]@users.noreply.github.com")
skip_autofix=false
# Explicit name/email checks (existing behavior)
for b in "${BOT_NAMES[@]}"; do
if [[ "$LAST_AUTHOR_NAME" == "$b" ]] || [[ "$LAST_AUTHOR_NAME" == *"$b"* ]]; then
skip_autofix=true
fi
done
for e in "${BOT_EMAILS[@]}"; do
if [[ "$LAST_AUTHOR_EMAIL" == "$e" ]] || [[ "$LAST_AUTHOR_EMAIL" == *"$e"* ]]; then
skip_autofix=true
fi
done
# --- New: scan recent commits for any bot-like author/email or autofix references ---
RECENT_COMMITS=$(git log -n 10 --pretty=format:'%an <%ae> || %s' || true)
echo "Recent commits (last 10):"
echo "$RECENT_COMMITS"
# Patterns to treat as bot/autofix activity; extend as necessary
BOT_PATTERNS='autofix-ci|autofix.ci|autofix-ci\[bot\]|autofix-ci\[bot\]@users.noreply.github.com|autofix|autofix\.ci|github-actions\[bot\]|\[autofix\]'
if echo "$RECENT_COMMITS" | grep -Eiq "$BOT_PATTERNS"; then
echo "Detected recent autofix/bot activity in commit history. Skipping autofix to avoid repeated bot commits."
skip_autofix=true
fi
# Also catch generic [bot] no-reply email authors (covers many GitHub apps)
if echo "$RECENT_COMMITS" | grep -Eiq '\[bot\]@users.noreply.github.com'; then
echo "Detected commits from a GitHub app/bot (..[bot]@users.noreply.github.com). Skipping autofix."
skip_autofix=true
fi
if $skip_autofix; then
echo "skip_autofix=true" >> "$GITHUB_OUTPUT"
fi
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27
if: steps.check_autofix.outputs.skip_autofix != 'true'
update-starter-projects:
name: Update Starter Projects
if: ${{ github.actor != 'github-actions[bot]' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 50
- name: "Setup Environment"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
python-version: ${{ env.PYTHON_VERSION }}
prune-cache: false
- name: "Install dependencies"
run: |
uv sync
uv pip install -e .
- name: Run starter projects update
run: uv run python scripts/ci/update_starter_projects.py
- name: Check if last commit is from autofix bot
id: check_autofix
run: |
set -euo pipefail
# Try to get author info from the event payload first
LAST_AUTHOR_NAME=""
LAST_AUTHOR_EMAIL=""
if [ -f "$GITHUB_EVENT_PATH" ]; then
LAST_AUTHOR_NAME=$(jq -r '.head_commit.author.name // .pull_request.head.user.login // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
LAST_AUTHOR_EMAIL=$(jq -r '.head_commit.author.email // .pull_request.head.user.email // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
fi
# Fallback to git to ensure we have exact last commit author if payload is incomplete
if [ -z "${LAST_AUTHOR_NAME}" ] || [ "${LAST_AUTHOR_NAME}" = "null" ]; then
LAST_AUTHOR_NAME=$(git log -1 --pretty=format:'%an' || echo "")
fi
if [ -z "${LAST_AUTHOR_EMAIL}" ] || [ "${LAST_AUTHOR_EMAIL}" = "null" ]; then
LAST_AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae' || echo "")
fi
echo "Detected Last Author: $LAST_AUTHOR_NAME <$LAST_AUTHOR_EMAIL>"
# Known bot names / emails used by autofix action (keep these)
BOT_NAMES=("autofix-ci" "autofix-ci[bot]" "autofix-ci[bot]@users.noreply.github.com")
BOT_EMAILS=("autofix-ci[bot]@users.noreply.github.com")
skip_autofix=false
# Explicit name/email checks (existing behavior)
for b in "${BOT_NAMES[@]}"; do
if [[ "$LAST_AUTHOR_NAME" == "$b" ]] || [[ "$LAST_AUTHOR_NAME" == *"$b"* ]]; then
skip_autofix=true
fi
done
for e in "${BOT_EMAILS[@]}"; do
if [[ "$LAST_AUTHOR_EMAIL" == "$e" ]] || [[ "$LAST_AUTHOR_EMAIL" == *"$e"* ]]; then
skip_autofix=true
fi
done
# --- New: scan recent commits for any bot-like author/email or autofix references ---
RECENT_COMMITS=$(git log -n 10 --pretty=format:'%an <%ae> || %s' || true)
echo "Recent commits (last 10):"
echo "$RECENT_COMMITS"
# Patterns to treat as bot/autofix activity; extend as necessary
BOT_PATTERNS='autofix-ci|autofix.ci|autofix-ci\[bot\]|autofix-ci\[bot\]@users.noreply.github.com|autofix|autofix\.ci|github-actions\[bot\]|\[autofix\]'
if echo "$RECENT_COMMITS" | grep -Eiq "$BOT_PATTERNS"; then
echo "Detected recent autofix/bot activity in commit history. Skipping autofix to avoid repeated bot commits."
skip_autofix=true
fi
# Also catch generic [bot] no-reply email authors (covers many GitHub apps)
if echo "$RECENT_COMMITS" | grep -Eiq '\[bot\]@users.noreply.github.com'; then
echo "Detected commits from a GitHub app/bot (..[bot]@users.noreply.github.com). Skipping autofix."
skip_autofix=true
fi
if $skip_autofix; then
echo "skip_autofix=true" >> "$GITHUB_OUTPUT"
fi
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27
if: steps.check_autofix.outputs.skip_autofix != 'true'
update-component-index:
name: Update Component Index
if: ${{ github.actor != 'github-actions[bot]' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 50
- name: "Setup Environment"
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
python-version: ${{ env.PYTHON_VERSION }}
prune-cache: false
- name: "Install dependencies"
run: uv sync --dev --project .
- name: Build component index
env:
LFX_DEV: "1"
run: make build_component_index
- name: Check if last commit is from autofix bot
id: check_autofix
run: |
set -euo pipefail
# Try to get author info from the event payload first
LAST_AUTHOR_NAME=""
LAST_AUTHOR_EMAIL=""
if [ -f "$GITHUB_EVENT_PATH" ]; then
LAST_AUTHOR_NAME=$(jq -r '.head_commit.author.name // .pull_request.head.user.login // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
LAST_AUTHOR_EMAIL=$(jq -r '.head_commit.author.email // .pull_request.head.user.email // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
fi
# Fallback to git to ensure we have exact last commit author if payload is incomplete
if [ -z "${LAST_AUTHOR_NAME}" ] || [ "${LAST_AUTHOR_NAME}" = "null" ]; then
LAST_AUTHOR_NAME=$(git log -1 --pretty=format:'%an' || echo "")
fi
if [ -z "${LAST_AUTHOR_EMAIL}" ] || [ "${LAST_AUTHOR_EMAIL}" = "null" ]; then
LAST_AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae' || echo "")
fi
echo "Detected Last Author: $LAST_AUTHOR_NAME <$LAST_AUTHOR_EMAIL>"
# Known bot names / emails used by autofix action (keep these)
BOT_NAMES=("autofix-ci" "autofix-ci[bot]" "autofix-ci[bot]@users.noreply.github.com")
BOT_EMAILS=("autofix-ci[bot]@users.noreply.github.com")
skip_autofix=false
# Explicit name/email checks (existing behavior)
for b in "${BOT_NAMES[@]}"; do
if [[ "$LAST_AUTHOR_NAME" == "$b" ]] || [[ "$LAST_AUTHOR_NAME" == *"$b"* ]]; then
skip_autofix=true
fi
done
for e in "${BOT_EMAILS[@]}"; do
if [[ "$LAST_AUTHOR_EMAIL" == "$e" ]] || [[ "$LAST_AUTHOR_EMAIL" == *"$e"* ]]; then
skip_autofix=true
fi
done
# --- New: scan recent commits for any bot-like author/email or autofix references ---
RECENT_COMMITS=$(git log -n 10 --pretty=format:'%an <%ae> || %s' || true)
echo "Recent commits (last 10):"
echo "$RECENT_COMMITS"
# Patterns to treat as bot/autofix activity; extend as necessary
BOT_PATTERNS='autofix-ci|autofix.ci|autofix-ci\[bot\]|autofix-ci\[bot\]@users.noreply.github.com|autofix|autofix\.ci|github-actions\[bot\]|\[autofix\]'
if echo "$RECENT_COMMITS" | grep -Eiq "$BOT_PATTERNS"; then
echo "Detected recent autofix/bot activity in commit history. Skipping autofix to avoid repeated bot commits."
skip_autofix=true
fi
# Also catch generic [bot] no-reply email authors (covers many GitHub apps)
if echo "$RECENT_COMMITS" | grep -Eiq '\[bot\]@users.noreply.github.com'; then
echo "Detected commits from a GitHub app/bot (..[bot]@users.noreply.github.com). Skipping autofix."
skip_autofix=true
fi
if $skip_autofix; then
echo "skip_autofix=true" >> "$GITHUB_OUTPUT"
fi
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27
if: steps.check_autofix.outputs.skip_autofix != 'true'