Migrating Hugo Static Site Deployment from GitHub Actions to Forgejo Workflows
Initially created on
I moved from GitHub to the private.coffee Forgejo instance. You can now find my latest projects and repos at git.private.coffee/NE555. Porting my GitHub action to automatically build and deploy my static homepage using Hugo was a bit work.
Here’s the old GitHub action to build and then deploy my homepage using GitHub pages:
name: github pages
on:
push:
branches:
- master # Set a branch to deploy
pull_request:
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "latest"
# extended: true
- name: Clean public directory
run: rm -rf public
- name: Build
run: hugo --minify
- name: Create cname file
run: echo 'ne555.io' > public/CNAME
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
if: github.ref == 'refs/heads/master'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
And this is the new Forgejo workflow to build the site and then deploy it to Codeberg pages (coffeegit.page):
on:
push:
branches:
- main
jobs:
deploy:
runs-on: docker
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: setup Go
uses: actions/setup-go@v5
with:
go-version: "1.25.1"
- name: setup Hugo
uses: https://github.com/peaceiris/actions-hugo@v3
with:
hugo-version: "latest"
extended: false
- name: build site
run: hugo --minify
- name: set custom domain
run: "touch ./public/.domains && echo 'ne555.io' > ./public/.domains && echo 'www.ne555.io' >> ./public/.domains"
- name: deploy site
uses: https://github.com/peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: pages
publish_dir: ./public
In hindsight it was pretty much straight forward, however, this took a while to figure out, especially as Codeberg pages, Forgejo workflows and Forgejo are interconnected, but not the same thing and project. Their relationship to one another is not super clear at first.
The main things to change were:
- update the actions (while we are at it, why not)
- change from an Ubuntu image to
runs-on: docker
- change publishing branch (luckily paeaceiris action has you covered:
publish_branch: pages
(this is the default branch for Codeberg pages)
And that’s it. This site was served not by Microsoft servers, but by servers from private.coffee in Austria.