Compare commits

..

11 commits

Author SHA1 Message Date
bd4da76485 allow auto extarct 2024-12-12 22:26:05 -06:00
408ca30608 fix rm when none 2024-12-12 22:16:06 -06:00
5160db3212 fix rm 2024-12-12 19:10:43 -06:00
7462fb0984 remove silence 2024-12-12 19:08:53 -06:00
ff8e07e7f2 Update entrypoint.sh 2024-12-12 11:14:19 -06:00
80286d41fa Merge branch 'master' of ssh://git.jackz.me:222/jackz/ssh-scp-deploy 2024-12-12 11:05:28 -06:00
7123b59216 fix port 2024-12-12 11:05:22 -06:00
d949eaab09 Update entrypoint.sh 2024-12-11 23:18:43 -06:00
d5370c265f Update entrypoint.sh 2024-12-11 22:56:26 -06:00
9a2701b513 Update entrypoint.sh 2024-12-11 22:43:18 -06:00
7a5f9c9bbd Update entrypoint.sh 2024-12-11 21:44:04 -06:00
2 changed files with 25 additions and 12 deletions

View file

@ -1,9 +1,9 @@
name: 'SCP deploy action'
name: 'SCP Deploy Smart'
description: 'Action to send dist files to a remote server with scp command'
author: 'Fabricio Nogueira'
author: 'Fabricio Nogueira & Jackz'
inputs:
src:
description: 'Sorce dir to deploy'
description: 'Source dir to deploy'
required: true
host:
description: 'SSH address'
@ -14,7 +14,7 @@ inputs:
port:
description: 'SSH Port'
required: false
default: 22
default: "22"
user:
description: 'SSH User name'
required: true
@ -24,6 +24,9 @@ inputs:
options:
description: 'Extra options for scp'
required: false
extract:
description: 'Is src a tar file to be extracted?'
required: false
runs:
using: 'docker'
image: 'Dockerfile'

View file

@ -1,6 +1,7 @@
#!/bin/sh -l
set -e
echo -e "${INPUT_KEY}" >__TEMP_INPUT_KEY_FILE
set -x
chmod 600 __TEMP_INPUT_KEY_FILE
@ -9,13 +10,22 @@ if [[ -z "$COMMIT_SHA" ]]; then
echo "COMMIT_SHA: Could not find file ${INPUT_SRC}/.git-commit"
exit 1
fi
echo "SSH Host: ${INPUT_USER}@${INPUT_HOST}:${INPUT_PORT}"
echo "Local Path: ${INPUT_SRC}"
echo "Remote Path: ${INPUT_REMOTE}"
echo "Commit: ${COMMIT_SHA}"
if [[ -z "$INPUT_EXTRACT"]]; then
# SCP normal files
scp -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE \
-P "${INPUT_PORT}" $INPUT_OPTIONS -r ${INPUT_SRC} "${INPUT_USER}"@"${INPUT_HOST}":"${INPUT_REMOTE}/${COMMIT_SHA}" 2>/dev/null
echo "File transfer complete."
echo "Symlinking, purging old"
echo "Running on ssh: ln -s ${INPUT_REMOTE}/${COMMIT_SHA} ${INPUT_REMOTE}/latest"
ssh -P "${INPUT_PORT}" "${INPUT_USER}"@"${INPUT_HOST}" \
-C "ln -s ${INPUT_REMOTE}/${COMMIT_SHA} ${INPUT_REMOTE}/latest && find . -mindepth 1 -maxdepth 1 -type d -not -path './latest' | tail -n +5 | rm -r"
-P "${INPUT_PORT}" $INPUT_OPTIONS -r ${INPUT_SRC} "${INPUT_USER}"@"${INPUT_HOST}":"${INPUT_REMOTE}/${COMMIT_SHA}"
elif
# Untar directly via SSh
ssh -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE \
"${INPUT_USER}"@"${INPUT_HOST}" -p "${INPUT_PORT}" \
-C "mkdir ${INPUT_REMOTE}/${COMMIT_SHA} && cd ${INPUT_REMOTE}/${COMMIT_SHA} && tar -xvv" < $INPUT_SRC
fi
echo "File transfer complete. Symlinking and purging old entries"
ssh -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE \
"${INPUT_USER}"@"${INPUT_HOST}" -p "${INPUT_PORT}" \
-C "ln -s ${INPUT_REMOTE}/${COMMIT_SHA} ${INPUT_REMOTE}/latest && find ${INPUT_REMOTE} -mindepth 1 -maxdepth 1 -type d -not -path './latest' | tail -n +5 | xargs --no-run-if-empty rm -r"