-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
440 lines (375 loc) 路 21.8 KB
/
Copy pathaction.yml
File metadata and controls
440 lines (375 loc) 路 21.8 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
name: Python Linting
description: Run linting using pylint, black, and mypy.
author: Jason Miller
branding:
icon: check-square
color: green
inputs:
python-version:
description: Python version to use for linting. If not specified, uses the default Python available on the runner.
required: false
default: '3.x'
requirements-file:
description: Path to a requirements file to install before linting.
default: 'requirements.txt'
pylint-options:
description: The pylint options to pass to pylint.
required: false
black-options:
description: The black options to pass to black.
required: false
mypy-options:
description: The mypy options to pass to mypy.
required: false
commit-badges:
description: Whether to commit the generated SVG badges back to the repository. Set to 'true' to enable.
required: false
default: 'true'
badge-directory:
description: Directory to save the generated SVG badges. Defaults to .github/badges.
required: false
default: '.github/badges'
runs:
using: composite
steps:
- name: Setup Python
id: setup-python
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python-version }}
- name: Install Linting Tools
id: install-linting-tools
if: steps.setup-python.outcome == 'success'
run: |
echo "::notice file=action.yml,line=51::Installing pylint, black, and mypy."
pip3 install pylint black mypy && echo "::notice file=action.yml,line=52::Linting tools installation completed." || { echo "::error file=action.yml,line=53::Linting tools installation failed."; exit 1; }
if [ $? -eq 0 ]; then
echo "::notice file=action.yml,line=54::Successfully installed pylint, black, and mypy."
else
echo "::error file=action.yml,line=55::Failed to install pylint, black, and mypy."
exit 1
fi
shell: bash
continue-on-error: false
- name: Install Additional Requirements
id: install-requirements
if: inputs.requirements-file != '' && steps.setup-python.outcome == 'success'
run: |
echo "::notice file=action.yml,line=60::Installing additional requirements from ${{ inputs.requirements-file }}"
if [ test -r "${{ inputs.requirements-file }}" ]; then
pip3 install -r "${{ inputs.requirements-file }}" 2>&1 | tee requirements_output.txt && echo "::notice file=action.yml,line=61::Additional requirements installation completed." || { echo "::error file=action.yml,line=62::Additional requirements installation failed."; exit 1; }
else
echo "::warning file=action.yml,line=63::Requirements file not found: ${{ inputs.requirements-file }}"
echo "::notice file=action.yml,line=64::Skipping additional requirements installation."
fi
shell: bash
continue-on-error: true
- name: Generate Requirements Failure Summary
if: steps.setup-python.outcome == 'success' && steps.install-requirements.outcome == 'failure'
run: |
echo "::notice file=action.yml,line=73::Creating Requirements Installation Failure Summary in GitHub Step Summary."
echo "## Requirements Installation (Failure) :warning:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*Failed to install additional requirements from ${{ inputs.requirements-file }}.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat requirements_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=91::Removing temporary requirements output file."
rm -f requirements_output.txt && echo "::notice file=action.yml,line=93::Temporary requirements output file removed." || { echo "::warning file=action.yml,line=94::Failed to remove temporary requirements output file."; }
shell: bash
continue-on-error: true
- name: Failure On Requirements Installation Issues
if: steps.install-requirements.outcome == 'failure'
run: |
echo "::error file=action.yml,line=97::Failed to install additional requirements. Failing the action."
exit 1
shell: bash
continue-on-error: false
- name: Generate Requirements Success Summary
if: steps.install-requirements.outcome == 'success'
run: |
echo "::notice file=action.yml,line=81::Creating Requirements Installation Success Summary in GitHub Step Summary."
echo "## Requirements Installation (Success) :white_check_mark:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*Successfully installed additional requirements from ${{ inputs.requirements-file }}.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat requirements_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=99::Removing temporary requirements output file."
rm -f requirements_output.txt && echo "::notice file=action.yml,line=101::Temporary requirements output file removed." || { echo "::warning file=action.yml,line=102::Failed to remove temporary requirements output file."; }
shell: bash
continue-on-error: true
- name: Run Pylint
id: run-pylint
if: steps.install-linting-tools.outcome == 'success' && always()
run: |
if [[ -z "${{ inputs.pylint-options }}" ]]; then
echo "::notice file=action.yml,line=66::No Pylint options provided, using default."
pylint --reports=y --jobs=0 . 2>&1 | tee pylint_output.txt && echo "::notice file=action.yml,line=68::Pylint run completed." || { echo "::error file=action.yml,line=69::Pylint run failed."; exit 1; }
else
echo "::notice file=action.yml,line=68::Using Pylint options: ${{ inputs.pylint-options }}"
pylint ${{ inputs.pylint-options }} --reports=y --jobs=0 . 2>&1 | tee pylint_output.txt && echo "::notice file=action.yml,line=70::Pylint run completed." || { echo "::error file=action.yml,line=71::Pylint run failed."; exit 1; }
fi
shell: bash
continue-on-error: true
- name: Generate Pylint Failure Summary
if: steps.run-pylint.outcome == 'failure'
run: |
echo "::notice file=action.yml,line=112::Creating Pylint Failure Summary in GitHub Step Summary."
echo "## Pylint (Failure) :warning:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*Issues found by pylint.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat pylint_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=85::Removing temporary pylint output file."
rm -f pylint_output.txt && echo "::notice file=action.yml,line=87::Temporary pylint output file removed." || { echo "::warning file=action.yml,line=88::Failed to remove temporary pylint output file."; }
shell: bash
continue-on-error: true
- name: Failure On Pylint Issues
if: steps.run-pylint.outcome == 'failure'
run: |
echo "::error file=action.yml,line=121::Pylint found issues. Failing the action."
exit 1
shell: bash
continue-on-error: false
- name: Generate Pylint Success Summary
if: steps.run-pylint.outcome == 'success'
run: |
echo "::notice file=action.yml,line=119::Creating Pylint Success Summary in GitHub Step Summary."
echo "## Pylint (Success) :white_check_mark:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*No issues found by pylint.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat pylint_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=101::Removing temporary pylint output file."
rm -f pylint_output.txt && echo "::notice file=action.yml,line=103::Temporary pylint output file removed." || { echo "::warning file=action.yml,line=104::Failed to remove temporary pylint output file."; }
shell: bash
continue-on-error: true
- name: Run Black
id: run-black
if: steps.install-linting-tools.outcome == 'success' && always()
run: |
if [[ -z "${{ inputs.black-options }}" ]]; then
echo "::notice file=action.yml,line=88::No Black options provided, using default."
black --check . 2>&1 | tee black_output.txt && echo "::notice file=action.yml,line=90::Black run completed." || { echo "::error file=action.yml,line=91::Black run failed."; exit 1; }
else
echo "::notice file=action.yml,line=88::Running Black with options: ${{ inputs.black-options }}"
black --check ${{ inputs.black-options }} . 2>&1 | tee black_output.txt && echo "::notice file=action.yml,line=90::Black run completed." || { echo "::error file=action.yml,line=91::Black run failed."; exit 1; }
fi
shell: bash
continue-on-error: true
- name: Generate Black Failure Summary
if: steps.run-black.outcome == 'failure'
run: |
echo "::notice file=action.yml,line=140::Creating Black Failure Summary in GitHub Step Summary."
echo "## Black (Failure) :warning:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*Issues found by black.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat black_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=132::Removing temporary black output file."
rm -f black_output.txt && echo "::notice file=action.yml,line=134::Temporary black output file removed." || { echo "::warning file=action.yml,line=135::Failed to remove temporary black output file."; }
shell: bash
continue-on-error: true
- name: Failure On Black Issues
if: steps.run-black.outcome == 'failure'
run: |
echo "::error file=action.yml,line=149::Black found issues. Failing the action."
exit 1
shell: bash
continue-on-error: false
- name: Generate Black Success Summary
if: steps.run-black.outcome == 'success'
run: |
echo "::notice file=action.yml,line=147::Creating Black Success Summary in GitHub Step Summary."
echo "## Black (Success) :white_check_mark:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*No issues found by black.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat black_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=139::Removing temporary black output file."
rm -f black_output.txt && echo "::notice file=action.yml,line=141::Temporary black output file removed." || { echo "::warning file=action.yml,line=142::Failed to remove temporary black output file."; }
shell: bash
continue-on-error: true
- name: Run MyPy
id: run-mypy
if: steps.install-linting-tools.outcome == 'success' && always()
run: |
if [[ -z "${{ inputs.mypy-options }}" ]]; then
echo "::notice file=action.yml,line=105::No MyPy options provided, using default."
mypy . 2>&1 | tee mypy_output.txt
else
echo "::notice file=action.yml,line=108::Using MyPy options: ${{ inputs.mypy-options }}"
mypy ${{ inputs.mypy-options }} . 2>&1 | tee mypy_output.txt && echo "::notice file=action.yml,line=110::MyPy run completed." || { echo "::error file=action.yml,line=111::MyPy run failed."; exit 1; }
fi
shell: bash
continue-on-error: true
- name: Generate MyPy Failure Summary
if: steps.run-mypy.outcome == 'failure'
run: |
echo "::notice file=action.yml,line=172::Creating MyPy Failure Summary in GitHub Step Summary."
echo "## MyPy (Failure) :warning:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*Issues found by mypy.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat mypy_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=164::Removing temporary mypy output file."
rm -f mypy_output.txt && echo "::notice file=action.yml,line=166::Temporary mypy output file removed." || { echo "::warning file=action.yml,line=167::Failed to remove temporary mypy output file."; }
shell: bash
continue-on-error: true
- name: Failure On MyPy Issues
if: steps.run-mypy.outcome == 'failure'
run: |
echo "::error file=action.yml,line=181::MyPy found issues. Failing the action."
exit 1
shell: bash
continue-on-error: false
- name: Generate MyPy Success Summary
if: steps.run-mypy.outcome == 'success'
run: |
echo "::notice file=action.yml,line=179::Creating MyPy Success Summary in GitHub Step Summary."
echo "## MyPy (Success) :white_check_mark:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*No issues found by mypy.*" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat mypy_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::notice file=action.yml,line=154::Removing temporary mypy output file."
rm -f mypy_output.txt && echo "::notice file=action.yml,line=156::Temporary mypy output file removed." || { echo "::warning file=action.yml,line=157::Failed to remove temporary mypy output file."; }
shell: bash
continue-on-error: true
- name: Generate SVG Badges
id: generate-badges
if: steps.install-linting-tools.outcome == 'success' && inputs.commit-badges == 'true'
run: |
if [ test -d "${{ inputs.badge-directory }}" ]; then
echo "::notice file=action.yml,line=170::Badge directory exists: ${{ inputs.badge-directory }}"
else
echo "::notice file=action.yml,line=172::Badge directory does not exist. Creating it now."
mkdir -p "${{ inputs.badge-directory }}" && echo "::notice file=action.yml,line=174::Badge directory created successfully." || { echo "::error file=action.yml,line=175::Failed to create badge directory."; exit 1; }
fi
echo "::notice file=action.yml, line=320::Defining function to create SVG badges."
# Function to create badge
create_badge() {
local name=$1
local status=$2
local color=$3
local file=$4
cat > "$file" << 'EOF'
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<clipPath id="a">
<rect width="120" height="20" rx="3" fill="#fff"/>
</clipPath>
<g clip-path="url(#a)">
<path fill="#555" d="M0 0h60v20H0z"/>
<path fill="COLOR" d="M60 0h60v20H60z"/>
<path fill="url(#b)" d="M0 0h120v20H0z"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="30" y="15" fill="#010101" fill-opacity=".3">NAME</text>
<text x="30" y="14">NAME</text>
<text x="90" y="15" fill="#010101" fill-opacity=".3">STATUS</text>
<text x="90" y="14">STATUS</text>
</g>
</svg>
EOF
sed -i "s/NAME/$name/g; s/STATUS/$status/g; s/COLOR/$color/g" "$file"
}
# Determine badge status based on exit codes
PYLINT_STATUS="${{ steps.run-pylint.outcome }}"
PYLINT_COLOR="#4c1"
[ "${PYLINT_STATUS}" != "success" ] && PYLINT_COLOR="#e05d44"
echo "::notice file=action.yml,line=186::Pylint status: $PYLINT_STATUS, color: $PYLINT_COLOR"
BLACK_STATUS="${{ steps.run-black.outcome }}"
BLACK_COLOR="#4c1"
[ "${BLACK_STATUS}" != "success" ] && BLACK_COLOR="#e05d44"
echo "::notice file=action.yml,line=192::Black status: $BLACK_STATUS, color: $BLACK_COLOR"
MYPY_STATUS="${{ steps.run-mypy.outcome }}"
MYPY_COLOR="#4c1"
[ "${MYPY_STATUS}" != "success" ] && MYPY_COLOR="#e05d44"
echo "::notice file=action.yml,line=198::MyPy status: $MYPY_STATUS, color: $MYPY_COLOR"
# Create badges for each tool with actual status
echo "::notice file=action.yml,line=203::Generating SVG badge pylint.svg"
create_badge "pylint" "$PYLINT_STATUS" "$PYLINT_COLOR" "${{ inputs.badge-directory }}/pylint.svg" && echo "::notice file=action.yml,line=204::Pylint badge created successfully." || { echo "::error file=action.yml,line=204::Failed to create pylint badge."; exit 1; }
echo "::notice file=action.yml,line=206::Generating SVG badge black.svg"
create_badge "black" "$BLACK_STATUS" "$BLACK_COLOR" "${{ inputs.badge-directory }}/black.svg" && echo "::notice file=action.yml,line=207::Black badge created successfully." || { echo "::error file=action.yml,line=207::Failed to create black badge."; exit 1; }
echo "::notice file=action.yml,line=209::Generating SVG badge mypy.svg"
create_badge "mypy" "$MYPY_STATUS" "$MYPY_COLOR" "${{ inputs.badge-directory }}/mypy.svg" && echo "::notice file=action.yml,line=210::MyPy badge created successfully." || { echo "::error file=action.yml,line=210::Failed to create mypy badge."; exit 1; }
echo "::notice file=action.yml,line=212::SVG badge generation completed."
shell: bash
continue-on-error: true
- name: Commit Badges To Repository
id: commit-badges
if: steps.generate-badges.outcome == 'success' && inputs.commit-badges == 'true'
run: |
# Configure git
git config --local user.email "github-actions[bot]@users.noreply.github.com" && echo "::notice file=action.yml,line=253::Git user email set successfully." || { echo "::warning file=action.yml,line=254::Failed to set git user email."; exit 134; }
git config --local user.name "github-actions[bot]" && echo "::notice file=action.yml,line=257::Git user name set successfully." || { echo "::warning file=action.yml,line=258::Failed to set git user name."; exit 134; }
# Rebase to latest
git pull --rebase origin ${{ github.ref }} && echo "::notice file=action.yml,line=266::Rebased to latest changes from remote." || { echo "::warning file=action.yml,line=267::Failed to rebase from remote."; exit 1; }
# Check if badge directory exists
test -d "${{ inputs.badge-directory }}" && echo "::notice file=action.yml,line=263::Badge directory ${{ inputs.badge-directory }} exists." || { echo "::warning file=action.yml,line=264::Badge directory ${{ inputs.badge-directory }} does not exist. Skipping badge commit."; exit 0; }
# Add and commit badges
git add "${{ inputs.badge-directory }}/pylint.svg" && echo "::notice file=action.yml,line=267::Adding pylint badge to commit." || { echo "::warning file=action.yml,line=268::Failed to add pylint badge."; }
git add "${{ inputs.badge-directory }}/black.svg" && echo "::notice file=action.yml,line=270::Adding black badge to commit." || { echo "::warning file=action.yml,line=271::Failed to add black badge."; }
git add "${{ inputs.badge-directory }}/mypy.svg" && echo "::notice file=action.yml,line=273::Adding mypy badge to commit." || { echo "::warning file=action.yml,line=274::Failed to add mypy badge."; }
git commit -m "Update linting badges [skip ci]" && echo "::notice file=action.yml,line=302::Committing changes to repository." || { echo "::warning file=action.yml,line=303::No changes to commit."; exit 0; }
# Push changes to repository
git push origin ${{ github.ref }} && echo "::notice file=action.yml,line=306::Pushing changes to repository." || { echo "::warning file=action.yml,line=307::Failed to push changes to repository."; exit 1; }
shell: bash
continue-on-error: true
- name: Badge Generation Failure
if: steps.generate-badges.outcome == 'failure'
run: |
echo "::error file=action.yml,line=313::Failed to generate SVG badges."
exit 1
shell: bash
continue-on-error: false
- name: Badge Commit Failure
if: steps.commit-badges.outcome == 'failure'
run: |
echo "::error file=action.yml,line=314::Failed to commit or push badges to the repository."
exit 1
shell: bash
continue-on-error: false