Skip to content

Commit bee0668

Browse files
author
Alvaro Muñoz
committed
Add tests and update expected results
1 parent b80d3d5 commit bee0668

File tree

6 files changed

+561
-4
lines changed

6 files changed

+561
-4
lines changed
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# Ultralytics Actions 🚀, AGPL-3.0 License https://ultralytics.com/license
2+
3+
name: "Ultralytics Actions"
4+
author: "Ultralytics"
5+
description: "Optimize code and docs with official Ultralytics Actions for syntax, spelling, and link checks."
6+
branding:
7+
icon: "code"
8+
color: "blue"
9+
inputs:
10+
token:
11+
description: "GitHub token"
12+
required: true
13+
labels:
14+
description: "Run issue and PR auto-labeling"
15+
required: false
16+
default: "false"
17+
python:
18+
description: "Run Python formatting"
19+
required: false
20+
default: "false"
21+
markdown:
22+
description: "Run Markdown formatting (deprecated in favor of prettier)"
23+
required: false
24+
default: "false"
25+
prettier:
26+
description: "Run Prettier formatting for JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, YAML"
27+
required: false
28+
default: "false"
29+
swift:
30+
description: "Run Swift formatting"
31+
required: false
32+
default: "false"
33+
spelling:
34+
description: "Run Spelling checks"
35+
required: false
36+
default: "false"
37+
links:
38+
description: "Run Broken Links checks"
39+
required: false
40+
default: "false"
41+
summary:
42+
description: "Run PR Summary"
43+
required: false
44+
default: "false"
45+
openai_api_key:
46+
description: "OpenAI API Key"
47+
required: false
48+
openai_model:
49+
description: "OpenAI Model"
50+
required: false
51+
default: "gpt-4o"
52+
first_issue_response:
53+
description: "Example response to a new issue"
54+
required: false
55+
first_pr_response:
56+
description: "Example response to a new PR"
57+
required: false
58+
github_username:
59+
description: "GitHub username for commits"
60+
required: false
61+
default: "UltralyticsAssistant"
62+
github_email:
63+
description: "GitHub email for commits"
64+
required: false
65+
default: "[email protected]"
66+
runs:
67+
using: "composite"
68+
steps:
69+
- uses: astral-sh/setup-uv@v3
70+
- name: Install Dependencies
71+
# Note tomli required for codespell with pyproject.toml
72+
# For debug:
73+
# python -m pip install --upgrade pip wheel
74+
# pip install -q git+https://github.com/ultralytics/actions@main codespell tomli
75+
run: |
76+
packages="ultralytics-actions"
77+
if [ "${{ inputs.spelling }}" = "true" ]; then
78+
packages="$packages codespell tomli"
79+
fi
80+
81+
# On macOS, don't use sudo as it can cause environment issues
82+
if [ "$(uname)" = "Darwin" ]; then
83+
pip install -q $packages
84+
else
85+
sudo env "PATH=$PATH" uv pip install --system $packages
86+
fi
87+
88+
ultralytics-actions-info
89+
shell: bash
90+
91+
# Checkout Repository ----------------------------------------------------------------------------------------------
92+
- name: Checkout Repository
93+
if: github.event.action != 'closed'
94+
uses: actions/checkout@v4
95+
with:
96+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
97+
token: ${{ inputs.token }}
98+
ref: ${{ github.head_ref || github.ref }}
99+
fetch-depth: 0
100+
101+
# PR Summary -------------------------------------------------------------------------------------------------------
102+
- name: PR Summary
103+
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.summary == 'true' && github.event.action != 'synchronize'
104+
env:
105+
GITHUB_TOKEN: ${{ inputs.token }}
106+
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
107+
OPENAI_MODEL: ${{ inputs.openai_model }}
108+
run: |
109+
ultralytics-actions-summarize-pr
110+
shell: bash
111+
continue-on-error: true
112+
113+
# Python formatting ------------------------------------------------------------------------------------------------
114+
# Ignores the following Docs rules to match Google-style docstrings:
115+
# D100: Missing docstring in public module
116+
# D104: Missing docstring in public package
117+
# D203: 1 blank line required before class docstring
118+
# D205: 1 blank line required between summary line and description
119+
# D212: Multi-line docstring summary should start at the first line
120+
# D213: Multi-line docstring summary should start at the second line
121+
# D401: First line of docstring should be in imperative mood
122+
# D406: Section name should end with a newline
123+
# D407: Missing dashed underline after section
124+
# D413: Missing blank line after last section
125+
# --target-version is Python 3.8 for --extend-select UP (pyupgrade)
126+
- name: Run Python
127+
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.python == 'true' && github.event.action != 'closed'
128+
run: |
129+
ruff format \
130+
--line-length 120 \
131+
. || true
132+
ruff check \
133+
--fix \
134+
--unsafe-fixes \
135+
--extend-select I,D,UP \
136+
--target-version py38 \
137+
--ignore D100,D104,D203,D205,D212,D213,D401,D406,D407,D413 \
138+
. || true
139+
docformatter \
140+
--wrap-summaries 120 \
141+
--wrap-descriptions 120 \
142+
--pre-summary-newline \
143+
--close-quotes-on-newline \
144+
--in-place \
145+
--recursive \
146+
.
147+
shell: bash
148+
continue-on-error: true
149+
150+
# Prettier (JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, YAML) -------------
151+
- name: Run Prettier
152+
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && (inputs.prettier == 'true' || inputs.markdown == 'true') && github.event.action != 'closed'
153+
run: |
154+
ultralytics-actions-update-markdown-code-blocks
155+
npm install --global prettier
156+
npx prettier --write "**/*.{js,jsx,ts,tsx,css,less,scss,json,yml,yaml,html,vue,svelte}" '!**/*lock.{json,yaml,yml}' '!**/*.lock' '!**/model.json'
157+
# Handle Markdown separately
158+
find . -name "*.md" ! -path "*/docs/*" -exec npx prettier --write {} +
159+
if [ -d "./docs" ]; then
160+
find ./docs -name "*.md" ! -path "*/reference/*" -exec npx prettier --tab-width 4 --write {} +
161+
fi
162+
shell: bash
163+
continue-on-error: true
164+
165+
# - name: Fix MkDocs reference section changes
166+
# if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && (inputs.prettier == 'true' || inputs.markdown == 'true') && github.event.action != 'closed'
167+
# run: |
168+
# from pathlib import Path
169+
# for file in Path("./docs").rglob('*.md'):
170+
# content = file.read_text()
171+
# updated_content = content.replace(".\_","._")
172+
# file.write_text(updated_content)
173+
# shell: python
174+
# continue-on-error: true
175+
176+
# Swift formatting -------------------------------------------------------------------------------------------------
177+
- name: Run Swift Formatter
178+
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.swift == 'true' && github.event.action != 'closed'
179+
run: |
180+
brew install swift-format
181+
swift-format --in-place --recursive .
182+
shell: bash
183+
continue-on-error: true
184+
185+
# Spelling ---------------------------------------------------------------------------------------------------------
186+
- name: Run Codespell
187+
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && inputs.spelling == 'true' && github.event.action != 'closed'
188+
run: |
189+
codespell \
190+
--write-changes \
191+
--ignore-words-list "crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall,skelton,goin" \
192+
--skip "*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,*lock*,__pycache__*,*.ico,*.jpg,*.png,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml"
193+
shell: bash
194+
continue-on-error: true
195+
196+
# Autolabel Issues and PRs (run before commit changes in case commit fails) ----------------------------------------
197+
- name: Autolabel Issues and PRs
198+
if: inputs.labels == 'true' && (github.event.action == 'opened' || github.event.action == 'created')
199+
env:
200+
GITHUB_TOKEN: ${{ inputs.token }}
201+
FIRST_ISSUE_RESPONSE: ${{ inputs.first_issue_response }}
202+
FIRST_PR_RESPONSE: ${{ inputs.first_pr_response }}
203+
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
204+
OPENAI_MODEL: ${{ inputs.openai_model }}
205+
run: |
206+
ultralytics-actions-first-interaction
207+
shell: bash
208+
continue-on-error: true
209+
210+
# Commit Changes ---------------------------------------------------------------------------------------------------
211+
- name: Commit and Push Changes
212+
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.action != 'closed'
213+
run: |
214+
git config --global user.name "${{ inputs.github_username }}"
215+
git config --global user.email "${{ inputs.github_email }}"
216+
git pull origin ${{ github.head_ref || github.ref }}
217+
git add .
218+
git reset HEAD -- .github/workflows/ # workflow changes are not permitted with default token
219+
if ! git diff --staged --quiet; then
220+
git commit -m "Auto-format by https://ultralytics.com/actions"
221+
git push
222+
else
223+
echo "No changes to commit"
224+
fi
225+
shell: bash
226+
continue-on-error: false
227+
228+
# Broken links -----------------------------------------------------------------------------------------------------
229+
- name: Broken Link Checker
230+
if: inputs.links == 'true' && github.event.action != 'closed'
231+
uses: lycheeverse/[email protected]
232+
with:
233+
# Check all markdown and html files in repo. Ignores the following status codes to reduce false positives:
234+
# - 403(OpenVINO, "forbidden")
235+
# - 429(Instagram, "too many requests")
236+
# - 500(Zenodo, "cached")
237+
# - 502(Zenodo, "bad gateway")
238+
# - 999(LinkedIn, "unknown status code")
239+
args: |
240+
--scheme https
241+
--timeout 60
242+
--insecure
243+
--accept 403,429,500,502,999
244+
--exclude-all-private
245+
--exclude "https?://(www\.)?(github\.com|linkedin\.com|twitter\.com|instagram\.com|kaggle\.com|fonts\.gstatic\.com|url\.com)"
246+
"./**/*.md"
247+
"./**/*.html"
248+
token: ${{ inputs.token }}
249+
output: ../lychee/results.md
250+
fail: true
251+
continue-on-error: false

0 commit comments

Comments
 (0)