14 Commits
v1.0 ... v1.2.2

Author SHA1 Message Date
wl
c6e4d76ad9 Merge pull request #26 from leoppro/master
Add an option named `sftp_only` to connect via sftp only
2022-02-22 08:43:07 +08:00
leoppro
3a6bd36ae1 Add an option named sftp_only to connect via sftp only 2021-09-19 20:50:48 +08:00
wl
28d6168ebf 1. fix mkdir issue 2021-03-31 12:50:09 +08:00
wl
f19d10cf6b 1. fix mkdir issue 2021-03-31 12:06:37 +08:00
wl
cf8d9e5b50 Merge pull request #8 from stan-chen/fix-ssh-port
mkdir cannot connect non 22 port
2020-11-26 09:15:07 +08:00
StanleyChen
6ff9f12bc8 mkdir cannot connect non 22 port 2020-11-10 08:23:18 +08:00
wl
b2206dcb19 Merge pull request #4 from JulianGro/ssh_mkdir
Create directory if needed
2020-07-05 15:43:27 +08:00
wl
19ad014b34 Merge pull request #3 from JulianGro/readme
Fix first example in readme
2020-07-05 15:33:42 +08:00
Julian Groß
1f1ab26f78 remove "make sure dir exists" 2020-07-03 11:35:24 +02:00
Julian Groß
564673d595 disable StrictHostKeyChecking 2020-07-03 11:28:33 +02:00
Julian Groß
7fd32bff94 make directory when needed 2020-07-03 11:17:29 +02:00
motofckr9k
610ec6e1c9 Fix first example in readme 2020-07-03 03:36:27 +02:00
william
f1b3556b75 1. update readme 2020-02-18 22:57:55 +08:00
william
6b5c2a4271 1. update readme 2020-02-18 10:09:16 +08:00
6 changed files with 105 additions and 13 deletions

102
README.md
View File

@@ -4,37 +4,47 @@
> 使用此`action`部署你的项目到服务器上,`仅支持密钥对连接`
> [使用Github Action 部署项目到云服务器](https://zhuanlan.zhihu.com/p/107545396)
## Inputs
### `username`
> **Required** sftp username.
**Required** sftp username.
### `server`
> **Required** sftp server address.
**Required** sftp server address.
### `port`
> sftp srever port , default `22`.
sftp srever port , default `22`
### `ssh_private_key`
> **Required** you can copy private_key from your `ssh_private_key.pem file`, keep format, and save at`repo/settings/secrets`
**Required** you can copy private_key from your `ssh_private_key.pem file`, keep format, and save at`repo/settings/secrets`
![](./resource/secret.jpg)
### `local_path`
> **Required** `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).
**Required** `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`
> **Required** remote_path
**Required** remote_path
### `sftp_only`
connection via sftp protocol only, the default value is `false`. 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`
> args of sftp cmd, E.g.`-o ConnectTimeout=5`
args of sftp cmd, E.g.`-o ConnectTimeout=5`
## Example usage
## Action Example
on: [push]
@@ -47,11 +57,81 @@
- name: Checkout
uses: actions/checkout@v2
- name: deploy file
uses: ./ # Uses an action in the root directory
uses: wlixcc/SFTP-Deploy-Action@v1.0
with:
username: 'root'
server: 'your server ip'
private_key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
local_path: './static/*'
remote_path: '/var/www/app' #make sure dir exist
remote_path: '/var/www/app'
args: '-o ConnectTimeout=5'
## 1. [Deploy React App Example](https://github.com/wlixcc/React-Deploy)
> If you use nginx, all you need to do is upload the static files to the server after the project is built
on: [push]
jobs:
deploy_job:
runs-on: ubuntu-latest
name: build&deploy
steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
run: yarn
- name: Build
run: yarn build
- name: deploy file to server
uses: wlixcc/SFTP-Deploy-Action@v1.0
with:
username: 'root'
server: '${{ secrets.SERVER_IP }}'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
local_path: './build/*'
remote_path: '/var/www/react-app'
args: '-o ConnectTimeout=5'
![](./resource/reactExample.jpg)
## 2.Deploy Umi App Example (Ant Design Pro)
name: continuous deployment
on: [push]
jobs:
deploy_job:
runs-on: ubuntu-latest
name: build&deploy
steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Install umi
run: yarn global add umi
- name: Install Dependencies
run: yarn
- name: Build
run: yarn build
- name: deploy file to server
uses: wlixcc/SFTP-Deploy-Action@v1.0
with:
username: 'root'
server: '${{ secrets.SERVER_IP }}'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
local_path: './dist/*'
remote_path: '/var/www/umiapp'
args: '-o ConnectTimeout=5'
![](./resource/umiExample.jpg)

View File

@@ -23,6 +23,10 @@ inputs:
description: 'files will copy to under remote_path'
required: true
default: /
sftp_only:
description: 'connection via sftp protocol only'
required: false
default: false
args:
description: 'sftp args'
@@ -39,6 +43,7 @@ runs:
- ${{ inputs.ssh_private_key }}
- ${{ inputs.local_path }}
- ${{ inputs.remote_path }}
- ${{ inputs.sftp_only }}
- ${{ inputs.args }}
branding:

View File

@@ -12,12 +12,19 @@ printf "%s" "$4" >$TEMP_SSH_PRIVATE_KEY_FILE
# avoid Permissions too open
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE
echo 'sftp start'
if test $7 = "true"; then
echo "Connection via sftp protocol only, skip the command to create a directory"
else
echo 'ssh start'
ssh -o StrictHostKeyChecking=no -p $3 -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$2 mkdir -p $6
fi
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 $7 -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'
exit 0

BIN
resource/reactExample.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
resource/secret.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

BIN
resource/umiExample.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB