Continuous Deployment Via FTP For Hugo Using GitHub Actions

After I migrated my website to Hugo, I needed a way to deploy the site to my host without manually FTPing files every time I make change. Netlify has support for static site hosting and continuous deployment, but I wasn’t looking to switch hosts. Previously I used AppVeyor to deploy, but this time I decided to use GitHub Actions to automate building and deploying the site whenever I push changes to master.

I utilized two actions from the GitHub Marketplace to setup the workflow:

I started by created a workflow .yml configuration file in .github/workflows. I’m triggering the workflow on git push to the master branch and also on a schedule using cron:

name: Deploy via FTP

    - master
    - cron:  '0 8 * * *' #every day at 8 am

Next I need to execute the following steps when the job is run:

  1. Checkout the latest version of the code
  2. Setup Hugo
  3. Build the site
  4. Deploy the artifacts to my host using FTP
    runs-on: ubuntu-latest

    - uses: actions/checkout@v1
        submodules: true

    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2
        hugo-version: 'latest'

    - name: Build site
      run: hugo --minify

    - name: FTP site
      uses: SamKirkland/FTP-Deploy-Action@3.0.0
        ftp-username: username
        ftp-password: ${{ secrets.FTP_PASSWORD }}
        local-dir: public/
        git-ftp-args: --insecure --all

There are two important things to note about the FTP options I’ve used:

  1. I used GitHub secrets to securely store my FTP password
  2. I had to set the --insecure argument so that Git-ftp doesn’t attempt to verify the certificate. Unfortunately this was the only way I could get it to connect to my host.

And that’s all there is to it! I now have a Hugo-based website that is automatically deployed to my webhost.