-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (199 loc) · 7.04 KB
/
formatting.yml
File metadata and controls
231 lines (199 loc) · 7.04 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
name: Code Formatting and Linting
on:
push:
branches:
- main
- master
- develop
paths:
- '**.py'
- '**.sh'
- '**.c'
- '**.h'
- '**.ts'
- '**.tsx'
- '**.js'
- '**.jsx'
- '**.md'
- '**.vim'
pull_request:
branches:
- main
- master
- develop
paths:
- '**.py'
- '**.sh'
- '**.c'
- '**.h'
- '**.ts'
- '**.tsx'
- '**.js'
- '**.jsx'
- '**.md'
- '**.vim'
jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install shellcheck
run: |
sudo apt-get update
sudo apt-get install -y shellcheck
- name: Install shfmt
run: |
curl -sS https://webi.sh/shfmt | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Find shell scripts
id: find_shell
run: |
# Find all .sh files and files with shell shebangs
SHELL_FILES=$(find . -type f \( -name "*.sh" -o -exec sh -c 'head -n1 "$1" | grep -q "^#!.*sh"' _ {} \; \) -print | grep -v ".git" || true)
if [ -n "$SHELL_FILES" ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "$SHELL_FILES" > /tmp/shell_files.txt
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Run shellcheck (BLOCKING)
if: steps.find_shell.outputs.found == 'true'
run: |
echo "Running shellcheck on all shell scripts..."
cat /tmp/shell_files.txt | xargs shellcheck
- name: Run shfmt
if: steps.find_shell.outputs.found == 'true'
run: |
echo "Formatting shell scripts with shfmt..."
cat /tmp/shell_files.txt | xargs shfmt -w -i 2 -ci -bn
- name: Install C tools
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy clang-format
- name: Find C files
id: find_c
run: |
C_FILES=$(find . -type f \( -name "*.c" -o -name "*.h" \) -not -path "./.git/*" || true)
if [ -n "$C_FILES" ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "$C_FILES" > /tmp/c_files.txt
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Run clang-tidy (BLOCKING)
if: steps.find_c.outputs.found == 'true'
run: |
echo "Running clang-tidy on all C files..."
cat /tmp/c_files.txt | xargs clang-tidy --warnings-as-errors='*'
- name: Run clang-format
if: steps.find_c.outputs.found == 'true'
run: |
echo "Formatting C code with clang-format..."
cat /tmp/c_files.txt | xargs clang-format -i --style=LLVM
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install TypeScript and Markdown tools
run: |
npm install -g eslint prettier @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-markdown markdownlint-cli
- name: Find TypeScript files
id: find_ts
run: |
TS_FILES=$(find . -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) -not -path "./node_modules/*" -not -path "./.git/*" || true)
if [ -n "$TS_FILES" ]; then
echo "found=true" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Find Markdown files
id: find_md
run: |
MD_FILES=$(find . -type f -name "*.md" -not -path "./node_modules/*" -not -path "./.git/*" || true)
if [ -n "$MD_FILES" ]; then
echo "found=true" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Run ESLint (BLOCKING)
if: steps.find_ts.outputs.found == 'true'
run: |
echo "Running ESLint on TypeScript/JavaScript files..."
npx eslint . --ext .ts,.tsx,.js,.jsx || echo "No ESLint config found, skipping..."
continue-on-error: true
- name: Run markdownlint (BLOCKING)
if: steps.find_md.outputs.found == 'true'
run: |
echo "Running markdownlint on Markdown files..."
npx markdownlint '**/*.md' --ignore node_modules --ignore .git || echo "No markdownlint config found, using defaults..."
continue-on-error: true
- name: Run Prettier on TypeScript/JavaScript
if: steps.find_ts.outputs.found == 'true'
run: |
echo "Formatting TypeScript/JavaScript with Prettier..."
npx prettier --write "**/*.{ts,tsx,js,jsx,json}"
- name: Run Prettier on Markdown
if: steps.find_md.outputs.found == 'true'
run: |
echo "Formatting Markdown with Prettier..."
npx prettier --write "**/*.md"
- name: Install Vimscript tools
run: |
pip install vim-vint --break-system-packages
- name: Find Vimscript files
id: find_vim
run: |
VIM_FILES=$(find . -type f \( -name "*.vim" -o -name ".vimrc" -o -name "vimrc" \) -not -path "./.git/*" || true)
if [ -n "$VIM_FILES" ]; then
echo "found=true" >> $GITHUB_OUTPUT
echo "$VIM_FILES" > /tmp/vim_files.txt
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Run vint (BLOCKING)
if: steps.find_vim.outputs.found == 'true'
run: |
echo "Running vint on Vimscript files..."
cat /tmp/vim_files.txt | xargs vint
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python formatting tools
run: |
python -m pip install --upgrade pip
pip install black isort ssort ruff
- name: Run ruff check (BLOCKING)
run: |
echo "Running ruff linter on all Python files..."
ruff check .
- name: Run ssort
run: |
ssort **/*.py || true
continue-on-error: false
- name: Run isort
run: |
isort .
continue-on-error: false
- name: Run black
run: |
black .
continue-on-error: false
- name: Check for changes
id: verify_diff
run: |
git diff --quiet . || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit and push changes
if: steps.verify_diff.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "style: auto-format code with shfmt, clang-format, eslint, prettier, markdownlint, vint, black, isort, and ssort"
git push