From 3d80672bfe5ef69305a3219bb487febc4c0bda45 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Mon, 8 Jan 2024 10:37:34 +0100 Subject: [PATCH] (actions) sync ssh commands --- .github/workflows/main.yml | 3 ++- ci/azure-pipelines.example.yml | 1 + ci/azure-pipelines.multiple_pkgs.example.yml | 1 + ci/main/action.yml | 17 +++++++++-------- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c980f0eab..c9ca1fdf7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -119,7 +119,8 @@ jobs: SSH_ARG=() if [[ -n "${SSH_KEY}" ]] then - SSH_KEY_PATH="${HOME}/.ssh/ci_ssh_key" + SSH_KEY_PATH="${HOME}"/.ssh/ci_ssh_key + echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m" mkdir -p "${HOME}"/.ssh echo "${SSH_KEY}" > "${SSH_KEY_PATH}" chmod 600 "${SSH_KEY_PATH}" diff --git a/ci/azure-pipelines.example.yml b/ci/azure-pipelines.example.yml index ad648d922..9d806d510 100644 --- a/ci/azure-pipelines.example.yml +++ b/ci/azure-pipelines.example.yml @@ -67,6 +67,7 @@ steps: targetType: inline script: | # START SSH ONLY + echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m" mkdir -p "${HOME}"/.ssh cp $(deployKey.secureFilePath) "${HOME}"/.ssh/ci_ssh_key if [[ -n "${SSH_KNOWN_HOSTS}" ]] diff --git a/ci/azure-pipelines.multiple_pkgs.example.yml b/ci/azure-pipelines.multiple_pkgs.example.yml index a79395b45..c9cbaff70 100644 --- a/ci/azure-pipelines.multiple_pkgs.example.yml +++ b/ci/azure-pipelines.multiple_pkgs.example.yml @@ -110,6 +110,7 @@ stages: targetType: inline script: | # START SSH ONLY + echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m" mkdir -p "${HOME}"/.ssh cp $(deployKey.secureFilePath) "${HOME}"/.ssh/ci_ssh_key if [[ -n "${SSH_KNOWN_HOSTS}" ]] diff --git a/ci/main/action.yml b/ci/main/action.yml index dc6ac6204..f5638bb49 100644 --- a/ci/main/action.yml +++ b/ci/main/action.yml @@ -59,20 +59,22 @@ runs: PULLREQUEST=${PULLREQUEST:-false} SSH_KEY="${{ inputs.ssh-key }}" SSH_KNOWN_HOSTS="${{ inputs.ssh-known-hosts }}" + SSH_ARG=() if [[ -n "${SSH_KEY}" ]] then - SSH_ARG="--ssh" + SSH_KEY_PATH="${HOME}"/.ssh/ci_ssh_key + echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m" mkdir -p "${HOME}"/.ssh - echo "${SSH_KEY}" > "${HOME}"/.ssh/ci_ssh_key - SSH_KEY_ARG="--ssh-key=${HOME}/.ssh/ci_ssh_key" + echo "${SSH_KEY}" > "${SSH_KEY_PATH}" + SSH_ARG+=("--ssh" "--ssh-key=${SSH_KEY_PATH}") fi if [[ -n "${SSH_KNOWN_HOSTS}" ]] then - echo -e "\e[35;1mmkdir -p ${HOME}/.ssh \e[0m" - mkdir -p ${HOME}/.ssh + echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m" + mkdir -p "${HOME}"/.ssh for host in ${SSH_KNOWN_HOSTS} do - echo -e "\e[35;1mssh-keyscan -t rsa -H \"${host}\" 2>&1 | tee -a ${HOME}/.ssh/known_hosts \e[0m" + echo -e "\e[35;1mssh-keyscan -t rsa -H \"${host}\" 2>&1 | tee -a ${HOME}/.ssh/known_hosts\e[0m" ssh-keyscan -t rsa -H "${host}" 2>&1 | tee -a "${HOME}"/.ssh/known_hosts done fi @@ -82,8 +84,7 @@ runs: --branch="${BRANCH}" \ --commit="${GITHUB_SHA}" \ --pullrequest="${PULLREQUEST}" \ - "${SSH_ARG}" \ - "${SSH_KEY_ARG}" + "${SSH_ARG[@]}" echo "::endgroup::" shell: bash