From cff8bde1a0befdd0c675b54319626475a910106b Mon Sep 17 00:00:00 2001 From: Thiago Brito Date: Tue, 24 Aug 2021 12:24:19 -0300 Subject: [PATCH] Create new branch on bare clone for LOCI This commit will force a branch creation on a bare clone of the locally cloned repo so LOCI can use it afterwards to build images. The aim is to prevent images from being build with code different from what is checked-in on the local repo. That way we can avoid controlling branches in two places (manifest and loci files). Story: 2003907 Task: 42364 Signed-off-by: Thiago Brito Change-Id: I863ac450ddfaec3115f3ecbc2789fc5d7c9d887f --- .../build-docker-images/build-stx-images.sh | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/build-tools/build-docker-images/build-stx-images.sh b/build-tools/build-docker-images/build-stx-images.sh index e45a9a4a..4b4f4d03 100755 --- a/build-tools/build-docker-images/build-stx-images.sh +++ b/build-tools/build-docker-images/build-stx-images.sh @@ -358,12 +358,26 @@ function build_image_loci { \rm -rf ${CLONE_DIR} echo "Creating bare clone of ${PROJECT_REPO} for ${LABEL} build..." - git clone --bare ${PROJECT_REPO} ${CLONE_DIR} \ - && mv ${CLONE_DIR}/hooks/post-update.sample ${CLONE_DIR}/hooks/post-update \ - && chmod a+x ${CLONE_DIR}/hooks/post-update \ - && cd ${CLONE_DIR} \ - && git update-server-info \ - && cd ${ORIGWD} + if [ -n "${PROJECT_REF}" ]; then + echo "PROJECT_REF specified is ${PROJECT_REF}..." + git clone --bare ${PROJECT_REPO} ${CLONE_DIR} \ + && cd ${PROJECT_REPO} \ + && git push --force ${CLONE_DIR} HEAD:refs/heads/${PROJECT_REF} \ + && mv ${CLONE_DIR}/hooks/post-update.sample ${CLONE_DIR}/hooks/post-update \ + && chmod a+x ${CLONE_DIR}/hooks/post-update \ + && cd ${CLONE_DIR} \ + && git update-server-info \ + && cd ${ORIGWD} + else + git clone --bare ${PROJECT_REPO} ${CLONE_DIR} \ + && cd ${PROJECT_REPO} \ + && mv ${CLONE_DIR}/hooks/post-update.sample ${CLONE_DIR}/hooks/post-update \ + && chmod a+x ${CLONE_DIR}/hooks/post-update \ + && cd ${CLONE_DIR} \ + && git update-server-info \ + && cd ${ORIGWD} + fi + if [ $? -ne 0 ]; then echo "Failed to clone ${PROJECT_REPO}... Aborting ${LABEL} build" RESULTS_FAILED+=(${LABEL})