import os
import sys
def get_file_action(path):
"""
Determine CI action based on file path.
Returns:
"SKIP" - Skip all (no compile and test, no package)
"PKG" - Trigger package build
"COMPILE" - Normal compile
"""
skip_keywords = ['.md', 'OWNERS', 'LICENSE', 'classify_rule.yaml', 'docs']
pkg_keywords = ['examples']
for kw in skip_keywords:
if kw in path:
return "SKIP"
for kw in pkg_keywords:
if kw in path:
return "PKG"
return "COMPILE"
def main():
"""
Get change info from ci, CI_MODE=True, ci will write 'get diff >/change_file.txt'
Returns:
"SKIP" - Skip all (docs, OWNERS, .md only)
"PKG" - Trigger package build (examples only)
"COMPILE" - Normal compile (source code changes)
"""
if len(sys.argv) < 2:
return "COMPILE"
changed_files_arg = sys.argv[1]
try:
if os.path.isfile(changed_files_arg) and changed_files_arg.endswith('.txt'):
with open(changed_files_arg, 'r') as f:
changed_files = [line.strip() for line in f.readlines() if line.strip()]
elif ',' in changed_files_arg:
changed_files = [f.strip() for f in changed_files_arg.split(',') if f.strip()]
else:
changed_files = [changed_files_arg.strip()]
except BaseException as err:
return "COMPILE"
if not changed_files:
return "COMPILE"
actions = [get_file_action(f) for f in changed_files]
if all(a == "SKIP" for a in actions):
return "SKIP"
if any(a == "PKG" for a in actions):
if not any(a == "COMPILE" for a in actions):
return "PKG"
else:
return "COMPILE"
return "COMPILE"
if __name__ == '__main__':
sys.stdout.write(main())