2019-09-15 23:56:38 -05:00
# FTP Deploy GitHub Action
2019-01-05 00:48:18 -06:00
Automate deploying websites and more with this GitHub action.
2019-09-15 23:56:38 -05:00

2019-01-05 00:48:18 -06:00
2019-09-15 23:56:38 -05:00
### Usage Example (Your_Project/.github/workflows/main.yml)
2019-09-18 17:28:39 +04:00
```yml
2019-08-29 00:21:07 -05:00
on : push
name : Publish Website
jobs :
2019-09-16 10:42:35 -05:00
FTP-Deploy-Action :
2019-08-29 00:21:07 -05:00
name : FTP-Deploy-Action
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@master
- name : FTP-Deploy-Action
2019-10-08 00:26:19 -05:00
uses : SamKirkland/FTP-Deploy-Action@2.0.0
2019-08-29 00:21:07 -05:00
env :
2019-09-15 23:56:38 -05:00
FTP_SERVER : ftp.samkirkland.com
2019-10-08 00:26:19 -05:00
FTP_USERNAME : myFtpUserName
2019-09-15 23:56:38 -05:00
FTP_PASSWORD : ${{ secrets.FTP_PASSWORD }}
ARGS : --delete
# --delete arg will delete files on the server if you've deleted them in git
2019-01-05 00:48:18 -06:00
```
1. Select the repository you want to add the action to
2019-11-10 01:15:05 +01:00
2. Select the actions tab
2019-08-31 17:11:09 -05:00
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`
2019-08-29 00:21:07 -05:00
4. Paste the above code into your file and save
2019-10-08 00:26:19 -05:00
7. 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`
2019-01-05 00:48:18 -06:00
### Settings
2019-10-08 00:26:19 -05:00
Keys can be added directly to your .yml config file or referenced from your project `Secrets` storage.
To add a `secret` go to the `Settings` tab in your project then select `Secrets` .
I recommend you store your FTP_PASSWORD as a secret.
| Key Name | Required? | Example | Default | Description |
|----------------|-----------|----------------------------|-----------------|----------------------------------------------------------|
| `FTP_SERVER` | Yes | ftp.samkirkland.com | N/A | FTP server name (you may need to specify a port) |
| `FTP_USERNAME` | Yes | git-action@samkirkland .com | N/A | FTP account username |
| `FTP_PASSWORD` | Yes | CrazyUniquePassword&%123 | N/A | FTP account password |
| `METHOD` | No | ftp | ftp | Protocol used to deploy (ftp or sftp) |
| `PORT` | No | 21 | ftp=21, sftp=22 | The port used to connect to server |
| `LOCAL_DIR` | No | build | . (root project folder) | The local folder to copy, defaults to root project folder. Do NOT include slashes for folders. |
| `REMOTE_DIR` | No | serverFolder | . (root FTP folder) | The remote folder to copy to, deafults to root FTP folder (I recommend you configure this on your server side instead of here). Do NOT include slashes for folders. |
| `ARGS` | No | See `ARGS` section below | N/A | Custom lftp arguments, this field is passed through directly into the lftp script. |
#### ARGS
2019-09-15 23:56:38 -05:00
Custom lftp arguments, this field is passed through directly into the lftp script. See [lftp's website ](https://lftp.yar.ru/lftp-man.html ) for all options.
You can use as many arguments as you want, seperate them with a space
2019-09-16 00:00:25 -05:00
2019-10-08 00:26:19 -05:00
Below is an incomplete list of commonly used ARGS:
2019-09-16 15:48:45 -05:00
| Argument | Description |
|------------------------|------------------------------------------------------------------------------------------------------|
2019-09-17 13:32:01 -05:00
| `--verbose` | Outputs which files are being modified, useful for debugging |
2019-09-16 15:48:45 -05:00
| `--delete` | Delete files not present at the source |
| `--transfer-all` | Transfer all files, even seemingly the same as the target site |
| `--dry-run` | Ouputs files that will be modified without making any actual changes |
| `--include=File.txt` | Include matching files, you can add multiple `--include` |
| `--exclude=File.txt` | Exclude matching files, you can add multiple `--exclude` |
| `--include-glob=*.zip` | Include matching files, you can add multiple `--include-glob` |
| `--exclude-glob=*.zip` | Exclude matching files, you can add multiple `--exclude-glob` |
2019-09-17 13:32:01 -05:00
| `--delete-excluded` | Deletes any items you've marked as excluded if they exist on the server |
2019-09-16 15:48:45 -05:00
| `--no-empty-dirs` | Don't create empty directories |
2019-09-17 13:32:01 -05:00
| `--parallel=X` | Uploads X files at a time in parallel |
| `-L` | Upload symbolic links as files (FTP doesn't have a way of creating actual symbolic links) |
2019-08-29 00:21:07 -05:00
## Common Examples
2019-09-15 23:56:38 -05:00
### Build and Publish React/Angular/Vue/Node Website
Make sure you have an npm script named 'build'. This config should work for most node built websites
2019-09-18 17:28:39 +04:00
```yml
2019-09-15 23:56:38 -05:00
on : push
name : Build and Publish Front End Framework Website
jobs :
2019-09-16 10:42:35 -05:00
FTP-Deploy-Action :
2019-09-15 23:56:38 -05:00
name : FTP-Deploy-Action
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@master
- name : Use Node.js 12.x
uses : actions/setup-node@v1
with :
node-version : '12.x'
- name : Build Project
run : |
npm install
npm run build --if-present
- name : List output files
run : ls
- name : FTP-Deploy-Action
2019-10-08 00:26:19 -05:00
uses : SamKirkland/FTP-Deploy-Action@2.0.0
2019-09-15 23:56:38 -05:00
env :
FTP_SERVER : ftp.samkirkland.com
2019-10-08 00:26:19 -05:00
FTP_USERNAME : myFTPUsername
2019-09-15 23:56:38 -05:00
FTP_PASSWORD : ${{ secrets.FTP_PASSWORD }}
LOCAL_DIR : build
ARGS : --delete
```
2019-01-05 00:48:18 -06:00
2019-10-08 00:26:19 -05:00
## SFTP Example
```yml
on : push
name : Publish Website over SFTP
jobs :
FTP-Deploy-Action :
name : FTP-Deploy-Action
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@master
- name : FTP-Deploy-Action
uses : SamKirkland/FTP-Deploy-Action@2.0.0
env :
FTP_SERVER : ftp.samkirkland.com
FTP_USERNAME : mySFTPUsername
FTP_PASSWORD : ${{ secrets.FTP_PASSWORD }}
METHOD : sftp
PORT : 7280
ARGS : --delete
```
2019-09-15 23:56:38 -05:00
### Log only dry run: Use this mode for testing
Ouputs a list of files that will be created/modified to sync your source without making any actual changes
2019-09-18 17:28:39 +04:00
```yml
2019-09-15 23:56:38 -05:00
on : push
name : Publish Website Dry Run
jobs :
2019-09-16 10:42:35 -05:00
FTP-Deploy-Action :
2019-09-15 23:56:38 -05:00
name : FTP-Deploy-Action
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@master
- name : FTP-Deploy-Action
2019-10-08 00:26:19 -05:00
uses : SamKirkland/FTP-Deploy-Action@2.0.0
2019-09-15 23:56:38 -05:00
env :
FTP_SERVER : ftp.samkirkland.com
2019-10-08 00:26:19 -05:00
FTP_USERNAME : myFTPUsername
2019-09-15 23:56:38 -05:00
FTP_PASSWORD : ${{ secrets.FTP_PASSWORD }}
ARGS : --delete --dry-run
```
2019-01-05 00:48:18 -06:00
2019-09-15 23:56:38 -05:00
##### Want another example? Let me know by creating a github issue
2019-01-05 00:48:18 -06:00
2019-09-15 23:56:38 -05:00
2019-09-16 00:55:22 -05:00
## FAQ
1. `rm: Access failed: 553 Prohibited file name: ./.ftpquota`
* The `.ftpquota` file is created by some FTP Servers and cannot be modified by the user
* **Fix:** Add `--exclude=.ftpquota` to your ARGS
2019-09-17 13:32:01 -05:00
2. How to exclude .git files from the publish
* **Fix:** Add `--exclude-glob=.git*/** --exclude-glob=.git**` to your ARGS
* Note: If you've already published these files you will need to manually delete them on the server or add the `--delete-excluded` option to ARGS
* Note: This will exclude all folders and files that start with `.git` no matter the folder they're in
2019-09-15 23:56:38 -05:00
#### Deprecated main.workflow config (used for beta/legacy apps that haven't been migrated to .yaml workflows yet)
2019-09-18 17:28:39 +04:00
```workflow
2019-08-29 00:21:07 -05:00
action "FTP-Deploy-Action" {
2019-10-08 00:26:19 -05:00
uses = "SamKirkland/FTP-Deploy-Action@1.0.0"
2019-08-29 00:21:07 -05:00
secrets = ["FTP_USERNAME", "FTP_PASSWORD", "FTP_SERVER"]
}
```
2019-01-05 00:48:18 -06:00
### Debugging locally
2019-09-15 23:56:38 -05:00
##### Instructions for debugging on windows
2019-01-05 00:48:18 -06:00
- Install docker for windows
- Open powershell
- Navigate to the repo folder
- Run `docker build --tag action .`
- (Optional) This step is only required when editing entrypoint.sh due to windows editors saving the file with windows line breaks instead of linux line breaks
- Download http://dos2unix.sourceforge.net/
- In another powershell window nagivate to the dos2unix folder /bin
- Run this command every time you modify entrypoint.sh `.\dos2unix.exe "{FULL_PATH_TO_REPO\entrypoint.sh}"`
- Run `docker run action`
2019-09-15 23:56:38 -05:00
##### Instructions for debugging on linux
2019-01-05 00:48:18 -06:00
- Please submit a PR for linux instructions :)
2019-09-15 23:56:38 -05:00
#### ToDo
- More examples
2019-01-05 00:48:18 -06:00
2019-09-15 23:56:38 -05:00
#### Pull Requests Welcome!