Skip to content

Commit 07e5367

Browse files
committed
cirrus: figure out DEST_BRANCH automatically
Instead of us forgetting to update it on each new branch push. Signed-off-by: Paul Holzinger <[email protected]>
1 parent af209f5 commit 07e5367

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.cirrus.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ env:
55
####
66
#### Global variables used for all tasks
77
####
8-
# Name of the ultimate destination branch for this CI run, PR or post-merge.
9-
DEST_BRANCH: "main"
108
# Sane (default) value for GOPROXY and GOSUMDB.
119
GOPROXY: "https://proxy.golang.org,direct"
1210
GOSUMDB: "sum.golang.org"
@@ -106,6 +104,11 @@ validate-source_task:
106104
cd /
107105
rm -rf $CIRRUS_WORKING_DIR
108106
mkdir -p $CIRRUS_WORKING_DIR
107+
if [[ -z "$CIRRUS_PR" ]]; then
108+
DEST_BRANCH="$CIRRUS_BRANCH"
109+
else
110+
DEST_BRANCH="$CIRRUS_BASE_BRANCH"
111+
fi
109112
git clone --recursive --branch=$DEST_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
110113
cd $CIRRUS_WORKING_DIR
111114
git remote update origin

contrib/cirrus/lib.sh

+19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ fi
3636
# Managed by setup_environment.sh; holds task-specific definitions.
3737
if [[ -r "/etc/ci_environment" ]]; then source /etc/ci_environment; fi
3838

39+
# Set DEST_BRANCH automatically, this var used for many checks,
40+
# i.e. to find out the merge base to do build/commit checks.
41+
# To avoid having to set it manually for each branch try to
42+
# generate based of the CIRRUS env.
43+
# shellcheck disable=SC2154
44+
if [[ -z "$CIRRUS_PR" ]]; then
45+
# shellcheck disable=SC2154
46+
DEST_BRANCH="$CIRRUS_BRANCH"
47+
else
48+
# shellcheck disable=SC2154
49+
DEST_BRANCH="$CIRRUS_BASE_BRANCH"
50+
fi
51+
if [[ -z "${DEST_BRANCH}" ]]; then
52+
die "DEST_BRANCH is undefined, not running under cirrus?"
53+
fi
54+
msg "DEST_BRANCH is $DEST_BRANCH"
55+
export DEST_BRANCH
56+
57+
3958
# This is normally set from .cirrus.yml but default is necessary when
4059
# running under hack/get_ci_vm.sh since it cannot infer the value.
4160
DISTRO_NV="${DISTRO_NV:-$OS_REL_VER}"

contrib/cirrus/prebuild.sh

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ set -eo pipefail
1212
set -a
1313
source /etc/automation_environment
1414
source $AUTOMATION_LIB_PATH/common_lib.sh
15+
# shellcheck source=contrib/cirrus/lib.sh
16+
source $(dirname $0)/lib.sh
1517
set +a
1618

1719
req_env_vars CI DEST_BRANCH IMAGE_SUFFIX TEST_FLAVOR TEST_ENVIRON \

0 commit comments

Comments
 (0)