|
1 | | -# SFTP Deploy action |
2 | 1 |
|
3 | | -> Use this action to deploy your files to server using `SSH Private Key` |
| 2 | +# SFTP Deploy Action |
4 | 3 |
|
5 | | -> 使用此`action`部署你的项目到服务器上,中文介绍链接:[使用Github Action 部署项目到云服务器](https://zhuanlan.zhihu.com/p/107545396) |
| 4 | +> Use this action to deploy your files to a server using `SSH Private Key` |
6 | 5 |
|
7 | | -## 1. Inputs |
| 6 | +> 使用此 `action` 部署你的项目到服务器上,中文介绍链接:[使用Github Action 部署项目到云服务器](https://zhuanlan.zhihu.com/p/107545396) |
8 | 7 |
|
9 | | -| Name | Required | Default | Description | |
10 | | -|------------------------|----------------------|---------|-----------------------------------------------| |
11 | | -`username` | yes| | SSH username |
12 | | -`server` | yes| | Remote host |
13 | | -`port`| yes | 22 | Remote host port |
14 | | -`ssh_private_key`| no| | You can copy private key from your `ssh_private_key` file, and save to`repo/settings/secrets` |
15 | | -`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). |
16 | | -`remote_path`|yes|| Remote path |
17 | | -`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. |
18 | | -<strike>args</strike> `sftpArgs` | no| | other args yor want to use of sftp, E.g.`-o ConnectTimeout=5` |
19 | | -`delete_remote_files` | no | false | Set to `true` will delete remote path folder and all files in it. |
20 | | -`password`| no| | SSH passsword,If a password is set, `ssh_private_key` is ignored. `for @v1.2.4 and greater` |
| 8 | +--- |
21 | 9 |
|
22 | | -> **Warning** |
| 10 | +## 🚀 **1. Inputs** |
23 | 11 |
|
24 | | -> Be careful when use `delete_remote_files`, This will delete remote path folder and all files in it |
| 12 | +| Name | Required | Default | Description | |
| 13 | +|------------------------|----------|---------|----------------------------------------------------------------------------------------------------------------------| |
| 14 | +| `username` | yes | | SSH username | |
| 15 | +| `server` | yes | | Remote host | |
| 16 | +| `port` | yes | 22 | Remote host port | |
| 17 | +| `ssh_private_key` | no | | You can copy the private key from your `ssh_private_key` file and save it to `repo/settings/secrets`<br>  | |
| 18 | +| `local_path` | yes | `./*` | Local path of your project. <br> - Single file: `./myfile` <br> - Directory: `./static/*` <br> Default: `./*` (will put all files in your repo). | |
| 19 | +| `remote_path` | yes | | The target folder on the remote server. | |
| 20 | +| `sftp_only` | no | | If your port only accepts the sftp protocol, set this option to `true`. However, when set to `true`, the remote folder won't be automatically created. | |
| 21 | +| `sftpArgs` | no | | Extra arguments you want to pass to `sftp`, for example: `-o ConnectTimeout=5` | |
| 22 | +| `delete_remote_files` | no | false | Set to `true` to delete the remote path folder and all files in it **before** uploading. | |
| 23 | +| `password` | no | | SSH password. If a password is set, `ssh_private_key` is ignored. *(for @v1.2.4 and greater)* | |
| 24 | +| `rsyncArgs` | no | | Additional arguments for the `rsync` command. You can customize file synchronization behavior, such as excluding files or directories. Example: `--exclude=node_modules --exclude=.git --exclude=*.log`. *(for @v1.2.5 and greater)* | |
25 | 25 |
|
26 | | ------ |
| 26 | +> ⚠️ **Warning:** |
| 27 | +> Be careful when using `delete_remote_files`. This will **permanently delete** the remote path folder and all files in it **before** uploading. |
27 | 28 |
|
28 | | -## 2.Action Examples |
| 29 | +--- |
| 30 | + |
| 31 | +## 📦 **2. Action Examples** |
| 32 | + |
| 33 | +### **🔹 Basic Example** |
29 | 34 |
|
30 | 35 | ```yaml |
31 | 36 | on: [push] |
32 | 37 |
|
33 | 38 | jobs: |
34 | | - deploy_job: |
| 39 | + deploy_job: |
35 | 40 | runs-on: ubuntu-latest |
36 | | - name: deploy |
| 41 | + name: Deploy Files |
37 | 42 | steps: |
38 | | - - name: Checkout |
| 43 | + - name: Checkout |
39 | 44 | uses: actions/checkout@v2 |
40 | | - - name: deploy file |
41 | | - uses: wlixcc/SFTP-Deploy-Action@v1.2.4 |
| 45 | + |
| 46 | + - name: Deploy to Server |
| 47 | + uses: wlixcc/SFTP-Deploy-Action@v1.2.5 |
42 | 48 | with: |
43 | | - username: 'root' |
44 | | - server: 'your server ip' |
45 | | - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
46 | | - local_path: './static/*' |
47 | | - remote_path: '/var/www/app' |
48 | | - sftpArgs: '-o ConnectTimeout=5' |
| 49 | + username: 'root' |
| 50 | + server: 'your server ip' |
| 51 | + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 52 | + local_path: './static/*' |
| 53 | + remote_path: '/var/www/app' |
| 54 | + sftpArgs: '-o ConnectTimeout=5' |
49 | 55 | ``` |
50 | 56 |
|
| 57 | +--- |
| 58 | +
|
| 59 | +### **🔹 Example with rsyncArgs** |
| 60 | +
|
51 | 61 | ```yaml |
52 | 62 | on: [push] |
53 | 63 |
|
54 | 64 | jobs: |
55 | | - deploy_job: |
| 65 | + deploy_job: |
56 | 66 | runs-on: ubuntu-latest |
57 | | - name: deploy |
| 67 | + name: Deploy with rsync exclude |
58 | 68 | steps: |
59 | | - - name: Checkout |
| 69 | + - name: Checkout |
60 | 70 | uses: actions/checkout@v2 |
61 | | - - name: Deploy file |
62 | | - uses: wlixcc/SFTP-Deploy-Action@v1.2.4 |
| 71 | + |
| 72 | + - name: Deploy with Exclude Patterns |
| 73 | + uses: wlixcc/SFTP-Deploy-Action@v1.2.5 |
63 | 74 | with: |
64 | | - username: ${{ secrets.FTP_USERNAME }} |
65 | | - server: ${{ secrets.FTP_SERVER }} |
66 | | - port: ${{ secrets.FTP_PORT }} |
67 | | - local_path: './static/*' |
68 | | - remote_path: '/var/www/app' |
69 | | - sftp_only: true |
70 | | - password: ${{ secrets.FTP_PASSWORD }} |
| 75 | + username: 'root' |
| 76 | + server: 'your server ip' |
| 77 | + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 78 | + local_path: './' |
| 79 | + remote_path: '/var/www/app' |
| 80 | + rsyncArgs: '--exclude=node_modules --exclude=.git --exclude=*.log' |
| 81 | + sftpArgs: '-o ConnectTimeout=5' |
71 | 82 | ``` |
72 | 83 |
|
73 | | -## 3. [Deploy React App Example](https://github.com/wlixcc/React-Deploy) |
| 84 | +--- |
74 | 85 |
|
| 86 | +### **🔹 Example with Password Authentication** |
75 | 87 |
|
76 | 88 | ```yaml |
77 | 89 | on: [push] |
78 | 90 |
|
79 | 91 | jobs: |
80 | | - deploy_job: |
| 92 | + deploy_job: |
81 | 93 | runs-on: ubuntu-latest |
82 | | - name: build&deploy |
| 94 | + name: Deploy with Password |
83 | 95 | steps: |
84 | | - # To use this repository's private action, you must check out the repository |
85 | | - - name: Checkout |
| 96 | + - name: Checkout |
86 | 97 | uses: actions/checkout@v2 |
87 | 98 |
|
88 | | - - name: Install Dependencies |
| 99 | + - name: Deploy with Password |
| 100 | + uses: wlixcc/SFTP-Deploy-Action@v1.2.5 |
| 101 | + with: |
| 102 | + username: ${{ secrets.FTP_USERNAME }} |
| 103 | + server: ${{ secrets.FTP_SERVER }} |
| 104 | + port: ${{ secrets.FTP_PORT }} |
| 105 | + local_path: './static/*' |
| 106 | + remote_path: '/var/www/app' |
| 107 | + sftp_only: true |
| 108 | + password: ${{ secrets.FTP_PASSWORD }} |
| 109 | +``` |
| 110 | +
|
| 111 | +--- |
| 112 | +
|
| 113 | +## 🌐 **3. [Deploy React App Example](https://github.com/wlixcc/React-Deploy)** |
| 114 | +
|
| 115 | +```yaml |
| 116 | +on: [push] |
| 117 | + |
| 118 | +jobs: |
| 119 | + deploy_job: |
| 120 | + runs-on: ubuntu-latest |
| 121 | + name: Build & Deploy React App |
| 122 | + steps: |
| 123 | + - name: Checkout |
| 124 | + uses: actions/checkout@v2 |
| 125 | + |
| 126 | + - name: Install Dependencies |
89 | 127 | run: yarn |
90 | | - - name: Build |
| 128 | + |
| 129 | + - name: Build |
91 | 130 | run: yarn build |
92 | 131 |
|
93 | | - - name: deploy file to server |
94 | | - uses: wlixcc/SFTP-Deploy-Action@v1.2.4 |
| 132 | + - name: Deploy Build Folder |
| 133 | + uses: wlixcc/SFTP-Deploy-Action@v1.2.5 |
95 | 134 | with: |
96 | | - username: 'root' |
97 | | - server: '${{ secrets.SERVER_IP }}' |
98 | | - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
99 | | - local_path: './build/*' |
100 | | - remote_path: '/var/www/react-app' |
101 | | - sftpArgs: '-o ConnectTimeout=5' |
| 135 | + username: 'root' |
| 136 | + server: '${{ secrets.SERVER_IP }}' |
| 137 | + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 138 | + local_path: './build/*' |
| 139 | + remote_path: '/var/www/react-app' |
| 140 | + rsyncArgs: '--exclude=*.map' |
| 141 | + sftpArgs: '-o ConnectTimeout=5' |
102 | 142 | ``` |
103 | 143 |
|
104 | | -  |
105 | | - |
106 | | - -------- |
| 144 | + |
| 145 | +
|
| 146 | +--- |
| 147 | +
|
| 148 | +## 🛡️ **4. Invalid format? You need to keep the format** |
| 149 | +
|
| 150 | +If you use the **Ed25519** algorithm to generate an SSH key pair: |
| 151 | +
|
| 152 | +```sh |
| 153 | +ssh-keygen -t ed25519 -C "your_email@example.com" |
| 154 | +``` |
| 155 | + |
| 156 | +⚠️ **Important:** |
| 157 | +The last line of the private key **must remain a blank line** when adding it to **Repository Secrets**. |
| 158 | +If you remove it, you might encounter an `invalid format` error. |
| 159 | + |
| 160 | + |
107 | 161 |
|
108 | | -## 4.Invalid format? You need keep format |
| 162 | +--- |
109 | 163 |
|
110 | | -If you use the Ed25519 algorithm to generate an SSH key pair `ssh-keygen -t ed25519 -C "your_email@example.com"`, |
111 | | -you need to note that the last line of the private key is a blank line. You need to keep this line when adding Repository secrets, otherwise it may lead to an `invalid format` error. |
112 | | -  |
113 | 164 |
|
114 | | - |
|
0 commit comments