diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0f9802e..18fc9f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,4 +18,4 @@ jobs: ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} local_path: './action.yml' # 对应我们项目build的文件夹路径 remote_path: '/var/www/react-app/' - delete_remote_files: true \ No newline at end of file + # delete_remote_files: true \ No newline at end of file diff --git a/README.md b/README.md index 03a3d3d..74405f7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ `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) `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. `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 diff --git a/action.yml b/action.yml index 0e7a38a..d5d5cca 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,6 @@ inputs: remote_path: description: 'files will copy to under remote_path' required: true - default: / sftp_only: description: 'connection via sftp protocol only' required: false diff --git a/entrypoint.sh b/entrypoint.sh index 15822ae..186391c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,29 +7,34 @@ set -eu TEMP_SSH_PRIVATE_KEY_FILE='../private_key.pem' TEMP_SFTP_FILE='../sftp' +if [ -z "$6" ]; then + echo 'remote_path is empty' + exit 1 +fi + # keep string format printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE # avoid Permissions too open chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE 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 fi if test $7 = "true"; then echo "Connection via sftp protocol only, skip the command to create a directory" else - echo 'ssh start' + echo 'SSH Start' ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6 fi -echo 'sftp start' +echo 'SFTP Start' # create a temporary file containing sftp commands printf "%s" "put -r $5 $6" >$TEMP_SFTP_FILE #-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 -echo 'deploy success' +echo 'Deploy Success' exit 0