Github -> hugo command -> serwer

I want to have something like this

  1. make some changes in code
    2*. git push to github
  2. then hugo extended will make ‘hugo’ command on FreeBSD server where i hosting my files

could you share on this forum your workflows?

Regards 2 - I dont need to executable ‘hugo’ command after every push to github, I could do it manually by ssh and ppreferably to do it by some maybe script

Right now everytime after ‘hugo’ command I need to upload almost 1,7 GB to my FreeBSD server via FileZilla - I want to make it on serwer and save some mobile data usage on my router :smile:

case: I also have two domains, so constains of one directory (from ‘public’ direcotry) with one language goes to other directory, other directory goes to other directory on serwer.

Propably generated so much data in Github WorkFlow will cost me something, I can do it on my own serwer FreeBSD

If I understand correctly you need to rsync your source files with GitHub Actions from GitHub to your server, then configure a hook on your FreeBSD server to run Hugo.
I think it would be simpler to configure Git on your FreeBSD server…

Here are two suggestions for your workflow:

1. GitHub Action

You can set up a GitHub Action to automatically build and deploy your Hugo site to your FreeBSD server whenever you push changes to your GitHub repository. Here are the basic steps:

  • Create a new file in your GitHub repository at .github/workflows/hugo.yml
  • Add the following contents to the file:
name: Build and deploy Hugo site

      - main

    runs-on: ubuntu-latest

    - uses: actions/checkout@v2
    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2.6.0
        hugo-version: '0.110.0'
    - name: Build
      run: hugo --minify
    - name: Deploy
      uses: appleboy/rsync-action@master
        args: -avz --delete
        src: public/
        dest: ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:/path/to/your/site
        RSYNC_PASSWORD: ${{ secrets.RSYNC_PASSWORD }}

This workflow will build your Hugo site whenever you push changes to the main branch of your GitHub repository, and then deploy the built site to your FreeBSD server using the rsync command. To use this workflow, you’ll need to set up two GitHub secrets:

  • SERVER_USER: The username you use to SSH into your FreeBSD server.
  • SERVER_IP: The IP address of your FreeBSD server.
  • RSYNC_PASSWORD: The password you use to authenticate with rsync on your FreeBSD server.

2. Rsync

If you prefer not to use GitHub Actions, you can use the rsync command directly to deploy your Hugo site to your FreeBSD server. Here’s an example command:

rsync -avz --delete public/ username@hostname:/path/to/your/site

Replace username, hostname, and /path/to/your/site with your own values. This command will copy the contents of the public/ directory (the built Hugo site) to the specified location on your FreeBSD server. You can run this command manually after you’ve pushed changes to your GitHub repository, or you can set up a cron job to run it automatically at regular intervals.

Note: Before implementing these codes in a production environment for your website, please make sure to perform proper testing as I have not tested them myself.

1 Like

It’s interesting what kind of your site were build more than 1 GB size files? Not sure the github will allow you to push the large files, it would reduce too much network traffic.

If there source code not much large you can try Sid’s suggest, I also use the way to push site to server. Here you can reference: hugo-next-docs/deploy-dev-site.yml

I’m trying to do essentially this, and the appleboy/rsync-action repo doesn’t exist – did you mean the appleboy/ssh-action repo, or is there a different user’s rsync action you recommend?

I don’t know what happened to appleboy/rsync-action. Later on, I discovered that there’s no need to use any 3rd party (other user’s) rsync action.

Take a look at the following article which tells how to do it using simple Linux commands.
Note: I didn’t write the article, but I found it to be a valuable resource.

Deploying to a server via SSH and Rsync in a Github Action | Zell Liew (