I have gone through several CI/CD solutions while using Forgejo (since it did not have it integrated for a long time) and most recently have this blog built and deployed using Woodpecker CI, which was fine if not amazing.

Since Forgejo now has Actions I wanted to redo it for that. I also moved my instance to a different host and had to setup a runner again. I encountered an issue with submodules in a workflow that I was sure worked before but at any rate had to fix that also.

I thought it might be worthwhile to share. Here’s my workflow (notes below):

name: publish

on:
  push:
    branches:
      - main

jobs:
  publish:
    runs-on: ubuntu-latest
    env:
      SSH_PRIVATE_KEY: ${{ secrets.SOME_SECRET_THAT_REPRESENTS_THE_PRIVATE_KEY }}
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0 # all history for all branches and tags\
          
      - uses: actions/cache@v3
        id: cache
        with:
          path: |
            ~/.cache/go-build
            ~/go
          key: ${{ runner.os }}-go-

      - uses: actions/setup-go@v4
        with:
          go-version: '>=1.21.0'

      - name: Install Hugo
        run: |
          go install -tags extended github.com/gohugoio/hugo@latest

      - uses: actions/cache@v3
        with:
          path: |
            ~/.cache/go-build
            ~/go
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-
            
      - name: Build
        run: |
          hugo --minify

      - name: Deploy
        run: |
          eval $(ssh-agent -s)
          echo "$SSH_PRIVATE_KEY" | ssh-add -
          apt update && apt install -y rsync
          mkdir ~/.ssh
          ssh-keyscan your-host.com  > ~/.ssh/known_hosts
          rsync -atv --progress ./public/ your-user@your-host.com:/home/your-user/your-content-directory/public

It’s pretty straightforward. Hugo was taking forever to install (a lot of Go modules) so after caching things improved dramatically. The deploy step is a little…. less polished than I would like but it works. It uses a secret for the private key and uses that when doing the rsync. After a quick search it seems like there is an rsync deployment action that I will have to investigate later.