-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
51 lines (45 loc) · 1.71 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Install SSH key
description: Stores a private SSH key on the GitHub Actions runner and adds it to the SSH agent.
author: Steffen Diswal
inputs:
key-name:
description: The name of the file in the `.ssh` directory that stores the value of `__private-key__`.
required: false
default: "id_ed25519"
#
known-hosts:
description: A newline-separated list of trusted remote host keys to be stored in `.ssh/known_hosts`.
required: true
#
__private-key__:
description: The private SSH key to be stored in `.ssh/<key-name>` and added to the SSH agent on the GitHub Actions runner.
required: true
runs:
using: composite
steps:
# language=sh
- run: |
if [[ ! "$KEY_NAME" =~ ^[0-9A-Za-z_.-]+$ ]]; then
echo 'Input parameter `key-name` must be non-empty and contain letters, numbers, dashes, underscores, and periods only.'
exit 2
elif [[ -z "$KNOWN_HOSTS" ]]; then
echo 'Input parameter `known-hosts` must be non-empty.'
exit 2
elif [[ -z "$PRIVATE_KEY" ]]; then
echo 'Input parameter `__private-key__` must be non-empty.'
exit 2
fi
mkdir "$HOME/.ssh"
echo "$KNOWN_HOSTS" > "$HOME/.ssh/known_hosts"
chmod 644 "$HOME/.ssh/known_hosts"
echo "$PRIVATE_KEY" > "$HOME/.ssh/$KEY_NAME"
chmod 600 "$HOME/.ssh/$KEY_NAME"
eval "$(ssh-agent -s)"
echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> "$GITHUB_ENV"
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> "$GITHUB_ENV"
ssh-add "$HOME/.ssh/$KEY_NAME"
env:
KEY_NAME: ${{ inputs.key-name }}
KNOWN_HOSTS: ${{ inputs.known-hosts }}
PRIVATE_KEY: ${{ inputs.__private-key__ }}
shell: bash