From 4878a62fb313918a2c7f4259d12b0e95239deede Mon Sep 17 00:00:00 2001 From: alessandrovitali Date: Sat, 10 Oct 2026 03:32:11 +0200 Subject: [PATCH] ssh: review ssh copy and run actions, add port variable --- ssh-copy/action.yml | 32 +++++++++++++++++++++----------- ssh-run/action.yml | 29 ++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ssh-copy/action.yml b/ssh-copy/action.yml index 0fd57e9..8767e46 100644 --- a/ssh-copy/action.yml +++ b/ssh-copy/action.yml @@ -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" diff --git a/ssh-run/action.yml b/ssh-run/action.yml index df18ee9..3be1c1c 100644 --- a/ssh-run/action.yml +++ b/ssh-run/action.yml @@ -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"