@@ -17,6 +17,48 @@ def compile_(ctx):
1717 raise Exception ("Could not compile all files" )
1818
1919
20+ @task
21+ def license (ctx ):
22+ # Verifies repo contains LICENSE file with ASF 2.0 content
23+ print ("" )
24+ print ("==================== license-check ====================" )
25+ print ("" )
26+ apache_license_rgx = re .compile (r'.*Apache License.*' )
27+ license_version_rgx = re .compile (r'.*Version 2\.0.*' )
28+ apache_url_rgx = re .compile (r'.*www\.apache\.org/licenses/LICENSE-2\.0.*' )
29+ files = []
30+ top_level_git_dir = ctx .run ('git rev-parse --show-toplevel' ).stdout .splitlines ()[0 ]
31+ base_branch = os .environ .get ('BASE_BRANCH' , 'origin/master' )
32+ license_file = os .path .join (top_level_git_dir , 'LICENSE' )
33+ with ctx .cd (top_level_git_dir ):
34+ files = ctx .run ("git diff --relative --diff-filter=ACMRTUXB "
35+ "--name-only {}" .format (base_branch )).stdout .splitlines ()
36+ if os .environ .get ('FORCE_CHECK_ALL_FILES' , False ) == 'true' or files :
37+ # Check for the existence of a LICENSE file
38+ if not os .path .exist (license_file ):
39+ raise Exception ("Missing LICENSE file in {root_dir}" .format (root_dir = top_level_git_dir ))
40+
41+ with open (license_file ) as f :
42+ lines = f .read ().splitlines ()
43+
44+ found_apache_license = False
45+ found_license_version = False
46+ found_apache_url = False
47+ for line in lines :
48+ if apache_license_rgx .match (line ):
49+ found_apache_license = True
50+ if license_version_rgx .match (line ):
51+ found_license_version = True
52+ if apache_url_rgx .match (line ):
53+ found_apache_url = True
54+ if found_apache_license and found_license_version and found_apache_url :
55+ break
56+ else :
57+ raise Exception ("LICENSE file doesn't contain Apache 2.0 license text" )
58+ else :
59+ print ("No files have changed, skipping run..." )
60+
61+
2062@task (copy .copy_pack_to_subdirectory )
2163def configs (ctx ):
2264 print ("" )
0 commit comments