ssh: review ssh copy and run actions, add port variable

This commit is contained in:
alessandrovitali committed 2026-10-10 03:32:11 +02:00
1 parent b27762c0d3
commit 4878a62fb3
2 files changed
+41 -20

No files matched your search

+21 -11
View File
@@ -16,26 +16,36 @@ inputs:
target:
description: destination path on remote
required: true
port:
description: SSH port
required: false
default: "22"
runs:
using: "composite"
steps:
- name: setup ssh
shell: bash
env:
SSH_KEY: ${{ inputs.key }}
HOST: ${{ inputs.host }}
PORT: ${{ inputs.port }}
run: |
set -euo pipefail
mkdir -p ~/.ssh
echo "${{ inputs.key }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: add remote host to known_hosts
shell: bash
run: ssh-keyscan -H "${{ inputs.host }}" >> ~/.ssh/known_hosts
- name: install rsync
shell: bash
run: sudo apt-get update && sudo apt-get install -y rsync
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
- name: rsync directory
shell: bash
env:
SRC: ${{ inputs.source }}
HOST: ${{ inputs.host }}
USER: ${{ inputs.user }}
TARGET: ${{ inputs.target }}
PORT: ${{ inputs.port }}
run: |
rsync -rlptz --delete ${{ inputs.source }} ${{ inputs.user }}@${{ inputs.host }}:${{ inputs.target }}
set -euo pipefail
rsync -rlptz --delete -e "ssh -p $PORT" "$SRC" "$USER@$HOST:$TARGET"
+20 -9
View File
@@ -13,24 +13,35 @@ inputs:
script:
description: commands to run via SSH
required: true
port:
description: SSH port
required: false
default: "22"
runs:
using: "composite"
steps:
- name: setup ssh
shell: bash
env:
SSH_KEY: ${{ inputs.key }}
HOST: ${{ inputs.host }}
PORT: ${{ inputs.port }}
run: |
set -euo pipefail
mkdir -p ~/.ssh
echo "${{ inputs.key }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: add remote host to known_hosts
shell: bash
run: ssh-keyscan -H "${{ inputs.host }}" >> ~/.ssh/known_hosts
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
- name: run on docker host
shell: bash
env:
HOST: ${{ inputs.host }}
USER: ${{ inputs.user }}
PORT: ${{ inputs.port }}
SCRIPT: ${{ inputs.script }}
run: |
ssh ${{ inputs.user }}@${{ inputs.host }} << 'EOF'
${{ inputs.script }}
EOF
set -euo pipefail
ssh -p "$PORT" "$USER@$HOST" bash -s <<< "$SCRIPT"