Skip to content

Commit c0161e1

Browse files
committed
simplify rsync deploy action
1 parent 56af482 commit c0161e1

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

.github/actions/rsync-deployments/action.yml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ inputs:
77
required: false
88
default: "--archive --compress"
99
path:
10-
description: Local source directory (always copies its content)
10+
description: Local source directory (always copies its content only)
1111
required: true
1212
remote_path:
1313
description: Remote destination directory
@@ -25,46 +25,28 @@ inputs:
2525
remote_key:
2626
description: SSH private key (OpenSSH/PEM)
2727
required: true
28-
known_hosts:
29-
description: Optional known_hosts entry for the remote host
30-
required: false
3128
runs:
3229
using: composite
3330
steps:
34-
- name: Prepare SSH
31+
- name: rsync via ssh-agent
3532
shell: bash
3633
run: |
3734
set -euo pipefail
38-
install -m 700 -d ~/.ssh
39-
printf '%s\n' "${{ inputs.remote_key }}" > ~/.ssh/id_ed25519
40-
chmod 600 ~/.ssh/id_ed25519
41-
42-
SSH_PORT="${{ inputs.remote_port }}"
43-
[[ -z "$SSH_PORT" ]] && SSH_PORT=22
4435
45-
if [[ -n "${{ inputs.known_hosts }}" ]]; then
46-
printf '%s\n' "${{ inputs.known_hosts }}" > ~/.ssh/known_hosts
47-
else
48-
ssh-keyscan -p "$SSH_PORT" -H "${{ inputs.remote_host }}" >> ~/.ssh/known_hosts
49-
fi
36+
# Start agent and load the key
37+
eval "$(ssh-agent -s)"
38+
ssh-add - <<< "${{ inputs.remote_key }}"
5039
51-
- name: Rsync upload
52-
shell: bash
53-
run: |
54-
set -euo pipefail
55-
SSH_PORT="${{ inputs.remote_port }}"
56-
[[ -z "$SSH_PORT" ]] && SSH_PORT=22
57-
SSH_CMD="ssh -p ${SSH_PORT} -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=yes"
40+
# SSH command with host key checking disabled (matches your reference impl)
41+
RSH="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${{ inputs.remote_port }}"
5842
59-
SRC="${{ inputs.path }}"
43+
# Resolve paths and DSN
44+
LOCAL_PATH="${GITHUB_WORKSPACE}/${{ inputs.path }}"
6045
DEST="${{ inputs.remote_path }}"
61-
USER="${{ inputs.remote_user }}"
62-
HOST="${{ inputs.remote_host }}"
46+
DSN="${{ inputs.remote_user }}@${{ inputs.remote_host }}"
6347
64-
# Ensure destination directory exists
65-
${SSH_CMD} "${USER}@${HOST}" "mkdir -p '${DEST%/}'"
48+
# Deploy (copy *contents* of LOCAL_PATH into DEST)
49+
rsync ${{ inputs.switches }} -e "$RSH" "${LOCAL_PATH%/}/" "$DSN:'${DEST%/}/'"
6650
67-
# Copy *contents* of SRC into DEST
68-
rsync ${{ inputs.switches }} \
69-
-e "${SSH_CMD}" \
70-
"${SRC%/}/" "${USER}@${HOST}:'${DEST%/}/'"
51+
# Cleanup identities from the agent
52+
ssh-add -D || true

0 commit comments

Comments
 (0)