Skip to content

Commit 507fa0b

Browse files
Implement ssh-key and ssh-known-hosts support for GHA
1 parent 8c9b2a6 commit 507fa0b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

.github/action.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,25 @@ if [ "${ACT:-}" = true ]; then
4848
ici_warn "Detected act, bundling industrial_ci"
4949
fi
5050

51+
INPUT_SSH_KEY=$(printenv INPUT_SSH-KEY) || true
52+
INPUT_SSH_KNOWN_HOSTS=$(printenv INPUT_SSH-KNOWN-HOSTS) || true
53+
54+
if [ -n "${INPUT_SSH_KEY:-}" ]; then
55+
# start SSH agent
56+
# shellcheck disable=SC2046
57+
eval $(ssh-agent -s)
58+
# add key to agent
59+
ssh-add <(echo "$INPUT_SSH_KEY") || { res=$?; echo "could not add ssh key"; exit $res; }
60+
fi
61+
62+
if [ -n "${SSH_AUTH_SOCK:-}" ]; then
63+
# setup known hosts
64+
mkdir -p ~/.ssh
65+
if [ -n "${INPUT_SSH_KNOWN_HOSTS:-}" ]; then
66+
echo "$INPUT_SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
67+
else
68+
cat /etc/ssh/ssh_known_hosts >> ~/.ssh/known_hosts
69+
fi
70+
fi
71+
5172
env "$@" bash "$ICI_SRC_PATH/ci_main.sh"

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ inputs:
55
config:
66
description: 'Configuration in JSON format, e.g. from matrix'
77
required: false
8+
ssh-key:
9+
description: 'Entire content of your private SSH key file'
10+
required: false
11+
ssh-known-hosts:
12+
description: 'Addtional entries for the host key database'
13+
required: false
814
runs:
915
using: 'node20'
1016
main: '.github/action.js'

0 commit comments

Comments
 (0)