DEV Community

S.M. Khalid Mahmud
S.M. Khalid Mahmud

Posted on

How to automatic deployment from GitHub to server via FTP (GitHub Actions)

We are going to take a look at how we can automate deployment from GitHub to server via FTP. To do that we have to create some folder and file in project root where .git folder exist. Such as:

Image description

Now, we need to add below code in server-deploy-via-ftp file, which we created before.

name: CI-FTP

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request event but only for the main branch
  push:
    branches: [ main ]
  #  pull_request:
  #    branches: [ main ]

  # Allows to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more job that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "FTP"
  deploy-via-ftp:
    runs-on: ubuntu-latest
    steps:
      # Checkouts repository under $GITHUB_WORKSPACE, so job can access it
      - uses: actions/checkout@v2

      - name: FTP Deploy
        uses: SamKirkland/FTP-Deploy-Action@4.3.2
        with:
          server: ${{ secrets.SERVER }}
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}

          # File will copy to under this path
          server-dir: ${{ secrets.SERVER_DIR }}
Enter fullscreen mode Exit fullscreen mode

Then we need to create some secrets on GitHub. For creating GitHub secrets, go to repository Settings, then click on Secrets from sidebar. Secrets are:

SERVER: Your server address
USERNAME: Your ftp username
PASSWORD: Your ftp password
SERVER_DIR: Where GitHub project will be uploaded
Enter fullscreen mode Exit fullscreen mode

Now push project on GitHub. And check status from Actions in repository.

Top comments (0)