mirror of
https://gitee.com/jack_whh/SFTP-Deploy-Action.git
synced 2026-03-09 23:12:55 +08:00
1. require remote_path
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -18,4 +18,4 @@ jobs:
|
|||||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
local_path: './action.yml' # 对应我们项目build的文件夹路径
|
local_path: './action.yml' # 对应我们项目build的文件夹路径
|
||||||
remote_path: '/var/www/react-app/'
|
remote_path: '/var/www/react-app/'
|
||||||
delete_remote_files: true
|
# delete_remote_files: true
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
`port`| yes | 22 | Remote host port
|
`port`| yes | 22 | Remote host port
|
||||||
`ssh_private_key`| yes| | You can copy private key from your `ssh_private_key.pem` file, and save to`repo/settings/secrets`
|
`ssh_private_key`| yes| | You can copy private key from your `ssh_private_key.pem` file, and save to`repo/settings/secrets`
|
||||||
`local_path`| yes| ./* | `local_path` of you project, if you want put single file:use path like `./myfile`, if you want put directory: use path like `./static/*`, it will put all files under `static` directory. Default to `./*`(will put all files in your repo).
|
`local_path`| yes| ./* | `local_path` of you project, if you want put single file:use path like `./myfile`, if you want put directory: use path like `./static/*`, it will put all files under `static` directory. Default to `./*`(will put all files in your repo).
|
||||||
`remote_path`|yes|/| Remote path
|
`remote_path`|yes|| Remote path
|
||||||
`sftp_only`| no| | If your port only accepts the sftp protocol, set this option to `true`. However, please note that when this option is set to `true`, the remote folder will not be created automatically.
|
`sftp_only`| no| | If your port only accepts the sftp protocol, set this option to `true`. However, please note that when this option is set to `true`, the remote folder will not be created automatically.
|
||||||
`args` | no| | other args yor want to use of sftp, E.g.`-o ConnectTimeout=5`
|
`args` | no| | other args yor want to use of sftp, E.g.`-o ConnectTimeout=5`
|
||||||
`delete_remote_files` | no | false | Set `true` will delete all files in the remote path before upload. Please be `careful` set this to true
|
`delete_remote_files` | no | false | Set `true` will delete all files in the remote path before upload. Please be `careful` set this to true
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ inputs:
|
|||||||
remote_path:
|
remote_path:
|
||||||
description: 'files will copy to under remote_path'
|
description: 'files will copy to under remote_path'
|
||||||
required: true
|
required: true
|
||||||
default: /
|
|
||||||
sftp_only:
|
sftp_only:
|
||||||
description: 'connection via sftp protocol only'
|
description: 'connection via sftp protocol only'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -7,29 +7,34 @@ set -eu
|
|||||||
TEMP_SSH_PRIVATE_KEY_FILE='../private_key.pem'
|
TEMP_SSH_PRIVATE_KEY_FILE='../private_key.pem'
|
||||||
TEMP_SFTP_FILE='../sftp'
|
TEMP_SFTP_FILE='../sftp'
|
||||||
|
|
||||||
|
if [ -z "$6" ]; then
|
||||||
|
echo 'remote_path is empty'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# keep string format
|
# keep string format
|
||||||
printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE
|
printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE
|
||||||
# avoid Permissions too open
|
# avoid Permissions too open
|
||||||
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE
|
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE
|
||||||
|
|
||||||
if test $9 == "true";then
|
if test $9 == "true";then
|
||||||
echo 'start delete remote files'
|
echo 'Start delete remote files'
|
||||||
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 rm -rf $6
|
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 rm -rf $6
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test $7 = "true"; then
|
if test $7 = "true"; then
|
||||||
echo "Connection via sftp protocol only, skip the command to create a directory"
|
echo "Connection via sftp protocol only, skip the command to create a directory"
|
||||||
else
|
else
|
||||||
echo 'ssh start'
|
echo 'SSH Start'
|
||||||
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
|
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo 'sftp start'
|
echo 'SFTP Start'
|
||||||
# create a temporary file containing sftp commands
|
# create a temporary file containing sftp commands
|
||||||
printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE
|
printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE
|
||||||
#-o StrictHostKeyChecking=no avoid Host key verification failed.
|
#-o StrictHostKeyChecking=no avoid Host key verification failed.
|
||||||
sftp -b $TEMP_SFTP_FILE -P $3 $8 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2
|
sftp -b $TEMP_SFTP_FILE -P $3 $8 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2
|
||||||
|
|
||||||
echo 'deploy success'
|
echo 'Deploy Success'
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user