build: manually unshallow the repo for builds publishing, use absolute paths (#45979)

Use the absolute path for the artifacts directory, as well as encapsulate the clone
vs init logic to prevent it from changing directories.

Manually remove the shallow marker so that git does not recognize this as a shallow repo.

PR Close #45979
This commit is contained in:
Joey Perrott 2022-05-12 22:30:23 +00:00 committed by Jessica Janiuk
parent ec4104ee28
commit e1a93e4d7c

View file

@ -49,23 +49,31 @@ function publishRepo {
echo "Starting cloning process of ${REPO_URL} into ${REPO_DIR}.."
if [[ $(git ls-remote --heads ${REPO_URL} ${BRANCH}) ]]; then
echo "Branch ${BRANCH} already exists. Cloning that branch."
git clone ${REPO_URL} ${REPO_DIR} --depth 1 --branch ${BRANCH}
(
if [[ $(git ls-remote --heads ${REPO_URL} ${BRANCH}) ]]; then
echo "Branch ${BRANCH} already exists. Cloning that branch."
git clone ${REPO_URL} ${REPO_DIR} --depth 1 --branch ${BRANCH}
cd ${REPO_DIR}
echo "Cloned repository and switched into the repository directory (${REPO_DIR})."
else
echo "Branch ${BRANCH} does not exist on ${packageRepo} yet."
echo "Cloning default branch and creating branch '${BRANCH}' on top of it."
cd ${REPO_DIR}
echo "Cloned repository and switched into the repository directory (${REPO_DIR})."
else
echo "Branch ${BRANCH} does not exist on ${packageRepo} yet."
echo "Cloning default branch and creating branch '${BRANCH}' on top of it."
git clone ${REPO_URL} ${REPO_DIR} --depth 1
cd ${REPO_DIR}
git clone ${REPO_URL} ${REPO_DIR} --depth 1
cd ${REPO_DIR}
echo "Cloned repository and switched into directory. Creating new branch now.."
echo "Cloned repository and switched into directory. Creating new branch now.."
git checkout -b ${BRANCH}
fi
git checkout -b ${BRANCH}
fi
)
# Unshallow the repo manually so that it doesn't trigger a push failure.
# This is generally unsafe, however we immediately remove all of the files from within
# the repo on the next line, so we should be able to safely treat the entire repo
# contents as an atomic piece to be pushed.
rm $REPO_DIR/.git/shallow
# copy over build artifacts into the repo directory
rm -rf $REPO_DIR/*
@ -135,11 +143,12 @@ function publishAllBuilds() {
COMMIT_MSG=`git log --oneline -1`
COMMITTER_USER_NAME=`git --no-pager show -s --format='%cN' HEAD`
COMMITTER_USER_EMAIL=`git --no-pager show -s --format='%cE' HEAD`
PACKAGES_DIST="$(pwd)/dist/packages-dist"
local shortSha=`git rev-parse --short HEAD`
local latestTag=`getLatestTag`
publishPackages $GIT_SCHEME dist/packages-dist $CUR_BRANCH "${latestTag}+${shortSha}"
publishPackages $GIT_SCHEME $PACKAGES_DIST $CUR_BRANCH "${latestTag}+${shortSha}"
}
# See docs/DEVELOPER.md for help