2323CURRENT_DIR = os .path .realpath (os .path .dirname (__file__ ))
2424BASE_DIR = os .path .realpath (os .path .join (CURRENT_DIR , '..' , '..' ))
2525GITHUB_REPO = os .environ .get ('GITHUB_REPO' , 'google-cloud-python' )
26+ CI = os .environ .get ('CI' , '' )
27+ CI_BRANCH = os .environ .get ('CIRCLE_BRANCH' )
28+ CI_PR = os .environ .get ('CIRCLE_PR_NUMBER' )
2629CIRCLE_TAG = os .environ .get ('CIRCLE_TAG' )
30+ MAJOR_DIV = '#' * 78
31+ MINOR_DIV = '#' + '-' * 77
32+
2733# NOTE: This reg-ex is copied from ``get_tagged_packages``.
2834TAG_RE = re .compile (r"""
2935 ^
4551def get_baseline ():
4652 """Return the baseline commit.
4753
48- On a pull request, or on a branch, return the master tip.
54+ On a pull request, or on a branch, return the common parent revision
55+ with the master branch.
4956
5057 Locally, return a value pulled from environment variables, or None if
5158 the environment variables are not set.
5259
5360 On a push to master, return None. This will effectively cause everything
5461 to be considered to be affected.
5562 """
56- ci_branch = os .environ .get ('CIRCLE_BRANCH' )
57- ci_pr = os .environ .get ('CIRCLE_PR_NUMBER' )
5863
5964 # If this is a pull request or branch, return the tip for master.
6065 # We will test only packages which have changed since that point.
61- ci_non_master = os .environ .get ('CI' , '' ) == 'true' and any ([
62- ci_branch != 'master' ,
63- ci_pr ,
64- ])
66+ ci_non_master = (CI == 'true' ) and any ([CI_BRANCH != 'master' , CI_PR ])
67+
6568 if ci_non_master :
69+ if CI_PR is None and CI_BRANCH is not None :
70+ output = subprocess .check_output (
71+ ['git' , 'merge-base' , 'master' , CI_BRANCH ])
72+ return output .strip ().decode ('ascii' )
73+
6674 repo_url = 'git@github.com:GoogleCloudPlatform/{}' .format (GITHUB_REPO )
6775 subprocess .run (['git' , 'remote' , 'add' , 'baseline' , repo_url ],
6876 stderr = subprocess .DEVNULL )
@@ -78,7 +86,7 @@ def get_baseline():
7886 return '%s/%s' % (remote , branch )
7987
8088 # If we are not in CI and we got this far, issue a warning.
81- if not os . environ . get ( 'CI' , '' ) :
89+ if not CI :
8290 warnings .warn ('No baseline could be determined; this means tests '
8391 'will run for every package. If this is local '
8492 'development, set the $GOOGLE_CLOUD_TESTING_REMOTE '
@@ -95,6 +103,7 @@ def get_changed_files():
95103 """
96104 # Get the baseline, and fail quickly if there is no baseline.
97105 baseline = get_baseline ()
106+ print ('# Baseline commit: {}' .format (baseline ))
98107 if not baseline :
99108 return None
100109
@@ -215,12 +224,36 @@ def get_target_packages():
215224 tagged_package = get_tagged_package ()
216225 if tagged_package is None :
217226 file_list = get_changed_files ()
227+ print (MAJOR_DIV )
228+ print ('# Changed files:' )
229+ print (MINOR_DIV )
230+ for file_ in file_list or ():
231+ print ('# {}' .format (file_ ))
218232 for package in sorted (get_changed_packages (file_list )):
219233 yield package
220234 else :
221235 yield tagged_package
222236
223237
224- if __name__ == '__main__' :
225- for package in get_target_packages ():
238+ def main ():
239+ print (MAJOR_DIV )
240+ print ('# Environment' )
241+ print (MINOR_DIV )
242+ print ('# CircleCI: {}' .format (CI ))
243+ print ('# CircleCI branch: {}' .format (CI_BRANCH ))
244+ print ('# CircleCI pr: {}' .format (CI_PR ))
245+ print ('# CircleCI tag: {}' .format (CIRCLE_TAG ))
246+ print (MAJOR_DIV )
247+
248+ packages = list (get_target_packages ())
249+
250+ print (MAJOR_DIV )
251+ print ('# Target packages:' )
252+ print (MINOR_DIV )
253+ for package in packages :
226254 print (package )
255+ print (MAJOR_DIV )
256+
257+
258+ if __name__ == '__main__' :
259+ main ()
0 commit comments