Commit d34f922d authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat(release): add custom Git user name and email support

parent a88294c4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -481,7 +481,8 @@ The release job is bound to the `publish` stage, appears only on production and
| `auto-release-enabled` / `PYTHON_AUTO_RELEASE_ENABLED`| When set the job start automatically on production branch. When not set (default), the job is manual. Note that this behavior also depends on release-enabled being set. | _none_ (disabled) |
| `release-next` / `PYTHON_RELEASE_NEXT`   | The part of the version to increase (one of: `major`, `minor`, `patch`) | `minor`           |
| `semrel-release-disabled` / `PYTHON_SEMREL_RELEASE_DISABLED`| Set to `true` to disable [semantic-release integration](#semantic-release-integration)   | _none_ (disabled) |
| :lock: `GIT_USERNAME`   | Git username for Git push operations (see below)                        | _none_            |
| :lock: `GIT_USER_NAME`  | Git user name to use when committing (global TBC variable)              | `$GITLAB_USER_NAME` |
| :lock: `GIT_USER_EMAIL` | Git user email to use when committing (global TBC variable)             | `$GITLAB_USER_EMAIL` |
| :lock: `GIT_PASSWORD`   | Git password for Git push operations (see below)                        | _none_            |
| :lock: `GIT_PRIVATE_KEY`| SSH key for Git push operations (see below)                             | _none_            |
| `release-commit-message` / `PYTHON_RELEASE_COMMIT_MESSAGE`| The Git commit message to use on the release commit. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are current_version and new_version. | `chore(python-release): {current_version} → {new_version}  [skip ci on prod]` |
@@ -596,7 +597,7 @@ The template handles both classic variable and file variable.

##### Using user/password credentials

Simply specify :lock: `$GIT_USERNAME` and :lock: `$GIT_PASSWORD` as secret project variables.
Simply specify :lock: `$GIT_USER_NAME` and :lock: `$GIT_PASSWORD` as secret project variables.

Note that the password should be an access token (preferably a [project](https://docs.gitlab.com/user/project/settings/project_access_tokens/) or [group](https://docs.gitlab.com/user/group/settings/group_access_tokens/) access token) with `write_repository` scope and `Maintainer` role.

+1 −1
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@
          "advanced": true
        },
        {
          "name": "GIT_USERNAME",
          "name": "GIT_USER_NAME",
          "description": "Git username for Git push operations",
          "secret": true
        },
+8 −7
Original line number Diff line number Diff line
@@ -899,10 +899,13 @@ variables:
  }

  function configure_scm_auth() {
    # set user info
    git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"
    git config --global user.name "${GIT_USER_NAME:-${GIT_USERNAME:-$GITLAB_USER_NAME}}"
    git_base_url=$(echo "$CI_REPOSITORY_URL" | cut -d\@ -f2)
    if [[ -n "${GIT_USERNAME}" ]] && [[ -n "${GIT_PASSWORD}" ]]; then
      log_info "--- using https protocol with SCM credentials from env (\$GIT_USERNAME and \$GIT_PASSWORD)..."
      export git_auth_url="https://${GIT_USERNAME}:${GIT_PASSWORD}@${git_base_url}"
    if [[ -n "${GIT_USER_NAME:-$GIT_USERNAME}" ]] && [[ -n "${GIT_PASSWORD}" ]]; then
      log_info "--- using https protocol with SCM credentials from env (\$GIT_USER_NAME and \$GIT_PASSWORD)..."
      export git_auth_url="https://${GIT_USER_NAME:-$GIT_USERNAME}:${GIT_PASSWORD}@${git_base_url}"
    elif [[ -n "${GIT_PRIVATE_KEY}" ]]; then
      log_info "--- using ssh protocol with SSH key from env (\$GIT_PRIVATE_KEY)..."
      mkdir -m 700 "${HOME}/.ssh"
@@ -916,7 +919,7 @@ variables:
      fi
      export git_auth_url="git@${git_base_url/\//:}"
    else
      log_error "--- Please specify either \$GIT_USERNAME and \$GIT_PASSWORD or \$GIT_PRIVATE_KEY variables to enable release (see doc)."
      log_error "--- Please specify either \$GIT_USER_NAME and \$GIT_PASSWORD or \$GIT_PRIVATE_KEY variables to enable release (see doc)."
      exit 1
    fi
  }
@@ -1667,10 +1670,8 @@ py-release:
    # install git and OpenSSH
    - maybe_install_packages git openssh-client
  script:
    - git config --global user.email "$GITLAB_USER_EMAIL"
    - git config --global user.name "$GITLAB_USER_LOGIN"
    - git checkout -B $CI_COMMIT_REF_NAME
    - configure_scm_auth
    - git checkout -B $CI_COMMIT_REF_NAME
    - py_release
  artifacts:
    paths: