@@ -17,6 +17,47 @@ 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+ license_file = os .path .join (top_level_git_dir , 'LICENSE' )
32+ with ctx .cd (top_level_git_dir ):
33+ files = ctx .run ("git diff --relative --diff-filter=ACMRTUXB "
34+ "--name-only {}" .format (base_branch )).stdout .splitlines ()
35+ if os .environ .get ('FORCE_CHECK_ALL_FILES' , False ) == 'true' or files :
36+ # Check for the existence of a LICENSE file
37+ if not os .path .exist (license_file ):
38+ raise Exception ("Missing LICENSE file in {root_dir}" .format (root_dir = top_level_git_dir ))
39+
40+ with open (license_file ) as f :
41+ lines = f .read ().splitlines ()
42+
43+ found_apache_license = False
44+ found_license_version = False
45+ found_apache_url = False
46+ for line in lines :
47+ if apache_license_rgx .match (line ):
48+ found_apache_license = True
49+ if license_version_rgx .match (line ):
50+ found_license_version = True
51+ if apache_url_rgx .match (line ):
52+ found_apache_url = True
53+ if found_apache_license and found_license_version and found_apache_url :
54+ break
55+ else :
56+ raise Exception ("LICENSE file doesn't contain Apache 2.0 license text" )
57+ else :
58+ print ("No files have changed, skipping run..." )
59+
60+
2061@task (copy .copy_pack_to_subdirectory )
2162def configs (ctx ):
2263 print ("" )
0 commit comments