Fix: Use refspec to push tag and code
[releng/global-jjb.git] / shell / release-job.sh
index a419438..6c280d2 100644 (file)
@@ -365,7 +365,13 @@ tag-git-repo(){
             fi
             git config user.name "$RELEASE_USERNAME"
             git config user.email "$RELEASE_EMAIL"
+            echo "INFO: push tag: $GIT_TAG"
             git push origin "$GIT_TAG"
+            # Check if sentinal file exists
+            if [[ -f .testhash ]]; then
+                echo "INFO: push code bundle"
+                git push origin "HEAD:${GERRIT_REFSPEC}"
+            fi
         fi
     fi
 }
@@ -399,6 +405,7 @@ artifact_release_file(){
             wget "${path}"/"${name}" -o artifacts/"${name}"
             if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
                 #lftools sign sigul artifacts
+                # shellcheck disable=SC2261
                 curl -v -u <NEXUSUSER>:<NEXUSPASS> --upload-file \
                     "${NEXUS_URL}"/content/repositories/releases/org/"${ORG}"/"${VERSION}"/"${name}" \;
             fi
@@ -458,9 +465,25 @@ maven_release_file(){
         gunzip taglist.log.gz
         cat "$PATCH_DIR"/taglist.log
     popd
-    git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
+
+    # compare if the commit sha1 from taglist is the same origin/${GERRIT_BRANCH}
+    # ensure that the tag lands on the target branch
+    # forward from the tagging point, then a spur commit is created
+    # for the tag
+    taghash="$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
+    # shellcheck disable=SC2046
+    if [ "${taghash}" = $(git rev-parse "origin/${GERRIT_BRANCH}") ]; then
+        git checkout "origin/${GERRIT_BRANCH}"
+        # sentinal file
+        touch .testhash
+    else
+        git checkout "${taghash}"
+    fi
+
     git fetch "$PATCH_DIR/${PROJECT//\//-}.bundle"
     git merge --ff-only FETCH_HEAD
+    # print last few changes to see how the bundle is applied
+    git log --graph --all --decorate --pretty=oneline -n10
     nexus_release
     tag-git-repo
 }