Skip to content

Commit

Permalink
cirrus: figure out DEST_BRANCH automatically
Browse files Browse the repository at this point in the history
Instead of us forgetting to update it on each new branch push.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Feb 12, 2025
1 parent af209f5 commit 07e5367
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ env:
####
#### Global variables used for all tasks
####
# Name of the ultimate destination branch for this CI run, PR or post-merge.
DEST_BRANCH: "main"
# Sane (default) value for GOPROXY and GOSUMDB.
GOPROXY: "https://proxy.golang.org,direct"
GOSUMDB: "sum.golang.org"
Expand Down Expand Up @@ -106,6 +104,11 @@ validate-source_task:
cd /
rm -rf $CIRRUS_WORKING_DIR
mkdir -p $CIRRUS_WORKING_DIR
if [[ -z "$CIRRUS_PR" ]]; then
DEST_BRANCH="$CIRRUS_BRANCH"
else
DEST_BRANCH="$CIRRUS_BASE_BRANCH"
fi
git clone --recursive --branch=$DEST_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
cd $CIRRUS_WORKING_DIR
git remote update origin
Expand Down
19 changes: 19 additions & 0 deletions contrib/cirrus/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ fi
# Managed by setup_environment.sh; holds task-specific definitions.
if [[ -r "/etc/ci_environment" ]]; then source /etc/ci_environment; fi

# Set DEST_BRANCH automatically, this var used for many checks,
# i.e. to find out the merge base to do build/commit checks.
# To avoid having to set it manually for each branch try to
# generate based of the CIRRUS env.
# shellcheck disable=SC2154
if [[ -z "$CIRRUS_PR" ]]; then
# shellcheck disable=SC2154
DEST_BRANCH="$CIRRUS_BRANCH"
else
# shellcheck disable=SC2154
DEST_BRANCH="$CIRRUS_BASE_BRANCH"
fi
if [[ -z "${DEST_BRANCH}" ]]; then
die "DEST_BRANCH is undefined, not running under cirrus?"
fi
msg "DEST_BRANCH is $DEST_BRANCH"
export DEST_BRANCH


# This is normally set from .cirrus.yml but default is necessary when
# running under hack/get_ci_vm.sh since it cannot infer the value.
DISTRO_NV="${DISTRO_NV:-$OS_REL_VER}"
Expand Down
2 changes: 2 additions & 0 deletions contrib/cirrus/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set -eo pipefail
set -a
source /etc/automation_environment
source $AUTOMATION_LIB_PATH/common_lib.sh
# shellcheck source=contrib/cirrus/lib.sh
source $(dirname $0)/lib.sh
set +a

req_env_vars CI DEST_BRANCH IMAGE_SUFFIX TEST_FLAVOR TEST_ENVIRON \
Expand Down

0 comments on commit 07e5367

Please sign in to comment.