Skip to content

Commit 6657288

Browse files
authored
Update block-mini.yml
print violating filenames and line numbers
1 parent a07c55d commit 6657288

File tree

1 file changed

+55
-46
lines changed

1 file changed

+55
-46
lines changed

.github/workflows/block-mini.yml

+55-46
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
11
name: Block Minified JavaScript/TypeScript
22

33
on:
4-
pull_request:
5-
branches: ["main", "develop", "*"] # Adjust as needed
6-
push:
7-
branches: ["main", "develop", "*"] # If you also want to scan direct pushes
4+
pull_request:
5+
branches: ["main", "develop", "*"]
6+
push:
7+
branches: ["main", "develop", "*"]
88

99
jobs:
10-
block-minified-code:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- name: Check out code
14-
uses: actions/checkout@v4
15-
16-
- name: Detect potential minified code
17-
shell: bash
18-
run: |
19-
echo "Scanning for potential minified JS/TS code..."
20-
# Find .ts, .tsx, .js, .jsx files; skip common directories like node_modules, dist, build, etc.
21-
FILES=$(find . \
22-
\( -name 'node_modules' -prune \) -o \
23-
\( -name 'dist' -prune \) -o \
24-
\( -name 'build' -prune \) -o \
25-
-type f \( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \) \
26-
-print)
27-
28-
if [ -z "$FILES" ]; then
29-
echo "No relevant JS/TS files found."
30-
exit 0
31-
fi
32-
33-
# Define a threshold for line length.
34-
# Lines exceeding this length are considered potentially minified.
35-
THRESHOLD=500
36-
VIOLATIONS=0
37-
38-
for file in $FILES; do
39-
# Check if any line in the file exceeds $THRESHOLD characters.
40-
if grep -qE ".{$THRESHOLD,}" "$file"; then
41-
echo "::error file=$file::Detected potential minified code (line length > $THRESHOLD)."
42-
VIOLATIONS=1
43-
fi
44-
done
45-
46-
if [ "$VIOLATIONS" -eq 1 ]; then
47-
echo "ERROR: Minified code detected. Please remove or exclude it."
48-
exit 1
49-
else
50-
echo "No minified code detected."
51-
fi
10+
block-minified-code:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v4
15+
16+
- name: Detect potential minified code
17+
shell: bash
18+
run: |
19+
echo "Scanning for potential minified JS/TS code..."
20+
21+
# We'll look in .ts, .tsx, .js, .jsx files, skipping common build dirs.
22+
FILES=$(find . \
23+
\( -name 'node_modules' -prune \) -o \
24+
\( -name 'dist' -prune \) -o \
25+
\( -name 'build' -prune \) -o \
26+
-type f \( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \) \
27+
-print)
28+
29+
if [ -z "$FILES" ]; then
30+
echo "No relevant JS/TS files found."
31+
exit 0
32+
fi
33+
34+
THRESHOLD=500
35+
VIOLATIONS=0
36+
37+
for file in $FILES; do
38+
# Use grep -En to capture line number and text
39+
# If any line is ≥ THRESHOLD chars, we store those lines in RESULTS
40+
RESULTS=$(grep -En ".{${THRESHOLD},}" "$file" || true)
41+
if [ -n "$RESULTS" ]; then
42+
# We have potential minified lines
43+
while IFS= read -r match; do
44+
# 'match' will be something like "1234:the entire matched line"
45+
LINENUM=$(echo "$match" | cut -d: -f1)
46+
# If you want the text, you can do:
47+
# MATCHED_LINE=$(echo "$match" | cut -d: -f2-)
48+
49+
echo "::error file=$file,line=$LINENUM::Detected potential minified code (≥ $THRESHOLD chars)."
50+
done <<< "$RESULTS"
51+
VIOLATIONS=1
52+
fi
53+
done
54+
55+
if [ "$VIOLATIONS" -eq 1 ]; then
56+
echo "ERROR: Minified code detected. Please remove or exclude it."
57+
exit 1
58+
else
59+
echo "No minified code detected."
60+
fi

0 commit comments

Comments
 (0)