From 58320afad0b80d1da398240a19774922daac2bf2 Mon Sep 17 00:00:00 2001
From: Pierre Smeyers <pierre.smeyers@gmail.com>
Date: Tue, 19 Sep 2023 10:13:52 +0200
Subject: [PATCH] fix(release): fix and clarify Git config in release process

---
 templates/gitlab-ci-maven.yml | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/templates/gitlab-ci-maven.yml b/templates/gitlab-ci-maven.yml
index f4f697c..3911eef 100644
--- a/templates/gitlab-ci-maven.yml
+++ b/templates/gitlab-ci-maven.yml
@@ -175,6 +175,10 @@ stages:
   }
 
   function configure_scm_auth() {
+    log_info "Preparing Git repository for release..."
+    # set user info
+    git config --global user.email "${GITLAB_USER_EMAIL}"
+    git config --global user.name "${GITLAB_USER_NAME}"
     # shellcheck disable=SC2086
     scm_url=$(mvn $MAVEN_CLI_OPTS $mvn_settings_opt $java_proxy_args org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.scm.developerConnection -q -DforceStdout | tail -n 1)
     if [[ $scm_url == "scm:git:https"* ]]; then
@@ -198,8 +202,6 @@ stages:
         else
           echo "${GIT_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
         fi
-        git config --global user.email "${GITLAB_USER_EMAIL}"
-        git config --global user.name "${GITLAB_USER_LOGIN}"
       else
         log_error "--- project scm.developerConnection is using SSH protocol but no SSH key configured."
         log_error "--- Please either specify the \$GIT_PRIVATE_KEY variable or change to https protocol with username/password credentials."
@@ -559,9 +561,6 @@ mvn-release:
   stage: publish
   before_script:
     - !reference [ .mvn-base, before_script ]
-    - log_info "Preparing Git repository for release..."
-    - git config --global user.name $GITLAB_USER_ID
-    - git config --global user.email $GITLAB_USER_EMAIL
     - git checkout -B "$CI_COMMIT_REF_NAME"
   script:
     - configure_scm_auth
@@ -571,10 +570,10 @@ mvn-release:
       then
         if [ -z "${SEMREL_INFO_NEXT_VERSION}" ]
         then
-          log_info "no new version to release"
+          log_info "No next release version determined by semantic-release info: skip"
           exit 0
         else
-          log_info "semantic-release info is activated, using computed next version for release \\e[1;94m${SEMREL_INFO_NEXT_VERSION}\\e[0m"
+          log_info "Use next release version determined by semantic-release info: \\e[1;94m${SEMREL_INFO_NEXT_VERSION}\\e[0m"
           semrel_args="-DreleaseVersion=${SEMREL_INFO_NEXT_VERSION}"
         fi
       fi
-- 
GitLab