Skip to content

Commit 7b463cd

Browse files
committed
chore: update
1 parent 6587071 commit 7b463cd

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

.github/workflows/antlr-lint.yml

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -148,60 +148,57 @@ jobs:
148148
149149
# Run linter and capture output
150150
output_file=$(mktemp)
151-
if antlr-lint lint $verbose_opt $config_opt "$file" 2>&1 | tee "$output_file"; then
152-
echo "✅ PASSED: No issues found"
153-
passed_files=$((passed_files + 1))
154-
else
151+
antlr-lint lint $verbose_opt $config_opt "$file" 2>&1 | tee "$output_file"
152+
153+
# Check if there are any errors or warnings in the output
154+
if grep -E "ERROR|WARNING" "$output_file" > /dev/null; then
155155
echo "❌ FAILED: Issues detected"
156156
failed_files=$((failed_files + 1))
157157
158158
# Parse the output for GitHub annotations
159-
# Extract file path, line numbers, and messages for GitHub annotations
159+
# Look for the table format with Location, Severity, Rule, and Message
160160
while IFS= read -r line; do
161-
# Look for patterns like "filename:line:column: severity: message"
162-
# or "filename:line: severity: message"
163-
if echo "$line" | grep -E "^.*\.g4:[0-9]+:" > /dev/null; then
164-
# Extract components
165-
file_path=$(echo "$line" | cut -d: -f1)
166-
line_num=$(echo "$line" | cut -d: -f2)
161+
# Look for lines with the format: │ 827:1 │ ERROR │ S001 │ Message...
162+
if echo "$line" | grep -E "^│ [0-9]+:[0-9]+" > /dev/null; then
163+
# Extract location (line:column)
164+
location=$(echo "$line" | sed -n 's/^│ *\([0-9]*:[0-9]*\).*/\1/p' | tr -d ' ')
165+
line_num=$(echo "$location" | cut -d: -f1)
166+
col_num=$(echo "$location" | cut -d: -f2)
167167
168-
# Check if there's a column number
169-
if echo "$line" | cut -d: -f3 | grep -E "^[0-9]+$" > /dev/null; then
170-
col_num=$(echo "$line" | cut -d: -f3)
171-
rest=$(echo "$line" | cut -d: -f4-)
172-
else
173-
col_num=""
174-
rest=$(echo "$line" | cut -d: -f3-)
175-
fi
176-
177-
# Determine severity and message
178-
if echo "$rest" | grep -i "error" > /dev/null; then
168+
# Extract severity
169+
if echo "$line" | grep -i "ERROR" > /dev/null; then
179170
severity="error"
180-
message=$(echo "$rest" | sed 's/^ *error: *//')
181-
elif echo "$rest" | grep -i "warning" > /dev/null; then
171+
elif echo "$line" | grep -i "WARNING" > /dev/null; then
182172
severity="warning"
183-
message=$(echo "$rest" | sed 's/^ *warning: *//')
184173
else
185174
severity="notice"
186-
message=$(echo "$rest" | sed 's/^ *//')
187175
fi
188176
177+
# Extract rule code
178+
rule=$(echo "$line" | sed -n 's/.*│ *\([A-Z][0-9]*\) *│.*/\1/p')
179+
180+
# Extract message - everything after the rule code
181+
message=$(echo "$line" | sed -n 's/.*│ [A-Z][0-9]* *│ *\(.*\) *│$/\1/p' | sed 's/ *$//')
182+
189183
# Output GitHub annotation
190-
if [ -n "$col_num" ]; then
191-
echo "::${severity} file=${file_path},line=${line_num},col=${col_num}::${message}"
184+
if [ -n "$col_num" ] && [ "$col_num" != "1" ]; then
185+
echo "::${severity} file=${file},line=${line_num},col=${col_num}::[$rule] ${message}"
192186
else
193-
echo "::${severity} file=${file_path},line=${line_num}::${message}"
187+
echo "::${severity} file=${file},line=${line_num}::[$rule] ${message}"
194188
fi
195189
196190
# Store for summary
197-
echo "${severity}: ${file_path}:${line_num} - ${message}" >> "$issues_file"
191+
echo "${severity}: ${file}:${line_num} - [$rule] ${message}" >> "$issues_file"
198192
fi
199193
done < "$output_file"
200194
201195
# If no specific line annotations were found, create a general file-level annotation
202196
if ! grep -q "::" "$output_file"; then
203197
echo "::error file=${file}::ANTLR grammar linting failed. Check the workflow logs for details."
204198
fi
199+
else
200+
echo "✅ PASSED: No issues found"
201+
passed_files=$((passed_files + 1))
205202
fi
206203
207204
rm -f "$output_file"
@@ -263,11 +260,12 @@ jobs:
263260
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
264261
265262
for file in $(find ${{ matrix.path }} -name "*.g4" -type f | sort); do
266-
# Check if this file had issues (simplified check)
267-
if antlr-lint lint "$file" > /dev/null 2>&1; then
268-
echo "| \`${file}\` | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
269-
else
263+
# Check if this file had issues
264+
output=$(antlr-lint lint "$file" 2>&1)
265+
if echo "$output" | grep -E "ERROR|WARNING" > /dev/null; then
270266
echo "| \`${file}\` | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
267+
else
268+
echo "| \`${file}\` | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
271269
fi
272270
done
273271

0 commit comments

Comments
 (0)