From e433241469126b6d38a24ce35a4eaf434196691f Mon Sep 17 00:00:00 2001 From: stertingen Date: Mon, 25 Jan 2021 17:32:17 +0100 Subject: [PATCH 1/4] Initial support for automatic setup of GitLab CI credentials --- .../gitlab-credential-helper | 31 +++++++++++++++++++ industrial_ci/src/isolation/docker.env | 5 +++ industrial_ci/src/workspace.sh | 9 ++++++ 3 files changed, 45 insertions(+) create mode 100755 industrial_ci/src/credential-helpers/gitlab-credential-helper diff --git a/industrial_ci/src/credential-helpers/gitlab-credential-helper b/industrial_ci/src/credential-helpers/gitlab-credential-helper new file mode 100755 index 000000000..bf2f0b884 --- /dev/null +++ b/industrial_ci/src/credential-helpers/gitlab-credential-helper @@ -0,0 +1,31 @@ +#!/bin/sh -e + +# Copyright (c) 2021, Mathias Lüdtke +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing@, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if [ "$1" = "get" ]; then + if [ -n "${CI_SERVER_PROTOCOL}" ]; then + echo "protocol=${CI_SERVER_PROTOCOL}" + fi + if [ -n "${CI_SERVER_HOST}" ]; then + if [ -n "${CI_SERVER_PORT}" ]; then + echo "host=${CI_SERVER_HOST}:${CI_SERVER_PORT}" + else + echo "host=${CI_SERVER_HOST}" + fi + fi + echo "username=gitlab-ci-token" + echo "password=${CI_JOB_TOKEN}" +fi diff --git a/industrial_ci/src/isolation/docker.env b/industrial_ci/src/isolation/docker.env index a637538da..f51d585cb 100644 --- a/industrial_ci/src/isolation/docker.env +++ b/industrial_ci/src/isolation/docker.env @@ -10,6 +10,11 @@ CATKIN_LINT CATKIN_LINT_ARGS CC CFLAGS +CI_JOB_TOKEN +CI_SERVER_HOST +CI_SERVER_PORT +CI_SERVER_PROTOCOL +CI_SERVER_URL CLANG_FORMAT_CHECK CLANG_FORMAT_VERSION CLANG_TIDY diff --git a/industrial_ci/src/workspace.sh b/industrial_ci/src/workspace.sh index 360c5ebc5..2103a8e40 100644 --- a/industrial_ci/src/workspace.sh +++ b/industrial_ci/src/workspace.sh @@ -111,11 +111,20 @@ function ici_install_pypi_pkgs_for_command { ici_exec_for_command "$command" ici_pip_install "$@" } +function ici_setup_git_credential_helper { + local url=$1; shift + local helper=$1; shift + git config --global "credential.${url}.helper" "${ICI_SRC_PATH}/credential-helpers/${helper}" +} + function ici_setup_git_client { ici_install_pkgs_for_command git git-core if [ -d ~/.ssh ]; then ici_install_pkgs_for_command ssh ssh-client fi + if [ -n "${CI_SERVER_URL}" -a -n "${CI_JOB_TOKEN}" ]; then + ici_setup_git_credential_helper "${CI_SERVER_URL}" "gitlab-credential-helper" + fi } function ici_vcs_import { From 97b23788c06c9f6a8da2092b5ab4643ae0c94ca5 Mon Sep 17 00:00:00 2001 From: stertingen Date: Mon, 25 Jan 2021 17:45:27 +0100 Subject: [PATCH 2/4] Fix shellcheck --- industrial_ci/src/workspace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/industrial_ci/src/workspace.sh b/industrial_ci/src/workspace.sh index 2103a8e40..a16a73053 100644 --- a/industrial_ci/src/workspace.sh +++ b/industrial_ci/src/workspace.sh @@ -122,7 +122,7 @@ function ici_setup_git_client { if [ -d ~/.ssh ]; then ici_install_pkgs_for_command ssh ssh-client fi - if [ -n "${CI_SERVER_URL}" -a -n "${CI_JOB_TOKEN}" ]; then + if [ -n "${CI_SERVER_URL}" ] && [ -n "${CI_JOB_TOKEN}" ]; then ici_setup_git_credential_helper "${CI_SERVER_URL}" "gitlab-credential-helper" fi } From d7c51a2bf67c40c0fa2e641e7104f70d752239f3 Mon Sep 17 00:00:00 2001 From: stertingen Date: Mon, 25 Jan 2021 17:49:48 +0100 Subject: [PATCH 3/4] Fix prerelease tests --- industrial_ci/src/workspace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/industrial_ci/src/workspace.sh b/industrial_ci/src/workspace.sh index a16a73053..e65a1959e 100644 --- a/industrial_ci/src/workspace.sh +++ b/industrial_ci/src/workspace.sh @@ -122,7 +122,7 @@ function ici_setup_git_client { if [ -d ~/.ssh ]; then ici_install_pkgs_for_command ssh ssh-client fi - if [ -n "${CI_SERVER_URL}" ] && [ -n "${CI_JOB_TOKEN}" ]; then + if [ -n "${CI_SERVER_URL:-}" ] && [ -n "${CI_JOB_TOKEN:-}" ]; then ici_setup_git_credential_helper "${CI_SERVER_URL}" "gitlab-credential-helper" fi } From 2559f4b8083cf04035a410925a03a561d6ba3a0a Mon Sep 17 00:00:00 2001 From: stertingen Date: Mon, 25 Jan 2021 17:55:38 +0100 Subject: [PATCH 4/4] Add extra check for GitLab CI before adding credential helper --- industrial_ci/src/isolation/docker.env | 1 + industrial_ci/src/workspace.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/industrial_ci/src/isolation/docker.env b/industrial_ci/src/isolation/docker.env index f51d585cb..963971ef3 100644 --- a/industrial_ci/src/isolation/docker.env +++ b/industrial_ci/src/isolation/docker.env @@ -27,6 +27,7 @@ CXXFLAGS DEBUG_BASH DOWNSTREAM_CMAKE_ARGS DOWNSTREAM_WORKSPACE +GITLAB_CI HASHKEY_SKS # EXPECT_EXIT_CODE, do not pass to make sure code is checked on the outer level only IMMEDIATE_TEST_OUTPUT diff --git a/industrial_ci/src/workspace.sh b/industrial_ci/src/workspace.sh index e65a1959e..956f2f526 100644 --- a/industrial_ci/src/workspace.sh +++ b/industrial_ci/src/workspace.sh @@ -122,7 +122,7 @@ function ici_setup_git_client { if [ -d ~/.ssh ]; then ici_install_pkgs_for_command ssh ssh-client fi - if [ -n "${CI_SERVER_URL:-}" ] && [ -n "${CI_JOB_TOKEN:-}" ]; then + if [ "${GITLAB_CI:-false}" = "true" ] && [ -n "${CI_SERVER_URL:-}" ] && [ -n "${CI_JOB_TOKEN:-}" ]; then ici_setup_git_credential_helper "${CI_SERVER_URL}" "gitlab-credential-helper" fi }