Compare commits

5 Commits

Author SHA1 Message Date
SamKirkland
9c4e4646b8 v2.0.0
SFTP support!
2019-10-08 00:26:19 -05:00
Sam Kirkland
67f266cff8 Merge pull request #13 from ctrleffive/patch-1
syntax highlighting types in README changed
2019-09-18 09:29:20 -05:00
Chandu J S
f8a41d35d1 syntax highlighting types changed
code example's language type in the file was wrong. changed from `shell` to `yml` and `json` to `workflow`
2019-09-18 17:28:39 +04:00
Sam Kirkland
8bbce4e262 Update README.md 2019-09-17 13:32:01 -05:00
Sam Kirkland
3e99626730 Update action.yml 2019-09-17 09:16:03 -05:00
4 changed files with 91 additions and 38 deletions

View File

@@ -10,7 +10,8 @@ LABEL "com.github.actions.description"="Deploy your website via FTP"
LABEL "com.github.actions.icon"="upload-cloud" LABEL "com.github.actions.icon"="upload-cloud"
LABEL "com.github.actions.color"="orange" LABEL "com.github.actions.color"="orange"
RUN apk add lftp RUN apk update
RUN apk add openssh sshpass lftp
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod 777 entrypoint.sh RUN chmod 777 entrypoint.sh

View File

@@ -5,7 +5,7 @@ Automate deploying websites and more with this GitHub action.
![Action](images/action-preview.gif) ![Action](images/action-preview.gif)
### Usage Example (Your_Project/.github/workflows/main.yml) ### Usage Example (Your_Project/.github/workflows/main.yml)
```shell ```yml
on: push on: push
name: Publish Website name: Publish Website
jobs: jobs:
@@ -15,10 +15,10 @@ jobs:
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: FTP-Deploy-Action - name: FTP-Deploy-Action
uses: SamKirkland/FTP-Deploy-Action@master uses: SamKirkland/FTP-Deploy-Action@2.0.0
env: env:
FTP_SERVER: ftp.samkirkland.com FTP_SERVER: ftp.samkirkland.com
FTP_USERNAME: ${{ secrets.FTP_USERNAME }} FTP_USERNAME: myFtpUserName
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
ARGS: --delete ARGS: --delete
# --delete arg will delete files on the server if you've deleted them in git # --delete arg will delete files on the server if you've deleted them in git
@@ -28,31 +28,34 @@ jobs:
2. Select the actions tab `(currently only for beta testers)` 2. Select the actions tab `(currently only for beta testers)`
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` 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`
4. Paste the above code into your file and save 4. Paste the above code into your file and save
7. Now you need to add a few keys to the `secrets` section in your project, the following are required at a minimum. To add a `secret` go to the `Settings` tab in your project then select `Secrets`. Add a new `Secret` for each of the following 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`
* FTP_SERVER
* FTP_USERNAME
* FTP_PASSWORD
* (see optional settings below)
### Settings ### Settings
To add a `secret` go to the `Settings` tab in your project then select `Secrets`. Add a new `Secret` for each of the following. Keys can be added directly to your .yml config file or referenced from your project `Secrets` storage.
I recommend you use a secrets to store your FTP_USERNAME and FTP_PASSWORD.
| Key Name | Required? | Example | Default | Description | 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.
| `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 |
| `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 `Commonly used ARGS` section below | N/A | Custom lftp arguments, this field is passed through directly into the lftp script. |
#### Commonly used ARGS | 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
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. 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 You can use as many arguments as you want, seperate them with a space
Below is an incomplete list of commonly used ARGS:
| Argument | Description | | Argument | Description |
|------------------------|------------------------------------------------------------------------------------------------------| |------------------------|------------------------------------------------------------------------------------------------------|
| `--verbose` | Outputs which files are being modified, useful for debugging |
| `--delete` | Delete files not present at the source | | `--delete` | Delete files not present at the source |
| `--transfer-all` | Transfer all files, even seemingly the same as the target site | | `--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 | | `--dry-run` | Ouputs files that will be modified without making any actual changes |
@@ -60,13 +63,16 @@ You can use as many arguments as you want, seperate them with a space
| `--exclude=File.txt` | Exclude matching files, you can add multiple `--exclude` | | `--exclude=File.txt` | Exclude matching files, you can add multiple `--exclude` |
| `--include-glob=*.zip` | Include matching files, you can add multiple `--include-glob` | | `--include-glob=*.zip` | Include matching files, you can add multiple `--include-glob` |
| `--exclude-glob=*.zip` | Exclude matching files, you can add multiple `--exclude-glob` | | `--exclude-glob=*.zip` | Exclude matching files, you can add multiple `--exclude-glob` |
| `--delete-excluded` | Deletes any items you've marked as excluded if they exist on the server |
| `--no-empty-dirs` | Don't create empty directories | | `--no-empty-dirs` | Don't create empty directories |
| `--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) |
## Common Examples ## Common Examples
### Build and Publish React/Angular/Vue/Node Website ### 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 Make sure you have an npm script named 'build'. This config should work for most node built websites
```shell ```yml
on: push on: push
name: Build and Publish Front End Framework Website name: Build and Publish Front End Framework Website
jobs: jobs:
@@ -90,18 +96,41 @@ jobs:
run: ls run: ls
- name: FTP-Deploy-Action - name: FTP-Deploy-Action
uses: SamKirkland/FTP-Deploy-Action@master uses: SamKirkland/FTP-Deploy-Action@2.0.0
env: env:
FTP_SERVER: ftp.samkirkland.com FTP_SERVER: ftp.samkirkland.com
FTP_USERNAME: ${{ secrets.FTP_USERNAME }} FTP_USERNAME: myFTPUsername
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
LOCAL_DIR: build LOCAL_DIR: build
ARGS: --delete ARGS: --delete
``` ```
## 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
```
### Log only dry run: Use this mode for testing ### 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 Ouputs a list of files that will be created/modified to sync your source without making any actual changes
```shell ```yml
on: push on: push
name: Publish Website Dry Run name: Publish Website Dry Run
jobs: jobs:
@@ -111,10 +140,10 @@ jobs:
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: FTP-Deploy-Action - name: FTP-Deploy-Action
uses: SamKirkland/FTP-Deploy-Action@master uses: SamKirkland/FTP-Deploy-Action@2.0.0
env: env:
FTP_SERVER: ftp.samkirkland.com FTP_SERVER: ftp.samkirkland.com
FTP_USERNAME: ${{ secrets.FTP_USERNAME }} FTP_USERNAME: myFTPUsername
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
ARGS: --delete --dry-run ARGS: --delete --dry-run
``` ```
@@ -126,13 +155,15 @@ jobs:
1. `rm: Access failed: 553 Prohibited file name: ./.ftpquota` 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 * The `.ftpquota` file is created by some FTP Servers and cannot be modified by the user
* **Fix:** Add `--exclude=.ftpquota` to your ARGS * **Fix:** Add `--exclude=.ftpquota` to your ARGS
2. How do I exclude .git files from the publish 2. How to exclude .git files from the publish
* **Fix:** Add `--exclude-glob=**/.git*/** --exclude-glob=**/.git**` to your ARGS * **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
#### Deprecated main.workflow config (used for beta/legacy apps that haven't been migrated to .yaml workflows yet) #### Deprecated main.workflow config (used for beta/legacy apps that haven't been migrated to .yaml workflows yet)
```json ```workflow
action "FTP-Deploy-Action" { action "FTP-Deploy-Action" {
uses = "SamKirkland/FTP-Deploy-Action@master" uses = "SamKirkland/FTP-Deploy-Action@1.0.0"
secrets = ["FTP_USERNAME", "FTP_PASSWORD", "FTP_SERVER"] secrets = ["FTP_USERNAME", "FTP_PASSWORD", "FTP_SERVER"]
} }
``` ```
@@ -154,7 +185,6 @@ action "FTP-Deploy-Action" {
#### ToDo #### ToDo
- SFTP example
- More examples - More examples
#### Pull Requests Welcome! #### Pull Requests Welcome!

View File

@@ -1,5 +1,5 @@
name: 'FTP Deploy' name: 'FTP Deploy'
description: 'Syncs files via FTP to a remote server' description: 'Syncs files via FTP/SFTP to a remote server'
inputs: inputs:
ftp_server: ftp_server:
description: 'FTP server name (you may need to specify a port)' description: 'FTP server name (you may need to specify a port)'
@@ -10,14 +10,22 @@ inputs:
ftp_password: ftp_password:
description: 'FTP account password' description: 'FTP account password'
required: true required: true
method:
description: 'Protocol used to deploy (ftp or sftp)'
required: false
default: "ftp"
port:
description: 'The port used to connect to server'
required: false
default: "21"
local_dir: local_dir:
description: 'The local folder to copy, defaults to root project folder' description: 'The local folder to copy, defaults to root project folder'
required: false required: false
default: '' default: ""
remote_dir: remote_dir:
description: 'The remote folder to copy to, deafults to root FTP folder (I recommend you configure this on your server side instead of here)' description: 'The remote folder to copy to, deafults to root FTP folder (I recommend you configure this on your server side instead of here)'
required: false required: false
default: '' default: ""
ARGS: ARGS:
description: 'Passes through options into lftp' description: 'Passes through options into lftp'
required: false required: false
@@ -29,8 +37,10 @@ runs:
- ${{ inputs.ftp_server }} - ${{ inputs.ftp_server }}
- ${{ inputs.ftp_username }} - ${{ inputs.ftp_username }}
- ${{ inputs.ftp_password }} - ${{ inputs.ftp_password }}
- ${{ inputs.method }}
- ${{ inputs.port }}
- ${{ inputs.local_dir }} - ${{ inputs.local_dir }}
- ${{ inputs.remote_dir }} - ${{ inputs.remote_dir }}
branding: branding:
icon: 'pload-cloud' icon: 'upload-cloud'
color: 'orange' color: 'orange'

View File

@@ -4,13 +4,25 @@
set -eu set -eu
echo "Starting FTP Deploy" echo "Starting FTP Deploy"
echo "Uploading files..."
WDEFAULT_LOCAL_DIR=${LOCAL_DIR:-"."} WDEFAULT_LOCAL_DIR=${LOCAL_DIR:-"."}
WDEFAULT_REMOTE_DIR=${REMOTE_DIR:-"."} WDEFAULT_REMOTE_DIR=${REMOTE_DIR:-"."}
WDEFAULT_ARGS=${ARGS:-""} WDEFAULT_ARGS=${ARGS:-""}
WDEFAULT_METHOD=${METHOD:-"ftp"}
lftp $FTP_SERVER -u $FTP_USERNAME,$FTP_PASSWORD -e "set ftp:ssl-allow no; mirror $WDEFAULT_ARGS -R $WDEFAULT_LOCAL_DIR $WDEFAULT_REMOTE_DIR; quit" if [ $WDEFAULT_METHOD = "sftp" ]; then
WDEFAULT_PORT=${PORT:-"22"}
echo "Establishing SFTP connection..."
sshpass -p $FTP_PASSWORD sftp -o StrictHostKeyChecking=no -P $WDEFAULT_PORT $FTP_USERNAME@$FTP_SERVER
echo "Connection established"
else
WDEFAULT_PORT=${PORT:-"21"}
fi;
echo "Using $WDEFAULT_METHOD to connect to port $WDEFAULT_PORT"
echo "Uploading files..."
lftp $WDEFAULT_METHOD://$FTP_SERVER:$WDEFAULT_PORT -u $FTP_USERNAME,$FTP_PASSWORD -e "set ftp:ssl-allow no; mirror $WDEFAULT_ARGS -R $WDEFAULT_LOCAL_DIR $WDEFAULT_REMOTE_DIR; quit"
echo "FTP Deploy Complete" echo "FTP Deploy Complete"
exit 0 exit 0