-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathaction.yml
More file actions
394 lines (377 loc) · 17 KB
/
action.yml
File metadata and controls
394 lines (377 loc) · 17 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
387
388
389
390
391
392
393
394
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
name: "Ultralytics Actions"
author: "Ultralytics"
description: "Optimize code and docs with official Ultralytics Actions for syntax, spelling, and link checks."
branding:
icon: "code"
color: "blue"
inputs:
token:
description: "GitHub token"
required: true
labels:
description: "Run issue and PR auto-labeling"
required: false
default: "false"
python:
description: "Run Python formatting"
required: false
default: "false"
python_docstrings:
description: "Run Python docstring formatting"
required: false
default: "true"
markdown:
description: "Run Markdown formatting (deprecated in favor of prettier)"
required: false
default: "false"
biome:
description: "Run Biome formatting"
required: false
default: "false"
prettier:
description: "Run Prettier formatting for JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, YAML"
required: false
default: "false"
swift:
description: "Run Swift formatting"
required: false
default: "false"
dart:
description: "Run Dart formatting"
required: false
default: "false"
spelling:
description: "Run Spelling checks"
required: false
default: "false"
links:
description: "Run Broken Links checks"
required: false
default: "false"
summary:
description: "Run PR Summary"
required: false
default: "false"
review:
description: "Run PR Review"
required: false
default: "true"
header:
description: "File header"
required: false
default: ""
brave_api_key:
description: "Brave API Key"
required: false
openai_api_key:
description: "OpenAI API Key"
required: false
anthropic_api_key:
description: "Anthropic API Key"
required: false
model:
description: "AI Model - defaults to GPT-5.4 or Sonnet 4.6 based on API key"
required: false
review_model:
description: "AI Model for PR reviews (optional, defaults to gpt-5.4)"
required: false
first_issue_response:
description: "Example response to a new issue"
required: false
first_pr_response:
description: "Example response to a new PR"
required: false
bun_update:
description: "Run bun update to update bun.lock if bun project detected"
required: false
default: "false"
github_username:
description: "GitHub username for commits"
required: false
default: "UltralyticsAssistant"
# default: "github-actions[bot]"
github_email:
description: "GitHub email for commits"
required: false
default: "web@ultralytics.com"
# default: "41898282+github-actions[bot]@users.noreply.github.com"
runs:
using: "composite"
steps:
- uses: astral-sh/setup-uv@v7
with:
ignore-empty-workdir: true
enable-cache: false
version: "0.9.4"
- name: Install Dependencies
# Note tomli required for codespell with pyproject.toml
env:
INPUTS_SPELLING: ${{ inputs.spelling }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF: ${{ github.ref }}
run: |
echo "::group::Install Dependencies"
# Install from git branch if testing in ultralytics/actions repo, otherwise from PyPI
if [ "$GITHUB_REPOSITORY" = "ultralytics/actions" ]; then
echo "Installing from git branch: $GITHUB_REF"
packages="git+https://github.com/ultralytics/actions@${GITHUB_REF#refs/heads/}"
else
# packages="ultralytics-actions"
packages="git+https://github.com/ultralytics/actions@main"
fi
if [ "$INPUTS_SPELLING" = "true" ]; then
packages="$packages codespell tomli"
fi
# On macOS, don't use sudo as it can cause environment issues
if [ "$(uname)" = "Darwin" ]; then
uv pip install --system --break-system-packages $packages
else
sudo env "PATH=$PATH" uv pip install --system --break-system-packages $packages
fi
ultralytics-actions-info
echo "::endgroup::"
shell: bash
# Checkout Repository ----------------------------------------------------------------------------------------------
- name: Checkout Repository
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'review_requested'
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
token: ${{ inputs.token }}
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 2
# File header ------------------------------------------------------------------------------------------------------
- name: File Header
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && (github.event.action == 'opened' || github.event.action == 'synchronize')
env:
HEADER: ${{ inputs.header }}
run: ultralytics-actions-headers
shell: bash
continue-on-error: false
# Python formatting ------------------------------------------------------------------------------------------------
# Ignores the following Docs rules to match Google-style docstrings:
# D100: Missing docstring in public module
# D104: Missing docstring in public package
# D203: 1 blank line required before class docstring
# D205: 1 blank line required between summary line and description
# D212: Multi-line docstring summary should start at the first line
# D213: Multi-line docstring summary should start at the second line
# D401: First line of docstring should be in imperative mood
# D406: Section name should end with a newline
# D407: Missing dashed underline after section
# D413: Missing blank line after last section
# --target-version is Python 3.9 for --extend-select UP (pyupgrade)
- name: Run Python
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.python == 'true' && (github.event.action == 'opened' || github.event.action == 'synchronize')
run: |
echo "::group::Run Python"
ruff check \
--fix \
--unsafe-fixes \
--extend-select F,I,D,UP,RUF,FA \
--target-version py39 \
--ignore D100,D104,D203,D205,D212,D213,D401,D406,D407,D413,RUF001,RUF002,RUF012 \
. || true
ruff format \
--line-length 120 \
. || true
if [ "${{ inputs.python_docstrings }}" = "true" ]; then
ultralytics-actions-format-python-docstrings . || true
fi
echo "::endgroup::"
shell: bash
continue-on-error: true
# Biome (JavaScript, TypeScript, JSON, JSX, TSX) ------------------------------------------------------------------
- name: Run Biome
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.biome == 'true' && (github.event.action == 'opened' || github.event.action == 'synchronize')
run: |
echo "::group::Run Biome"
if [ -f "biome.json" ] || [ -f "biome.jsonc" ]; then
npm install -g @biomejs/biome@latest
npx biome --version
npx biome check --write --line-width=120 --max-diagnostics=1000 --diagnostic-level=error --unsafe .
else
echo "⚠️ No biome.json found - skipping Biome formatting. Add biome.json to enable."
fi
echo "::endgroup::"
shell: bash
continue-on-error: true
# Prettier (JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, YAML) -------------
- name: Run Prettier
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && (inputs.prettier == 'true' || inputs.markdown == 'true') && (github.event.action == 'opened' || github.event.action == 'synchronize')
run: |
echo "::group::Run Prettier"
npm install -g prettier@3.6.2 prettier-plugin-sh
ultralytics-actions-update-markdown-code-blocks
npx prettier --write --list-different --print-width 120 "**/*.{js,jsx,ts,tsx,css,less,scss,json,yml,yaml,html,vue,svelte}" '!**/*lock.{json,yaml,yml}' '!**/*.lock' '!**/model.json' '!**/*.min.js' '!**/*.min.css'
# Bash file format
if find . -name "*.sh" -type f | grep -q .; then
npx prettier --write --list-different --print-width 120 --plugin=$(npm root -g)/prettier-plugin-sh/lib/index.cjs "**/*.sh"
fi
# Handle Markdown separately
find . -name "*.md" ! -path "*/docs/*" -exec npx prettier --write --list-different --print-width 120 {} +
if [ -d "./docs" ]; then
find ./docs -name "*.md" ! -path "*/reference/*" -exec npx prettier --tab-width 4 --print-width 120 --write --list-different {} +
fi
echo "::endgroup::"
shell: bash
continue-on-error: true
# Swift formatting -------------------------------------------------------------------------------------------------
- name: Run Swift Formatter
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.swift == 'true' && (github.event.action == 'opened' || github.event.action == 'synchronize')
run: |
echo "::group::Run Swift Formatter"
brew install swift-format
swift-format --in-place --recursive .
echo "::endgroup::"
shell: bash
continue-on-error: true
# Dart formatting --------------------------------------------------------------------------------------------------
- name: Setup Dart SDK
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.dart == 'true' && (github.event.action == 'opened' || github.event.action == 'synchronize')
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Run Dart Formatter
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.dart == 'true' && (github.event.action == 'opened' || github.event.action == 'synchronize')
run: |
dart format .
shell: bash
continue-on-error: true # Important so that commit step can pick up changes
# Spelling ---------------------------------------------------------------------------------------------------------
# --ignore-regex '\b[a-z]+[A-Z][a-zA-Z]*\b' ignores camelCase words (e.g. repoRes, dateA) to prevent false positives
- name: Run Codespell
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.spelling == 'true' && (github.event.action == 'opened' || github.event.action == 'synchronize')
run: |
echo "::group::Run Codespell"
codespell \
--builtin clear,rare,informal,en-GB_to_en-US \
--write-changes \
--uri-ignore-words-list * \
--ignore-regex '\b[a-z]+[A-Z][a-zA-Z]*\b' \
--ignore-words-list "nin,cancelled,MapPin,couldn,grey,writeable,RepResNet,Idenfy,WIT,Smoot,EHR,ROUGE,ALS,Carmel,FPR,Hach,Calle,ore,COO,MOT,crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall,skelton,goin,cann,CANN" \
--skip "*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,*lock*,__pycache__*,*.ico,*.jpg,*.png,*.webp,*.avif,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml,action.yml"
echo "::endgroup::"
shell: bash
continue-on-error: true
# PR Summary -------------------------------------------------------------------------------------------------------
- name: PR Summary
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.summary == 'true' && github.event.action == 'closed'
env:
GITHUB_TOKEN: ${{ inputs.token }}
BRAVE_API_KEY: ${{ inputs.brave_api_key }}
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }}
MODEL: ${{ inputs.model }}
run: ultralytics-actions-summarize-pr
shell: bash
continue-on-error: true
# Autolabel Issues and PRs (labels and first interaction) ---------------------------------------------------------
- name: Autolabel Issues and PRs
if: inputs.labels == 'true' && (github.event.action == 'opened' || github.event.action == 'created')
env:
GITHUB_TOKEN: ${{ inputs.token }}
FIRST_ISSUE_RESPONSE: ${{ inputs.first_issue_response }}
FIRST_PR_RESPONSE: ${{ inputs.first_pr_response }}
BRAVE_API_KEY: ${{ inputs.brave_api_key }}
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }}
MODEL: ${{ inputs.model }}
REVIEW_MODEL: ${{ inputs.review_model }}
REVIEW: ${{ inputs.review }}
run: ultralytics-actions-first-interaction
shell: bash
continue-on-error: true
# PR Review --------------------------------------------------------------------------------------------------------
- name: PR Review
if: |
(github.event_name == 'pull_request' || github.event_name == 'pull_request_target') &&
github.event.action == 'review_requested' &&
github.event.requested_reviewer.login == inputs.github_username
env:
GITHUB_TOKEN: ${{ inputs.token }}
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }}
MODEL: ${{ inputs.model }}
REVIEW_MODEL: ${{ inputs.review_model }}
run: ultralytics-actions-review-pr
shell: bash
continue-on-error: true
# Bun Update ---------------------------------------------------------------------------------------------------------
- name: Bun Update
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.bun_update == 'true' && github.event.action == 'opened'
run: |
echo "::group::Bun Update"
if [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
npm install -g bun
echo "Updating root..."
bun update --latest
for pkg in apps/*/package.json packages/*/package.json; do
[ -f "$pkg" ] || continue
dir=$(dirname "$pkg")
echo "Updating $dir..."
(cd "$dir" && bun update --latest)
done
echo "Resolving bun.lock versions..."
bun update
else
echo "No bun.lock found - skipping Bun update"
fi
echo "::endgroup::"
shell: bash
continue-on-error: true
# Commit Changes ---------------------------------------------------------------------------------------------------
- name: Commit and Push Changes
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && (github.event.action == 'opened' || github.event.action == 'synchronize')
env:
GITHUB_USERNAME: ${{ inputs.github_username }}
GITHUB_EMAIL: ${{ inputs.github_email }}
run: |
echo "::group::Commit and Push Changes"
COMMIT_MSG="Auto-format by https://ultralytics.com/actions"
# Check if last two commits were both auto-format to prevent recursive loops
LAST_TWO=$(git log -2 --pretty=format:'%s' 2>/dev/null || echo "")
MATCH_COUNT=$(printf '%s\n' "$LAST_TWO" | grep -Fxc "$COMMIT_MSG" || true)
if [ "$MATCH_COUNT" -ge 2 ]; then
echo "Skipping commit: last two commits were auto-format"
echo "::endgroup::"
exit 0
fi
git config --global user.name "$GITHUB_USERNAME"
git config --global user.email "$GITHUB_EMAIL"
git add .
git reset HEAD -- .github/workflows/ # workflow changes are not permitted with default token
if ! git diff --staged --quiet; then
git commit -m "$COMMIT_MSG"
git push
else
echo "No changes to commit"
fi
echo "::endgroup::"
shell: bash
continue-on-error: true
# Broken links -----------------------------------------------------------------------------------------------------
- name: Broken Link Checker
if: inputs.links == 'true' && github.event.action != 'closed'
uses: lycheeverse/lychee-action@v2.8.0
with:
# Check all markdown and html files in repo. Ignores the following status codes to reduce false positives:
# - 403(OpenVINO, "forbidden")
# - 429(Instagram, "too many requests")
# - 500(Zenodo, "cached")
# - 502(Zenodo, "bad gateway")
# - 999(LinkedIn, "unknown status code")
args: |
--scheme https
--timeout 60
--insecure
--accept 100..=103,200..=299,401,403,429,500,502,999
--exclude-all-private
--exclude "https?://(www\.)?(github\.com|linkedin\.com|twitter\.com|instagram\.com|kaggle\.com|fonts\.gstatic\.com|url\.com)"
"./**/*.md"
"./**/*.html"
token: ${{ inputs.token }}
output: ../lychee/results.md
fail: true
continue-on-error: false