-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathaction.yaml
More file actions
178 lines (159 loc) · 7.37 KB
/
action.yaml
File metadata and controls
178 lines (159 loc) · 7.37 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
name: Run Pylint
description: Lint Python files using pylint
inputs:
path:
description: Path to Python files or folder
required: true
output-file:
description: Path to store the pylint output
required: true
name:
description: Name of the artifact
required: true
enable-reviewdog:
description: Enable ReviewDog PR comments
required: false
default: "false"
github_token:
description: GitHub token for ReviewDog
required: false
fail-on-findings:
description: "Whether to fail the action if errors are found"
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Install Pylint
run: |
python -m pip install --upgrade pip
pip install pylint
shell: bash
- name: Run pylint
id: run-pylint
env:
path: ${{ inputs.path }}
output_file: ${{ inputs.output-file }}
run: |
# Run pylint on all Python files at once for a single comprehensive score
echo "🔍 Searching for Python files in: ${path}"
python_files=$(find "${path}" -name "*.py" -not -path "*/venv/*" 2>/dev/null || true)
if [ -n "${python_files}" ]; then
echo "📝 Found Python files, running pylint..."
# Save full output to temporary file first
temp_output="${output_file}.full"
find "${path}" -name "*.py" -not -path "*/venv/*" -print0 | xargs -0 pylint --rcfile="${path}/pylintrc" 2>&1 | tee "${temp_output}" || true
# Filter only errors (E) and fatal (F) issues to the main output file
if [ -f "${temp_output}" ]; then
# Extract errors and fatal issues
grep -E "^[^:]+:[0-9]+:[0-9]+: [EF][0-9]+:" "${temp_output}" > "${output_file}" 2>/dev/null || touch "${output_file}"
# Also preserve the score line if it exists
score_line=$(grep "Your code has been rated at" "${temp_output}" 2>/dev/null || echo "")
if [ -n "$score_line" ]; then
echo "" >> "${output_file}"
echo "$score_line" >> "${output_file}"
fi
else
touch "${output_file}"
fi
else
echo "⚠️ No Python files found in ${path}" | tee "${output_file}"
fi
if [ ! -f "${output_file}" ]; then
echo "No Python files found or pylint produced no output" > "${output_file}"
fi
shell: bash
- name: Analyze Pylint results
id: analyze-results
if: always()
env:
path: ${{ inputs.path }}
name: ${{ inputs.name }}
run: |
# Analyze from the full temporary file for complete statistics
temp_output="${{ inputs.output-file }}.full"
output_file="${{ inputs.output-file }}"
if [ -f "${temp_output}" ]; then
# Count issues by severity from full output
convention_count=$(grep -E "^[^:]+:[0-9]+:[0-9]+: C[0-9]+:" "${temp_output}" 2>/dev/null | wc -l | tr -d '[:space:]' || echo "0")
refactor_count=$(grep -E "^[^:]+:[0-9]+:[0-9]+: R[0-9]+:" "${temp_output}" 2>/dev/null | wc -l | tr -d '[:space:]' || echo "0")
warning_count=$(grep -E "^[^:]+:[0-9]+:[0-9]+: W[0-9]+:" "${temp_output}" 2>/dev/null | wc -l | tr -d '[:space:]' || echo "0")
error_count=$(grep -E "^[^:]+:[0-9]+:[0-9]+: E[0-9]+:" "${temp_output}" 2>/dev/null | wc -l | tr -d '[:space:]' || echo "0")
fatal_count=$(grep -E "^[^:]+:[0-9]+:[0-9]+: F[0-9]+:" "${temp_output}" 2>/dev/null | wc -l | tr -d '[:space:]' || echo "0")
total=$((convention_count + refactor_count + warning_count + error_count + fatal_count)) || total=0
critical_issues=$((error_count + fatal_count)) || critical_issues=0
# Try to extract the score
score=$(grep "Your code has been rated at" "${temp_output}" 2>/dev/null | tail -1 | grep -oE "[0-9]+\.[0-9]+/10" 2>/dev/null || echo "")
echo "### Pylint Results for ${name}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Total Issues**: $total" >> $GITHUB_STEP_SUMMARY
echo "- **Critical Issues (Errors + Fatal)**: $critical_issues" >> $GITHUB_STEP_SUMMARY
# Export error_count for use in the final step
echo "error_count=$critical_issues" >> $GITHUB_OUTPUT
echo "total_count=$total" >> $GITHUB_OUTPUT
if [ "$fatal_count" -gt 0 ]; then
echo "- 🔴 **Fatal**: $fatal_count" >> $GITHUB_STEP_SUMMARY
fi
if [ "$error_count" -gt 0 ]; then
echo "- ❌ **Errors**: $error_count" >> $GITHUB_STEP_SUMMARY
fi
if [ "$warning_count" -gt 0 ]; then
echo "- ⚠️ **Warnings**: $warning_count" >> $GITHUB_STEP_SUMMARY
fi
if [ "$refactor_count" -gt 0 ]; then
echo "- 🔧 **Refactor**: $refactor_count" >> $GITHUB_STEP_SUMMARY
fi
if [ "$convention_count" -gt 0 ]; then
echo "- 📋 **Convention**: $convention_count" >> $GITHUB_STEP_SUMMARY
fi
if [ -n "$score" ]; then
echo "- 📊 **Score**: $score" >> $GITHUB_STEP_SUMMARY
fi
if [ "$critical_issues" -gt 0 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔴 **Critical issues found! Please fix errors and fatal issues.**" >> $GITHUB_STEP_SUMMARY
echo "📄 **Artifact contains only critical issues for easier review.**" >> $GITHUB_STEP_SUMMARY
elif [ "$total" -gt 0 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **Non-critical issues found. Consider fixing warnings and other issues.**" >> $GITHUB_STEP_SUMMARY
echo "📄 **Artifact is empty as no critical issues were found.**" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ **No issues found!**" >> $GITHUB_STEP_SUMMARY
echo "error_count=0" >> $GITHUB_OUTPUT
echo "total_count=0" >> $GITHUB_OUTPUT
fi
rm -f "${temp_output}" 2>/dev/null || true
fi
shell: bash
- name: Upload Pylint report (Critical Issues Only)
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: pylint-report-${{ inputs.name }}
path: ${{ inputs.output-file }}
- name: Run ReviewDog (Pylint) - Errors Only
if: ${{ inputs.enable-reviewdog == 'true' && steps.analyze-results.outputs.error_count > 0 }}
uses: dciborow/action-pylint@cf6c9bcd79e4aa70e2fbeaf6332d741eb1e0bff8 #0.1.1
with:
github_token: ${{ inputs.github_token }}
reporter: github-pr-review
level: error
workdir: ${{ inputs.path }}
- name: Fail if Pylint found critical issues
if: inputs.fail-on-findings == 'true'
shell: bash
env:
output_file: ${{ inputs.output-file }}
run: |
error_count="${{ steps.analyze-results.outputs.error_count }}"
total_count="${{ steps.analyze-results.outputs.total_count }}"
if [ "$error_count" -gt 0 ]; then
echo "❌ Pylint found $error_count error(s). Failing the job."
exit 1
elif [ "$total_count" -gt 0 ]; then
echo "✅ Pylint found $total_count issue(s) but no errors. Job will continue."
echo "📋 Issues found: warnings, info, or notes that should be reviewed."
else
echo "✅ No Pylint issues found."
fi