2 minutes
Deploying a Hugo site in Github Pages with Github Actions (I hate CI!)
I passed 4 fours trying to setup CI to run Hugo + Github Actions, this is a test to see if it works
IT WORKED (2021-08-08 4:50pm)
It actually worked, now i can just commit and the blog will update alone, which is nice, since it worked i will write here how i did it
[Updated 2021-08-09]
First, if you dont know what is Hugo, its basically a static site generator made with Go. I choosed it because was simpler to setup and to get a theme, and also its fast, you can it check it page by here: https://gohugo.io.
There are a lot of themes there, you can find them here https://themes.gohugo.io/.
After choose or build the theme that you want and run it local, its time to deploy it, i choose Github Pages because its free. Well, now let’s go to the part the matters, in the Hugo website you will find a suggestion to create to github repositories, but i didnt that because i wanted to mainting just one repo, so what i did was actually create a branch that keeps all the source code, and other branch that just deploy the static files.
Here is the CI:
name: github pages
on:
push:
branches:
- source # Set a branch to deploy
pull_request:
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.ACESS_TOKEN }}
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: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
source
is branch that will hold our source code, and the branch that will be deployed will be gh-pages
that is created by the peaceiris/actions-gh-pages@v3
action, and thats it, its pretty simple actually, but it took me some time, so i decided to write about it.
Oh, remember to set the repo name to <yourusername>.github.io
so it can be considered a github pages repo by github
Quick note: If you want to use main or other name, you can setup it up in the Deploy step with
publish_brach: your_branch
, but if you dont use main as the branch to deployed, remember to change what branch should be deployed to Github Pages in Settings > Pages > Branch > Select the branch that holds the statics files
404 Words
2021-08-09 00:00 +0000