Skip to content

Commit 7b57d3c

Browse files
fabiobaltierinashif
authored andcommitted
scripts: compliance: check for binary files
Add a compliance check that fails if the diff is adding any binary file to prevent committing them by mistake. Only check for added files and explicitly allow image files in doc/ and boards/. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent c585df4 commit 7b57d3c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scripts/ci/check_compliance.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,29 @@ def run(self):
10581058
self.failure(failure)
10591059

10601060

1061+
class BinaryFiles(ComplianceTest):
1062+
"""
1063+
Check that the diff contains no binary files.
1064+
"""
1065+
name = "BinaryFiles"
1066+
doc = "No binary files allowed."
1067+
path_hint = "<git-top>"
1068+
1069+
def run(self):
1070+
BINARY_ALLOW_PATHS = ("doc/", "boards/", "samples/")
1071+
# svg files are always detected as binary, see .gitattributes
1072+
BINARY_ALLOW_EXT = (".jpg", ".jpeg", ".png", ".svg")
1073+
1074+
for stat in git("diff", "--numstat", "--diff-filter=A",
1075+
COMMIT_RANGE).splitlines():
1076+
added, deleted, fname = stat.split("\t")
1077+
if added == "-" and deleted == "-":
1078+
if (fname.startswith(BINARY_ALLOW_PATHS) and
1079+
fname.endswith(BINARY_ALLOW_EXT)):
1080+
continue
1081+
self.failure(f"Binary file not allowed: {fname}")
1082+
1083+
10611084
def init_logs(cli_arg):
10621085
# Initializes logging
10631086

0 commit comments

Comments
 (0)