entrypoint.sh is committed with mode 0644 while action.yml runs it directly as `${{ github.action_path }}/entrypoint.sh`, so the action fails before the script starts with 'entrypoint.sh: Permission denied' and exitcode 126 — the SSH key is never read, which makes it look like an auth failure. Sets the exec bit, and also invokes via 'sh' so the action no longer depends on the mode bit surviving a checkout. Found while deploying fmartingr/fmartingr.com (FMG-7).
Reviewed-on: #1
Reviewed-by: Felipe M <me@fmartingr.com>
49 lines
1.1 KiB
Shell
Executable file
49 lines
1.1 KiB
Shell
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
if [ -z "$INPUT_HOST" ]; then
|
|
echo "Error: host is required"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$INPUT_USERNAME" ]; then
|
|
echo "Error: username is required"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$INPUT_KEY" ]; then
|
|
echo "Error: key is required"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$INPUT_TARGET" ]; then
|
|
echo "Error: target is required"
|
|
exit 1
|
|
fi
|
|
|
|
SSH_PORT="${INPUT_PORT:-22}"
|
|
SOURCE="${INPUT_SOURCE:-.}"
|
|
|
|
# ssh expands ~ from the passwd database rather than $HOME, so the two disagree
|
|
# whenever a container sets HOME elsewhere. Pass absolute paths instead.
|
|
SSH_DIR="$HOME/.ssh"
|
|
KEY_FILE="$SSH_DIR/deploy_key"
|
|
KNOWN_HOSTS="$SSH_DIR/known_hosts"
|
|
|
|
mkdir -p "$SSH_DIR"
|
|
chmod 700 "$SSH_DIR"
|
|
|
|
trap 'rm -f "$KEY_FILE"' EXIT
|
|
|
|
echo "$INPUT_KEY" > "$KEY_FILE"
|
|
chmod 600 "$KEY_FILE"
|
|
|
|
ssh-keyscan -p "$SSH_PORT" -H "$INPUT_HOST" >> "$KNOWN_HOSTS" 2>/dev/null
|
|
|
|
rsync -avz \
|
|
-e "ssh -i $KEY_FILE -o UserKnownHostsFile=$KNOWN_HOSTS -p $SSH_PORT -o ConnectTimeout=30" \
|
|
$INPUT_ARGS \
|
|
"${SOURCE}/" \
|
|
"${INPUT_USERNAME}@${INPUT_HOST}:${INPUT_TARGET}/"
|
|
|
|
echo "Deployed ${SOURCE} to ${INPUT_HOST}:${INPUT_TARGET}"
|