|
15 | 15 | """Print a list of packages which require testing.""" |
16 | 16 |
|
17 | 17 | import os |
| 18 | +import re |
18 | 19 | import subprocess |
19 | 20 | import warnings |
20 | 21 |
|
21 | 22 |
|
22 | 23 | CURRENT_DIR = os.path.realpath(os.path.dirname(__file__)) |
23 | 24 | BASE_DIR = os.path.realpath(os.path.join(CURRENT_DIR, '..', '..')) |
24 | 25 | GITHUB_REPO = os.environ.get('GITHUB_REPO', 'google-cloud-python') |
| 26 | +CIRCLE_TAG = os.environ.get('CIRCLE_TAG') |
| 27 | +# NOTE: This reg-ex is copied from ``get_tagged_packages``. |
| 28 | +TAG_RE = re.compile(r""" |
| 29 | + ^ |
| 30 | + (?P<pkg> |
| 31 | + (([a-z]+)-)*) # pkg-name-with-hyphens- (empty allowed) |
| 32 | + ([0-9]+)\.([0-9]+)\.([0-9]+) # Version x.y.z (x, y, z all ints) |
| 33 | + $ |
| 34 | +""", re.VERBOSE) |
25 | 35 |
|
26 | 36 | # This is the current set of dependencies by package. |
27 | 37 | # As of this writing, the only "real" dependency is that of error_reporting |
@@ -143,7 +153,42 @@ def get_changed_packages(file_list): |
143 | 153 | return answer |
144 | 154 |
|
145 | 155 |
|
| 156 | +def get_tagged_package(): |
| 157 | + """Return the package corresponding to the current tag. |
| 158 | +
|
| 159 | + If there is not tag, will return :data:`None`. |
| 160 | + """ |
| 161 | + if CIRCLE_TAG is None: |
| 162 | + return |
| 163 | + |
| 164 | + match = TAG_RE.match(CIRCLE_TAG) |
| 165 | + if match is None: |
| 166 | + return |
| 167 | + |
| 168 | + pkg_name = match.group('pkg') |
| 169 | + if pkg_name == '': |
| 170 | + # NOTE: This corresponds to the "umbrella" tag. |
| 171 | + return |
| 172 | + |
| 173 | + return pkg_name.rstrip('-').replace('-', '_') |
| 174 | + |
| 175 | + |
| 176 | +def get_target_packages(): |
| 177 | + """Return a list of target packages to be run in the current build. |
| 178 | +
|
| 179 | + If in a tag build, will run only the package(s) that are tagged, otherwise |
| 180 | + will run the packages that have file changes in them (or packages that |
| 181 | + depend on those). |
| 182 | + """ |
| 183 | + tagged_package = get_tagged_package() |
| 184 | + if tagged_package is None: |
| 185 | + file_list = get_changed_files() |
| 186 | + for package in sorted(get_changed_packages(file_list)): |
| 187 | + yield package |
| 188 | + else: |
| 189 | + yield tagged_package |
| 190 | + |
| 191 | + |
146 | 192 | if __name__ == '__main__': |
147 | | - file_list = get_changed_files() |
148 | | - for package in sorted(get_changed_packages(file_list)): |
| 193 | + for package in get_target_packages(): |
149 | 194 | print(package) |
0 commit comments