Skip to content

Commit fc0368e

Browse files
authored
Use better merge base for detecting changed packages (googleapis#5018)
1 parent 77a1f68 commit fc0368e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

test_utils/scripts/get_target_packages.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,26 @@ def get_baseline():
5757
On a push to master, return None. This will effectively cause everything
5858
to be considered to be affected.
5959
"""
60+
ci_branch = os.environ.get('CIRCLE_BRANCH')
61+
ci_pr = os.environ.get('CIRCLE_PR_NUMBER')
62+
6063
# If this is a pull request or branch, return the tip for master.
6164
# We will test only packages which have changed since that point.
6265
ci_non_master = os.environ.get('CI', '') == 'true' and any([
63-
os.environ.get('CIRCLE_BRANCH', '') != 'master',
64-
os.environ.get('CIRCLE_PR_NUMBER', ''),
66+
ci_branch != 'master',
67+
ci_pr,
6568
])
6669
if ci_non_master:
70+
if ci_branch is not None:
71+
output = subprocess.check_output(
72+
['git', 'merge-base', 'master', ci_branch])
73+
return output.strip().decode('ascii')
74+
6775
repo_url = 'git@github.com:GoogleCloudPlatform/{}'.format(GITHUB_REPO)
6876
subprocess.run(['git', 'remote', 'add', 'baseline', repo_url],
6977
stderr=subprocess.DEVNULL)
7078
subprocess.run(['git', 'pull', 'baseline'], stderr=subprocess.DEVNULL)
79+
# Can we have a PR but not a branch?
7180
return 'baseline/master'
7281

7382
# If environment variables are set identifying what the master tip is,

0 commit comments

Comments
 (0)