ci/common: use gitlab CI target branch in get_upstream_branch (MR 5082)

This prefers gitlab CI's target branch from the env, and falls back to
the old target branch detection mechanism (using pmaports.cfg, etc) if
it's not set. This fixes CI in gitlab where the target branch is
something different than expected, e.g. if using stacked branches.

[ci:skip-build]: already built successfully in CI
This commit is contained in:
Clayton Craft 2024-04-30 10:36:32 -07:00 committed by Pablo Correa Gómez
parent 5db3273820
commit c63e05246f
No known key found for this signature in database
GPG key ID: 7A342565FF635F79

View file

@ -59,6 +59,11 @@ def get_upstream_branch():
channels.cfg from master to retrieve the upstream branch.
:returns: branch name, e.g. "v20.05" """
# Prefer gitlab CI target branch name if it's set (i.e. running in gitlab CI)
if target_branch := os.environ.get("CI_MERGE_REQUEST_TARGET_BRANCH_NAME"):
return target_branch
global cache
if "upstream_branch" in cache:
return cache["upstream_branch"]