File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Check if all required arguments are provided
4+ if [ " $# " -ne 3 ]; then
5+ echo " Usage: $0 <folder_path> <max_line_length> <file_globs>"
6+ exit 1
7+ fi
8+
9+ folder_path=" $1 "
10+ max_length=" $2 "
11+ file_globs=" $3 "
12+
13+ # Function to get relative path
14+ get_relative_path () {
15+ local path=" $1 "
16+ local base=" $( pwd) "
17+ echo " ${path# $base / } "
18+ }
19+
20+ # Initialize a flag to check if any lines exceed the max length
21+ found_lines=0
22+
23+ # Convert comma-separated globs to an array
24+ IFS=' ,' read -ra glob_array <<< " $file_globs"
25+
26+ # Use find to get all files matching the glob patterns
27+ for glob in " ${glob_array[@]} " ; do
28+ while IFS= read -r -d ' ' file; do
29+ # Get the relative path
30+ relative_path=$( get_relative_path " $file " )
31+
32+ # Use awk to process each file
33+ awk -v max=" $max_length " -v file=" $relative_path " '
34+ length($0) > max {
35+ print file ":" NR
36+ found = 1
37+ exit 1
38+ }
39+ END {
40+ exit found
41+ }' " $file "
42+
43+ # Check awk's exit status
44+ if [ $? -eq 1 ]; then
45+ found_lines=1
46+ fi
47+ done < <( find " $folder_path " -type f -name " $glob " -print0)
48+ done
49+
50+ # Exit with appropriate code
51+ if [ $found_lines -eq 0 ]; then
52+ echo " All lines are within the $max_length character limit."
53+ exit 0
54+ else
55+ echo " Some lines exceedded the $max_length character limit."
56+ exit 1
57+ fi
Original file line number Diff line number Diff line change @@ -101,3 +101,16 @@ jobs:
101101
102102 - name : Lint
103103 run : composer lint
104+
105+ max-lines :
106+ runs-on : ubuntu-latest
107+
108+ steps :
109+ - name : Checkout code
110+ uses : actions/checkout@v4
111+
112+ - name : Make script executable
113+ run : chmod +x ./.github/scripts/max-lines.sh
114+
115+ - name : Check max lines
116+ run : ./.github/scripts/max-lines.sh . 1200 "*.twig"
You can’t perform that action at this time.
0 commit comments