1. require remote_path

This commit is contained in:
wl
2022-06-29 21:49:29 +08:00
parent 3586e619fa
commit 33436f92f1
4 changed files with 11 additions and 7 deletions

View File

@@ -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

View File

@@ -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`![](./resource/secret.jpg) `ssh_private_key`| yes| | You can copy private key from your `ssh_private_key.pem` file, and save to`repo/settings/secrets`![](./resource/secret.jpg)
`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

View File

@@ -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

View File

@@ -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