generated from ultralytics/template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
210 lines (199 loc) · 8.6 KB
/
action.yml
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
# Ultralytics YOLO 🚀, 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
python:
description: "Run Python formatting"
required: false
default: "false"
markdown:
description: "Run Markdown formatting (deprecated in favor of prettier)"
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"
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"
openai_api_key:
description: "OpenAI API Key"
required: false
openai_azure_api_key:
description: "OpenAI Azure API Key"
required: false
openai_azure_endpoint:
description: "OpenAI Azure Endpoint"
required: false
openai_model:
description: "OpenAI Model"
required: false
default: "gpt-4o-2024-05-13"
runs:
using: "composite"
steps:
- name: Print Action Information
run: |
echo "github.event_name: ${{ github.event_name }}" # i.e. "pull_request"
echo "github.event.action: ${{ github.event.action }}" # i.e. "opened" or "closed"
echo "github.repository: ${{ github.repository }}"
echo "github.event.pull_request.number: ${{ github.event.pull_request.number }}"
echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}"
echo "github.actor: ${{ github.actor }}"
echo "github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}"
echo "github.ref: ${{ github.ref }}"
echo "github.head_ref: ${{ github.head_ref }}"
echo "github.base_ref: ${{ github.base_ref }}"
shell: bash
- name: Checkout Repository
if: github.event.action != 'closed'
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
token: ${{ inputs.token }}
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
- name: Install Dependencies
# Note tomli required for codespell with pyproject.toml
if: github.event.action != 'closed'
run: |
pip install -q \
ruff docformatter codespell tomli
# mdformat-gfm mdformat-frontmatter mdformat-mkdocs
shell: bash
# Python formatting ------------------------------------------------------------------------------------------------
# Note on sorting Python imports https://stackoverflow.com/questions/77876253/sort-imports-alphabetically-with-ruff
- name: Run Python
if: inputs.python == 'true' && github.event.action != 'closed'
run: |
ruff format \
--line-length 120 \
. || true
ruff check \
--fix \
--extend-select I \
. || true
docformatter \
--wrap-summaries 120 \
--wrap-descriptions 120 \
--in-place \
--pre-summary-newline \
--close-quotes-on-newline \
--recursive \
.
shell: bash
continue-on-error: true
# Markdown formatting ----------------------------------------------------------------------------------------------
- name: Run Mdformat
if: inputs.markdown == 'true' && github.event.action != 'closed'
run: |
curl -s "https://raw.githubusercontent.com/ultralytics/actions/main/utils/update_markdown_code_blocks.py" | python -
# mdformat . --number --wrap no
# find . -name "*.md" ! -path "./docs/*" -exec mdformat --number --wrap no {} +
shell: bash
continue-on-error: true
# Prettier (JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, YAML) -------------
- name: Run Prettier
if: (inputs.prettier == 'true' || inputs.markdown == 'true') && github.event.action != 'closed'
run: |
npm install --global prettier
# npx prettier --write "**/*.{js,jsx,ts,tsx,css,less,scss,json,md,mdx,yml,yaml,html,vue,svelte}"
npx prettier --write "**/*.{yml,yaml}"
find . -name "*.md" ! -path "*/docs/*" -exec npx prettier --write {} +
find ./docs -name "*.md" ! -path "*/reference/*" -exec npx prettier --tab-width 4 --write {} +
shell: bash
continue-on-error: true
- name: Update unordered Markdown list indents to 4 spaces for MkDocs compatibility
if: (inputs.prettier == 'true' || inputs.markdown == 'true') && github.event.action != 'closed'
run: |
from pathlib import Path
for file in Path("./docs").rglob('*.md'):
content = file.read_text()
updated_content = content.replace("| - ","| - ").replace('- ', '- ').replace("** ","** ").replace("* ","* ")
file.write_text(updated_content)
shell: python
continue-on-error: true
# Spelling ---------------------------------------------------------------------------------------------------------
- name: Run Codespell
if: inputs.spelling == 'true' && github.event.action != 'closed'
run: |
codespell \
--write-changes \
--ignore-words-list "crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall" \
--skip "*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,__pycache__*,*.ico,*.jpg,*.png,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml"
shell: bash
continue-on-error: true
# Commit Changes ---------------------------------------------------------------------------------------------------
- name: Commit and Push Changes
if: github.event.action != 'closed'
run: |
git add .
git reset HEAD -- .github/workflows/ # workflow changes are not permitted with default token
if ! git diff --staged --quiet; then
git config --global user.name "UltralyticsAssistant"
git config --global user.email "web@ultralytics.com"
git commit -m "Auto-format by https://ultralytics.com/actions"
git push
else
echo "No changes to commit"
fi
shell: bash
continue-on-error: false
# PR Summary -------------------------------------------------------------------------------------------------------
- name: PR Summary
if: inputs.summary == 'true' && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.action != 'synchronize'
env:
REPO_NAME: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ inputs.token }}
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
OPENAI_AZURE_API_KEY: ${{ inputs.openai_azure_api_key }}
OPENAI_AZURE_ENDPOINT: ${{ inputs.openai_azure_endpoint }}
OPENAI_MODEL: ${{ inputs.openai_model }}
# Note file must be run remotely using requests, not with "python utils/run_pr_summary.py"
run: |
pip install -q openai requests
curl -s "https://raw.githubusercontent.com/ultralytics/actions/main/utils/run_pr_summary.py" | python -
shell: bash
continue-on-error: true
# Broken links -----------------------------------------------------------------------------------------------------
- name: Broken Link Checker
if: inputs.links == 'true' && github.event.action != 'closed'
uses: lycheeverse/lychee-action@v1.10.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 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