Skip to content

Commit b5cb3be

Browse files
DLPX-91971 linux-pkg: Add support for os-upgrade branches (#320)
PR URL: https://www.github.com/delphix/linux-pkg/pull/320
1 parent 649bfd2 commit b5cb3be

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lib/common.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,24 @@ function git_fetch_helper() {
746746
git fetch "$git_url" "$@" || die "git fetch failed"
747747
}
748748

749+
#
750+
# Run git fetch with the passed arguments. Git url must be passed as first
751+
# argument. If FETCH_GIT_TOKEN is set and this is a github repository
752+
# then pass-in the token when fetching.
753+
#
754+
function git_branch_exists() {
755+
local git_url="$1"
756+
local label=''
757+
shift
758+
759+
if [[ -n "$FETCH_GIT_TOKEN" ]] &&
760+
[[ "$git_url" == https://github.com/* ]]; then
761+
git_url="${git_url/https:\/\//https:\/\/${FETCH_GIT_TOKEN}@}"
762+
label='[token passed]'
763+
fi
764+
git fetch "$git_url" "$@" --no-tags --depth=1 || return 1
765+
}
766+
749767
#
750768
# Fetch package repository into $WORKDIR/repo
751769
#
@@ -769,6 +787,25 @@ function fetch_repo_from_git() {
769787
logmust git show-ref repo-HEAD
770788
logmust git show-ref upstream-HEAD
771789
else
790+
791+
#
792+
# The "os-upgrade" branch is used for Ubuntu version upgrade projects. As such, the following
793+
# block of code will only be executed if the `PACKAGE_GIT_BRANCH` is set to "os-upgrade". Not
794+
# all product repositories are required to have an "os-upgrade" branch, because some packages
795+
# will successfully build on the new Ubuntu version as well as the old without any changes.
796+
# To allow engineering to create the "os-upgrade" branch only in repositories that require
797+
# changes for the new Ubuntu version, this block of code will check if the "os-upgrade" branch
798+
# exists in the repository and if it does not, it will build off of "develop" instead.
799+
#
800+
if [[ "$PACKAGE_GIT_BRANCH" == "os-upgrade" ]]; then
801+
git_branch_exists "$PACKAGE_GIT_URL" "$PACKAGE_GIT_BRANCH"
802+
branch_exists=$?
803+
if [[ $branch_exists -ne 0 ]]; then
804+
echo "NOTE: The branch 'os-upgrade' does not exist for this repo. Using 'develop' instead."
805+
PACKAGE_GIT_BRANCH="develop"
806+
fi
807+
fi
808+
772809
logmust git_fetch_helper "$PACKAGE_GIT_URL" --no-tags \
773810
"+$PACKAGE_GIT_BRANCH:repo-HEAD" --depth=1
774811
logmust git show-ref repo-HEAD

0 commit comments

Comments
 (0)