Skip to content

Commit cd478f7

Browse files
authored
Update action.yml
modify ssh socks approach to make it compatible with self-hosted runners
1 parent e41a801 commit cd478f7

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

utils/ssh-agent/action.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
name: 'ModernTribe - SSH Agent'
22
description: 'Setup SSH Agent'
33
author: 'moderntribe'
4+
45
inputs:
5-
ssh_private_key:
6-
required: true
7-
description: SSH Private Key
8-
server:
9-
required: false
10-
description: Server
6+
ssh_private_key:
7+
required: true
8+
description: SSH Private Key
9+
server:
10+
required: false
11+
description: Server
12+
1113
runs:
12-
using: composite
13-
steps:
14-
- name: Add SSH key
15-
shell: bash
16-
env:
17-
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
18-
run: |
19-
mkdir -p /home/runner/.ssh
20-
install -m 600 -D /dev/null /home/runner/.ssh/id_rsa
21-
echo "${{ inputs.ssh_private_key }}" > /home/runner/.ssh/id_rsa
22-
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
23-
ssh-add /home/runner/.ssh/id_rsa
14+
using: composite
15+
steps:
16+
- name: Generate unique SSH_AUTH_SOCK path
17+
shell: bash
18+
run: |
19+
export SSH_AUTH_SOCK="/tmp/ssh_agent_${{ github.run_id }}.sock"
20+
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> "$GITHUB_ENV"
21+
22+
- name: Add SSH key
23+
shell: bash
24+
env:
25+
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
26+
run: |
27+
mkdir -p /home/runner/.ssh
28+
install -m 600 -D /dev/null /home/runner/.ssh/id_rsa
29+
echo "${{ inputs.ssh_private_key }}" > /home/runner/.ssh/id_rsa
30+
ssh-agent -a "$SSH_AUTH_SOCK" > /dev/null
31+
ssh-add /home/runner/.ssh/id_rsa
2432
25-
- name: Add server to knownhosts
26-
if: ${{ inputs.server != '' }}
27-
shell: bash
28-
run: |
29-
ssh-keyscan -H ${{ inputs.server }} > /home/runner/.ssh/known_hosts
33+
- name: Add server to known_hosts
34+
if: ${{ inputs.server != '' }}
35+
shell: bash
36+
run: |
37+
mkdir -p /home/runner/.ssh
38+
ssh-keyscan -H ${{ inputs.server }} > /home/runner/.ssh/known_hosts

0 commit comments

Comments
 (0)