Search code examples
githubbuildjekyllworkflowgithub-actions

How can I deploy Jekyll site from github repo to my ftp?


I have a custom Jekyll site which is working fine on local.

I would like to deploy my builded site to my hosting environment. Via FTP with github actions is working fine with this: https://github.com/SamKirkland/FTP-Deploy-Action

This is the FTP workflow:

on: push
name: Publish Website
jobs:
  FTP-Deploy-Action:
    name: FTP-Deploy-Action
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2.1.0
      with:
        fetch-depth: 2
    - name: FTP-Deploy-Action
      uses: SamKirkland/FTP-Deploy-Action@3.1.1
      with:
        ftp-server: ${{ secrets.FTP_HOST }}
        ftp-username: ${{ secrets.FTP_USER }}
        ftp-password: ${{ secrets.FTP_PASSWORD }}
        local-dir: _site
        git-ftp-args: --changed-only

I tried with the _site folder and and action is run with every commit when the _site is not ignored.

So the best, If I am not comitting the _site page, that will do the GitHub server. I found this action: https://github.com/marketplace/actions/jekyll-actions

My test workflow:

on: push
name: Testing the GitHub Pages building
    
jobs:
  jekyll:
    runs-on: ubuntu-16.04
    steps:
    - uses: actions/checkout@v2

    # Use GitHub Actions' cache to shorten build times and decrease load on servers
    - uses: actions/cache@v1
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-

    # Standard usage
    - uses:  humarci/jekyll-action@1.0.0
    
    # FTP maybe from here

Solution

  • This is what I currently use, which I found from The World According to Mike Blog.

    This uses ncftp which allows you to upload files via ftp easily.

    name: Build & Upload Site
    # Run on pushes to the master branch
    on: 
      push:
        branches:
          - master
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-ruby@v1
          with:
            ruby-version: '2.7'
        # Install the gems in the gemfile & install ncftp
        - name: Setup Environment.
          run: |
            bundle install
            sudo apt-get install -y ncftp
        
        # Build the site
        - name: Build Site with Jekyll.
          run: JEKYLL_ENV=production bundle exec jekyll build
        
        # Looks kind of complicated but just uploads the content of _site folder to the ftp server. It does not upload the _site folder itself.
        - name: Upload site to FTP.
          env: 
            ftp_location: ${{ secrets.FTP_LOCATION }} # Pass in required secrets.
            ftp_username: ${{ secrets.FTP_USERNAME }}
            ftp_password: ${{ secrets.FTP_PASSWORD }} 
          run: |
            ncftpput -R -v -u "$ftp_username" -p "$ftp_password" $ftp_location / _site/*