|
| 1 | +name: Rsync Deploy (local) |
| 2 | +description: Upload a folder to a single remote destination via rsync over SSH. |
| 3 | +inputs: |
| 4 | + switches: |
| 5 | + description: rsync switches |
| 6 | + required: false |
| 7 | + default: "--archive --compress" |
| 8 | + path: |
| 9 | + description: Local source directory (always copies its content) |
| 10 | + required: true |
| 11 | + remote_path: |
| 12 | + description: Remote destination directory |
| 13 | + required: true |
| 14 | + remote_host: |
| 15 | + description: SSH host |
| 16 | + required: true |
| 17 | + remote_port: |
| 18 | + description: SSH port |
| 19 | + required: false |
| 20 | + default: "22" |
| 21 | + remote_user: |
| 22 | + description: SSH username |
| 23 | + required: true |
| 24 | + remote_key: |
| 25 | + description: SSH private key (OpenSSH/PEM) |
| 26 | + required: true |
| 27 | + known_hosts: |
| 28 | + description: Optional known_hosts entry for the remote host |
| 29 | + required: false |
| 30 | +runs: |
| 31 | + using: composite |
| 32 | + steps: |
| 33 | + - name: Prepare SSH |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + set -euo pipefail |
| 37 | + install -m 700 -d ~/.ssh |
| 38 | + printf '%s\n' "${{ inputs.remote_key }}" > ~/.ssh/id_ed25519 |
| 39 | + chmod 600 ~/.ssh/id_ed25519 |
| 40 | +
|
| 41 | + SSH_PORT="${{ inputs.remote_port }}" |
| 42 | + [[ -z "$SSH_PORT" ]] && SSH_PORT=22 |
| 43 | +
|
| 44 | + if [[ -n "${{ inputs.known_hosts }}" ]]; then |
| 45 | + printf '%s\n' "${{ inputs.known_hosts }}" > ~/.ssh/known_hosts |
| 46 | + else |
| 47 | + ssh-keyscan -p "$SSH_PORT" -H "${{ inputs.remote_host }}" >> ~/.ssh/known_hosts |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Rsync upload |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + set -euo pipefail |
| 54 | + SSH_PORT="${{ inputs.remote_port }}" |
| 55 | + [[ -z "$SSH_PORT" ]] && SSH_PORT=22 |
| 56 | + SSH_CMD="ssh -p ${SSH_PORT} -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=yes" |
| 57 | +
|
| 58 | + SRC="${{ inputs.path }}" |
| 59 | + DEST="${{ inputs.remote_path }}" |
| 60 | + USER="${{ inputs.remote_user }}" |
| 61 | + HOST="${{ inputs.remote_host }}" |
| 62 | +
|
| 63 | + # Ensure destination directory exists |
| 64 | + ${SSH_CMD} "${USER}@${HOST}" "mkdir -p '${DEST%/}'" |
| 65 | +
|
| 66 | + # Copy *contents* of SRC into DEST |
| 67 | + rsync ${{ inputs.switches }} \ |
| 68 | + -e "${SSH_CMD}" \ |
| 69 | + "${SRC%/}/" "${USER}@${HOST}:'${DEST%/}/'" |
0 commit comments