Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 964c154

Browse files
authored
Redo googleapis#5018: run only needed systests (googleapis#5482)
* Only match whole lines when searching target packages. * Add debugging output to 'get_target_packages.py'.
1 parent 7aabe3b commit 964c154

File tree

2 files changed

+69
-36
lines changed

2 files changed

+69
-36
lines changed

.circleci/config.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
build:
55
docker:
6-
- image: googleapis/nox:0.18.2
6+
- image: googleapis/nox:0.17.0
77
steps:
88
- checkout
99
- run:
@@ -43,151 +43,151 @@ jobs:
4343
- run:
4444
name: Run tests - google.api_core
4545
command: |
46-
if [[ -n $(grep api_core ~/target_packages) ]]; then
46+
if [[ -n $(grep -x api_core ~/target_packages) ]]; then
4747
nox -f api_core/nox.py
4848
fi
4949
- run:
5050
name: Run tests - google.cloud.core
5151
command: |
52-
if [[ -n $(grep core ~/target_packages) ]]; then
52+
if [[ -n $(grep -x core ~/target_packages) ]]; then
5353
nox -f core/nox.py
5454
fi
5555
- run:
5656
name: Run tests - google.cloud.bigquery
5757
command: |
58-
if [[ -n $(grep bigquery ~/target_packages) ]]; then
58+
if [[ -n $(grep -x bigquery ~/target_packages) ]]; then
5959
nox -f bigquery/nox.py
6060
fi
6161
- run:
6262
name: Run tests - google.cloud.bigquery_datatransfer
6363
command: |
64-
if [[ -n $(grep bigquery_datatransfer ~/target_packages) ]]; then
64+
if [[ -n $(grep -x bigquery_datatransfer ~/target_packages) ]]; then
6565
nox -f bigquery_datatransfer/nox.py
6666
fi
6767
- run:
6868
name: Run tests - google.cloud.bigtable
6969
command: |
70-
if [[ -n $(grep bigtable ~/target_packages) ]]; then
70+
if [[ -n $(grep -x bigtable ~/target_packages) ]]; then
7171
nox -f bigtable/nox.py
7272
fi
7373
- run:
7474
name: Run tests - google.cloud.container
7575
command: |
76-
if [[ -n $(grep container ~/target_packages) ]]; then
76+
if [[ -n $(grep -x container ~/target_packages) ]]; then
7777
nox -f container/nox.py
7878
fi
7979
- run:
8080
name: Run tests - google.cloud.datastore
8181
command: |
82-
if [[ -n $(grep datastore ~/target_packages) ]]; then
82+
if [[ -n $(grep -x datastore ~/target_packages) ]]; then
8383
nox -f datastore/nox.py
8484
fi
8585
- run:
8686
name: Run tests - google.cloud.dataproc
8787
command: |
88-
if [[ -n $(grep dataproc ~/target_packages) ]]; then
88+
if [[ -n $(grep -x dataproc ~/target_packages) ]]; then
8989
nox -f dataproc/nox.py
9090
fi
9191
- run:
9292
name: Run tests - google.cloud.dlp
9393
command: |
94-
if [[ -n $(grep dlp ~/target_packages) ]]; then
94+
if [[ -n $(grep -x dlp ~/target_packages) ]]; then
9595
nox -f dlp/nox.py
9696
fi
9797
- run:
9898
name: Run tests - google.cloud.dns
9999
command: |
100-
if [[ -n $(grep dns ~/target_packages) ]]; then
100+
if [[ -n $(grep -x dns ~/target_packages) ]]; then
101101
nox -f dns/nox.py
102102
fi
103103
- run:
104104
name: Run tests - google.cloud.error_reporting
105105
command: |
106-
if [[ -n $(grep error_reporting ~/target_packages) ]]; then
106+
if [[ -n $(grep -x error_reporting ~/target_packages) ]]; then
107107
nox -f error_reporting/nox.py
108108
fi
109109
- run:
110110
name: Run tests - google.cloud.firestore
111111
command: |
112-
if [[ -n $(grep firestore ~/target_packages) ]]; then
112+
if [[ -n $(grep -x firestore ~/target_packages) ]]; then
113113
nox -f firestore/nox.py
114114
fi
115115
- run:
116116
name: Run tests - google.cloud.language
117117
command: |
118-
if [[ -n $(grep language ~/target_packages) ]]; then
118+
if [[ -n $(grep -x language ~/target_packages) ]]; then
119119
nox -f language/nox.py
120120
fi
121121
- run:
122122
name: Run tests - google.cloud.logging
123123
command: |
124-
if [[ -n $(grep logging ~/target_packages) ]]; then
124+
if [[ -n $(grep -x logging ~/target_packages) ]]; then
125125
nox -f logging/nox.py
126126
fi
127127
- run:
128128
name: Run tests - google.cloud.monitoring
129129
command: |
130-
if [[ -n $(grep monitoring ~/target_packages) ]]; then
130+
if [[ -n $(grep -x monitoring ~/target_packages) ]]; then
131131
nox -f monitoring/nox.py
132132
fi
133133
- run:
134134
name: Run tests - google.cloud.pubsub
135135
command: |
136-
if [[ -n $(grep pubsub ~/target_packages) ]]; then
136+
if [[ -n $(grep -x pubsub ~/target_packages) ]]; then
137137
nox -f pubsub/nox.py
138138
fi
139139
- run:
140140
name: Run tests - google.cloud.resource_manager
141141
command: |
142-
if [[ -n $(grep resource_manager ~/target_packages) ]]; then
142+
if [[ -n $(grep -x resource_manager ~/target_packages) ]]; then
143143
nox -f resource_manager/nox.py
144144
fi
145145
- run:
146146
name: Run tests - google.cloud.runtimeconfig
147147
command: |
148-
if [[ -n $(grep runtimeconfig ~/target_packages) ]]; then
148+
if [[ -n $(grep -x runtimeconfig ~/target_packages) ]]; then
149149
nox -f runtimeconfig/nox.py
150150
fi
151151
- run:
152152
name: Run tests - google.cloud.spanner
153153
command: |
154-
if [[ -n $(grep spanner ~/target_packages) ]]; then
154+
if [[ -n $(grep -x spanner ~/target_packages) ]]; then
155155
nox -f spanner/nox.py
156156
fi
157157
- run:
158158
name: Run tests - google.cloud.speech
159159
command: |
160-
if [[ -n $(grep speech ~/target_packages) ]]; then
160+
if [[ -n $(grep -x speech ~/target_packages) ]]; then
161161
nox -f speech/nox.py
162162
fi
163163
- run:
164164
name: Run tests - google.cloud.storage
165165
command: |
166-
if [[ -n $(grep storage ~/target_packages) ]]; then
166+
if [[ -n $(grep -x storage ~/target_packages) ]]; then
167167
nox -f storage/nox.py
168168
fi
169169
- run:
170170
name: Run tests - google.cloud.trace
171171
command: |
172-
if [[ -n $(grep trace ~/target_packages) ]]; then
172+
if [[ -n $(grep -x trace ~/target_packages) ]]; then
173173
nox -f trace/nox.py
174174
fi
175175
- run:
176176
name: Run tests - google.cloud.translate
177177
command: |
178-
if [[ -n $(grep translate ~/target_packages) ]]; then
178+
if [[ -n $(grep -x translate ~/target_packages) ]]; then
179179
nox -f translate/nox.py
180180
fi
181181
- run:
182182
name: Run tests - google.cloud.vision
183183
command: |
184-
if [[ -n $(grep vision ~/target_packages) ]]; then
184+
if [[ -n $(grep -x vision ~/target_packages) ]]; then
185185
nox -f vision/nox.py
186186
fi
187187
- run:
188188
name: Run tests - google.cloud.videointelligence
189189
command: |
190-
if [[ -n $(grep videointelligence ~/target_packages) ]]; then
190+
if [[ -n $(grep -x videointelligence ~/target_packages) ]]; then
191191
nox -f videointelligence/nox.py
192192
fi
193193
- run:

test_utils/scripts/get_target_packages.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
CURRENT_DIR = os.path.realpath(os.path.dirname(__file__))
2424
BASE_DIR = os.path.realpath(os.path.join(CURRENT_DIR, '..', '..'))
2525
GITHUB_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')
2629
CIRCLE_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``.
2834
TAG_RE = re.compile(r"""
2935
^
@@ -45,24 +51,26 @@
4551
def 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_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 = '[email protected]: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:
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

Comments
 (0)