File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,13 +21,35 @@ jobs:
2121 - name : Get PR diff
2222 id : diff
2323 run : |
24- git diff origin/${{ github.base_ref }}...HEAD > pr.diff
24+ # Get diff without binary files
25+ git diff --origin/${{ github.base_ref }}...HEAD -- . ':(exclude)*.png' ':(exclude)*.jpg' ':(exclude)*.jpeg' ':(exclude)*.gif' ':(exclude)*.ico' ':(exclude)*.pdf' ':(exclude)*.zip' > pr.diff
26+
2527 MAX_SIZE=50000
26- if [ $(wc -c < pr.diff) -gt $MAX_SIZE ]; then
27- head -c $MAX_SIZE pr.diff > pr_truncated.diff
28- mv pr_truncated.diff pr.diff
29- echo "warning=Diff truncated to ${MAX_SIZE} bytes" >> $GITHUB_OUTPUT
28+ FILE_SIZE=$(wc -c < pr.diff)
29+
30+ if [ $FILE_SIZE -gt $MAX_SIZE ]; then
31+ # Truncate at UTF-8 character boundary using Perl
32+ perl -CS -e "
33+ local $/;
34+ my \$content = <>;
35+ my \$max = $MAX_SIZE;
36+ if (length(\$content) > \$max) {
37+ \$content = substr(\$content, 0, \$max);
38+ # Remove any partial UTF-8 character at the end
39+ \$content =~ s/[\x80-\xBF]+$//;
40+ print \$content;
41+ exit 1; # Indicate truncation occurred
42+ } else {
43+ print \$content;
44+ }
45+ " pr.diff > pr_truncated.diff
46+
47+ if [ $? -eq 1 ]; then
48+ mv pr_truncated.diff pr.diff
49+ echo "warning=Diff truncated to ${MAX_SIZE} bytes at UTF-8 boundary" >> $GITHUB_OUTPUT
50+ fi
3051 fi
52+
3153 FILES_CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | wc -l)
3254 echo "files_changed=$FILES_CHANGED" >> $GITHUB_OUTPUT
3355
You can’t perform that action at this time.
0 commit comments