mirror of
				https://github.com/SamKirkland/FTP-Deploy-Action.git
				synced 2025-10-31 19:33:59 +00:00 
			
		
		
		
	v2.0.0
SFTP support!
This commit is contained in:
		
							parent
							
								
									67f266cff8
								
							
						
					
					
						commit
						9c4e4646b8
					
				| @ -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.color"="orange" | ||||
| 
 | ||||
| RUN apk add lftp | ||||
| RUN apk update | ||||
| RUN apk add openssh sshpass lftp | ||||
| 
 | ||||
| COPY entrypoint.sh /entrypoint.sh | ||||
| RUN chmod 777 entrypoint.sh | ||||
|  | ||||
							
								
								
									
										72
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								README.md
									
									
									
									
									
								
							| @ -15,10 +15,10 @@ jobs: | ||||
|     steps: | ||||
|     - uses: actions/checkout@master | ||||
|     - name: FTP-Deploy-Action | ||||
|       uses: SamKirkland/FTP-Deploy-Action@master | ||||
|       uses: SamKirkland/FTP-Deploy-Action@2.0.0 | ||||
|       env: | ||||
|         FTP_SERVER: ftp.samkirkland.com | ||||
|         FTP_USERNAME: ${{ secrets.FTP_USERNAME }} | ||||
|         FTP_USERNAME: myFtpUserName | ||||
|         FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} | ||||
|         ARGS: --delete | ||||
|         # --delete arg will delete files on the server if you've deleted them in git | ||||
| @ -28,29 +28,31 @@ jobs: | ||||
| 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` | ||||
| 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 | ||||
|    * FTP_SERVER | ||||
|    * FTP_USERNAME | ||||
|    * FTP_PASSWORD | ||||
|    * (see optional settings below) | ||||
| 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` | ||||
| 
 | ||||
| ### 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. | ||||
| I recommend you use a secrets to store your FTP_USERNAME and FTP_PASSWORD. | ||||
| Keys can be added directly to your .yml config file or referenced from your project `Secrets` storage. | ||||
| 
 | ||||
| | 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 | | ||||
| | `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. | | ||||
| 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. | ||||
| 
 | ||||
| #### 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. | ||||
| 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                                                                                          | | ||||
| |------------------------|------------------------------------------------------------------------------------------------------| | ||||
| | `--verbose`            | Outputs which files are being modified, useful for debugging                                         | | ||||
| @ -94,15 +96,38 @@ jobs: | ||||
|       run: ls | ||||
|        | ||||
|     - name: FTP-Deploy-Action | ||||
|       uses: SamKirkland/FTP-Deploy-Action@master | ||||
|       uses: SamKirkland/FTP-Deploy-Action@2.0.0 | ||||
|       env: | ||||
|         FTP_SERVER: ftp.samkirkland.com | ||||
|         FTP_USERNAME: ${{ secrets.FTP_USERNAME }} | ||||
|         FTP_USERNAME: myFTPUsername | ||||
|         FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} | ||||
|         LOCAL_DIR: build | ||||
|         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 | ||||
| Ouputs a list of files that will be created/modified to sync your source without making any actual changes | ||||
| ```yml | ||||
| @ -115,10 +140,10 @@ jobs: | ||||
|     steps: | ||||
|     - uses: actions/checkout@master | ||||
|     - name: FTP-Deploy-Action | ||||
|       uses: SamKirkland/FTP-Deploy-Action@master | ||||
|       uses: SamKirkland/FTP-Deploy-Action@2.0.0 | ||||
|       env: | ||||
|         FTP_SERVER: ftp.samkirkland.com | ||||
|         FTP_USERNAME: ${{ secrets.FTP_USERNAME }} | ||||
|         FTP_USERNAME: myFTPUsername | ||||
|         FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} | ||||
|         ARGS: --delete --dry-run | ||||
| ``` | ||||
| @ -138,7 +163,7 @@ jobs: | ||||
| #### Deprecated main.workflow config (used for beta/legacy apps that haven't been migrated to .yaml workflows yet) | ||||
| ```workflow | ||||
| 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"] | ||||
| } | ||||
| ``` | ||||
| @ -160,7 +185,6 @@ action "FTP-Deploy-Action" { | ||||
| 
 | ||||
| 
 | ||||
| #### ToDo | ||||
| - SFTP example | ||||
| - More examples | ||||
| 
 | ||||
| #### Pull Requests Welcome! | ||||
|  | ||||
							
								
								
									
										16
									
								
								action.yml
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								action.yml
									
									
									
									
									
								
							| @ -1,5 +1,5 @@ | ||||
| name: 'FTP Deploy' | ||||
| description: 'Syncs files via FTP to a remote server' | ||||
| description: 'Syncs files via FTP/SFTP to a remote server' | ||||
| inputs: | ||||
|   ftp_server: | ||||
|     description: 'FTP server name (you may need to specify a port)' | ||||
| @ -10,14 +10,22 @@ inputs: | ||||
|   ftp_password: | ||||
|     description: 'FTP account password' | ||||
|     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: | ||||
|     description: 'The local folder to copy, defaults to root project folder' | ||||
|     required: false | ||||
|     default: '' | ||||
|     default: "" | ||||
|   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)' | ||||
|     required: false | ||||
|     default: '' | ||||
|     default: "" | ||||
|   ARGS: | ||||
|     description: 'Passes through options into lftp' | ||||
|     required: false | ||||
| @ -29,6 +37,8 @@ runs: | ||||
|     - ${{ inputs.ftp_server }} | ||||
|     - ${{ inputs.ftp_username }} | ||||
|     - ${{ inputs.ftp_password }} | ||||
|     - ${{ inputs.method }} | ||||
|     - ${{ inputs.port }} | ||||
|     - ${{ inputs.local_dir }} | ||||
|     - ${{ inputs.remote_dir }} | ||||
| branding: | ||||
|  | ||||
| @ -4,13 +4,25 @@ | ||||
| set -eu | ||||
| 
 | ||||
| echo "Starting FTP Deploy" | ||||
| echo "Uploading files..." | ||||
| 
 | ||||
| WDEFAULT_LOCAL_DIR=${LOCAL_DIR:-"."} | ||||
| WDEFAULT_REMOTE_DIR=${REMOTE_DIR:-"."} | ||||
| 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" | ||||
| exit 0 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user