Add action.yml
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
name: 'SSH Upload'
|
||||
description: 'Upload files via SCP, automatically creating destination directories.'
|
||||
author: 'MegaMiley Studio'
|
||||
|
||||
inputs:
|
||||
host:
|
||||
description: 'SSH Host IP or Domain'
|
||||
required: true
|
||||
port:
|
||||
description: 'SSH Port (default: 22)'
|
||||
required: false
|
||||
default: '22'
|
||||
username:
|
||||
description: 'SSH Username'
|
||||
required: true
|
||||
private_key:
|
||||
description: 'SSH Private Key'
|
||||
required: true
|
||||
transfers:
|
||||
description: 'List of transfers formatted as "source_file(s) | remote_destination". One per line.'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Execute SSH/SCP Transfers
|
||||
shell: bash
|
||||
run: |
|
||||
# 1. Create a secure temporary file for the SSH key
|
||||
SSH_KEY_PATH=$(mktemp)
|
||||
cat << 'EOF' > "$SSH_KEY_PATH"
|
||||
${{ inputs.private_key }}
|
||||
EOF
|
||||
chmod 600 "$SSH_KEY_PATH"
|
||||
|
||||
# 2. Add Host to known_hosts to prevent verification prompts
|
||||
mkdir -p ~/.ssh
|
||||
ssh-keyscan -p ${{ inputs.port }} -H ${{ inputs.host }} >> ~/.ssh/known_hosts 2>/dev/null
|
||||
|
||||
# 3. Securely write transfers input to a file for parsing
|
||||
cat << 'EOF' > transfers.txt
|
||||
${{ inputs.transfers }}
|
||||
EOF
|
||||
|
||||
# 4. Loop through each line and execute commands
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
# Skip empty lines
|
||||
[[ -z "$(echo "$line" | tr -d '[:space:]')" ]] && continue
|
||||
|
||||
# Parse using the pipe | delimiter
|
||||
IFS='|' read -r src dest <<< "$line"
|
||||
|
||||
# Trim leading and trailing whitespace
|
||||
src=$(echo "$src" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
dest=$(echo "$dest" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
|
||||
if [ -n "$src" ] && [ -n "$dest" ]; then
|
||||
echo "::group::Transfer to $dest"
|
||||
|
||||
echo "Creating remote directory: $dest"
|
||||
ssh -i "$SSH_KEY_PATH" -p ${{ inputs.port }} ${{ inputs.username }}@${{ inputs.host }} "mkdir -p \"$dest\""
|
||||
|
||||
echo "Copying $src to $dest..."
|
||||
# Note: eval is used so wildcards or multiple space-separated files expand properly
|
||||
eval "scp -i \"$SSH_KEY_PATH\" -P ${{ inputs.port }} $src \"${{ inputs.username }}@${{ inputs.host }}:$dest/\""
|
||||
|
||||
echo "::endgroup::"
|
||||
fi
|
||||
done < transfers.txt
|
||||
|
||||
# 5. Cleanup
|
||||
rm -f "$SSH_KEY_PATH" transfers.txt
|
||||
Reference in New Issue
Block a user