|
1 | | -# rsync-Deploy-Action |
| 1 | +<p align="center"> |
| 2 | + <img alt="web deploy - Continuous integration for everyone" src="images/web-deploy-logo-small.png"> |
| 3 | +</p> |
| 4 | + |
| 5 | +Automate deploying websites and more with this GitHub action |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +### Usage Example |
| 12 | +Place the following in `Your_Project/.github/workflows/main.yml` |
| 13 | +```yml |
| 14 | +on: push |
| 15 | +name: Publish Website |
| 16 | +jobs: |
| 17 | + web-deploy: |
| 18 | + name: 🚀 Deploy website every commit |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: 🚚 Get latest code |
| 22 | + uses: actions/checkout@v2.1.0 |
| 23 | + |
| 24 | + - name: 📂 Sync files |
| 25 | + uses: SamKirkland/web-deploy@1.0.0 |
| 26 | + with: |
| 27 | + target-server: samkirkland.com |
| 28 | + remote-user: myFtpUserName |
| 29 | + remote-key: ${{ secrets.SSH_KEY }} |
| 30 | +``` |
| 31 | +
|
| 32 | +--- |
| 33 | +
|
| 34 | +### Requirements |
| 35 | +- You must have shell access to your server, please read you webite hosts documentation |
| 36 | +- **You CANNOT use a FTP account - they are not the same!** |
| 37 | + - If you don't have SSH access but have ftp access use [FTP-Deploy-Action](https://github.com/SamKirkland/FTP-Deploy-Action) instead |
| 38 | +- You will need to create a **SSH** user to deploy. Normally this is your cpanel or hosting providers username and password |
| 39 | +- Most web hosts change the default port (22), check with your host for your port number |
| 40 | +
|
| 41 | +--- |
| 42 | +
|
| 43 | +### Setup Steps |
| 44 | +1. Select the repository you want to add the action to |
| 45 | +2. Select the `Actions` tab |
| 46 | +3. Select `Blank workflow file` or `Set up a workflow yourself`, if you don't see these options manually create a yaml file `Your_Project/.github/workflows/main.yml` |
| 47 | +4. Paste the example above into your yaml file and save |
| 48 | +5. Now you need to add a key to the `secrets` section in your project. To add a `secret` go to the `Settings` tab in your project then select `Secrets`. Add a new `Secret` for `ftp-password` |
| 49 | +6. Update your yaml file settings |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +### Settings |
| 54 | +Keys can be added directly to your .yml config file or referenced from your project `Secrets` storage. |
| 55 | + |
| 56 | +To add a `secret` go to the `Settings` tab in your project then select `Secrets`. |
| 57 | +I strongly recommend you store your `remote-key` as a secret. |
| 58 | + |
| 59 | +| Key Name | Required? | Example | Default | Description | |
| 60 | +|--------------------|-----------|-----------------------------------|---------|----------------------------------------------------------| |
| 61 | +| `target-server` | Yes | `ftp.samkirkland.com` | | Deployment destination server. Formatted as `domain.com:port`. Port is optional, when not specified it will default to 22 | |
| 62 | +| `remote-user` | Yes | `username@samkirkland.com` | | SSH user name | |
| 63 | +| `remote-key` | Yes | `CrazyUniquePassword&%123` | | SSH private key | |
| 64 | +| `source-path` | No | `./myFolderToPublish/` | `./` | Path to upload to on the server, must end with trailing slash `/` | |
| 65 | +| `destination-path` | No | `ftp.samkirkland.com` | `./` | Folder to upload from, must end with trailing slash `/` | |
| 66 | +| `rsync-options` | No | See `rsync-options` section below | `--archive --verbose --compress --human-readable --delete --exclude=.git* --exclude=.git/ --exclude=README.md --exclude=readme.md --exclude .gitignore` | Custom rsync arguments, this field is passed through directly into the rsync script | |
| 67 | + |
| 68 | +#### Advanced options using `rsync-options` |
| 69 | +Custom arguments, this field is passed through directly into the rsync script. See [rsync's manual](https://linux.die.net/man/1/rsync) for all options. |
| 70 | +You can use as many arguments as you want, seperate them with a space |
| 71 | + |
| 72 | +Below is an incomplete list of commonly used args: |
| 73 | + |
| 74 | +| Option | Description | |
| 75 | +|------------------------|------------------------------------------------------------------------------------------------------------------| |
| 76 | +| `--dry-run` | Does not upload or delete anything, but tells you what it would upload/delete if this was a real deploy | |
| 77 | +| `--stats` | Print verbose statistics on the file transfer, allowing you to tell how effective rsync’s delta-transfer algorithm is for your data | |
| 78 | +| `--links` | When symlinks are encountered, recreate the symlink on the destination | |
| 79 | +| `--compress` | Compresses the file data as it is sent to the destination machine, which reduces the amount of data being transmitted | |
| 80 | +| `--human-readable` | Output bytes in a more human-readable format (K, M, G) | |
| 81 | +| `--delete` | When you delete a file on github it will also be deleted on the server | |
| 82 | +| `--max-size '200K'` | Ignore syncing files over this limit. Value is a number followed by "K", "M", or "G" | |
| 83 | +| `--exclude 'file.txt'` | Excludes file(s) from the deployment. Supports glob pattterns (ex: `*.jpg`). You can have multiple excludes! | |
| 84 | +| `--include 'file.txt'` | Includes file(s) even if it was excluded. Supports glob pattterns (ex: `*.jpg`). You can have multiple includes! | |
| 85 | + |
| 86 | + |
| 87 | +# Common Examples |
| 88 | +#### Build and Publish React/Angular/Vue Website |
| 89 | +Make sure you have an npm script named 'build'. This config should work for most node built websites. |
| 90 | + |
| 91 | +```yml |
| 92 | +on: push |
| 93 | +name: Publish Website |
| 94 | +jobs: |
| 95 | + web-deploy: |
| 96 | + name: 🚀 Deploy website every commit |
| 97 | + runs-on: ubuntu-latest |
| 98 | + steps: |
| 99 | + - name: 🚚 Get latest code |
| 100 | + uses: actions/checkout@v2.1.0 |
| 101 | +
|
| 102 | + - name: Use Node.js 12.x |
| 103 | + uses: actions/setup-node@v1 |
| 104 | + with: |
| 105 | + node-version: '12.x' |
| 106 | + |
| 107 | + - name: 🔨 Build Project |
| 108 | + run: | |
| 109 | + npm install |
| 110 | + npm run build |
| 111 | + |
| 112 | + - name: 📂 Sync files |
| 113 | + uses: SamKirkland/web-deploy@1.0.0 |
| 114 | + with: |
| 115 | + target-server: samkirkland.com |
| 116 | + remote-user: myFtpUserName |
| 117 | + remote-key: ${{ secrets.SSH_KEY }} |
| 118 | +``` |
| 119 | + |
| 120 | +#### Log only dry run: Use this mode for testing |
| 121 | +Ouputs a list of files that will be created/modified to sync your source without making any actual changes |
| 122 | +```yml |
| 123 | +on: push |
| 124 | +name: Publish Website Dry Run |
| 125 | +jobs: |
| 126 | + web-deploy: |
| 127 | + name: 🚀 Deploy website every commit |
| 128 | + runs-on: ubuntu-latest |
| 129 | + steps: |
| 130 | + - name: 🚚 Get latest code |
| 131 | + uses: actions/checkout@v2.1.0 |
| 132 | +
|
| 133 | + - name: 📂 Sync files |
| 134 | + uses: SamKirkland/web-deploy@1.0.0 |
| 135 | + with: |
| 136 | + ftp-server: samkirkland.com |
| 137 | + ftp-username: myFTPUsername |
| 138 | + ftp-password: ${{ secrets.FTP_PASSWORD }} |
| 139 | + git-ftp-args: --dry-run |
| 140 | +``` |
| 141 | + |
| 142 | +_Want another example? Let me know by creating a [github issue](https://github.com/SamKirkland/web-deploy/issues/new)_ |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## FAQ |
| 147 | +<details> |
| 148 | + <summary>How to exclude .git files from the publish</summary> |
| 149 | + |
| 150 | +Git files are excluded by default |
| 151 | + |
| 152 | +If have customized `rsync-options` you will need to re-add the default exclude options using `--exclude=.git* --exclude=.git/ --exclude=README.md --exclude=readme.md --exclude=.gitignore` |
| 153 | +</details> |
| 154 | + |
| 155 | +<details> |
| 156 | + <summary>How to exclude a specific file or folder</summary> |
| 157 | + |
| 158 | +You can use `rsync-options` and pass in as many `--exclude` options as you want. By default this action excludes github files. If you choose to customize `rsync-options` make sure you copy over the defaults. |
| 159 | + |
| 160 | + |
| 161 | +Example excluding all `.jpg` files: |
| 162 | + |
| 163 | +`rsync-options: --exclude "*.jpg"` |
| 164 | + |
| 165 | + |
| 166 | +Example excluding a specific folder: |
| 167 | + |
| 168 | +`rsync-options: --exclude "wp-content/themes/"` |
| 169 | +</details> |
| 170 | + |
| 171 | + |
| 172 | +<details> |
| 173 | + <summary>How do I set a upload timeout?</summary> |
| 174 | + |
| 175 | +github has a built-in `timeout-minutes` option, see customized example below |
| 176 | + |
| 177 | +```yaml |
| 178 | +on: push |
| 179 | +name: Publish Website |
| 180 | +jobs: |
| 181 | + web-deploy: |
| 182 | + name: web-deploy |
| 183 | + runs-on: ubuntu-latest |
| 184 | + timeout-minutes: 15 # time out after 15 minutes (default is 360 minutes) |
| 185 | + steps: |
| 186 | + .... |
| 187 | +``` |
| 188 | +</details> |
| 189 | + |
| 190 | +--- |
| 191 | + |
| 192 | +## Common Errors |
| 193 | +<details id="ssl-peer-certificate"> |
| 194 | + <summary>Error: SSL peer certificate or SSH remote key was not OK</summary> |
| 195 | + |
| 196 | + Whitelist your host via the `known-hosts` configuration option or add the `--insecure` argument |
| 197 | +</details> |
| 198 | + |
| 199 | +--- |
| 200 | + |
| 201 | +## Debugging locally |
| 202 | +##### Instructions for debugging on windows |
| 203 | +- Install docker for windows |
| 204 | +- Open powershell |
| 205 | +- Navigate to the repo folder |
| 206 | +- Run `docker build --tag action .` |
| 207 | +- Run `docker run action` |
0 commit comments