Blog updated: Hugo & GitHub Actions

Blog updated: Hugo & GitHub Actions

 25 Apr 2020 -  Giulio Vian -  ~2 Minutes

I wrote a while ago about Automating Hugo to publish a blog. In that post, I used Azure Pipelines (well, they had a different name at that time).

Today, after three years, I revised the solution and I am amazed by Hugo   progress. Many of my customisations and hacks I implemented are gone: Hugo batteries included philosophy is a true thing.

In addition to using the most recent version – 0.68.3, while I was stuck at 0.24.1 – I decided to move everything to GitHub. I am urged by two motives. One reason is to test GitHub Actions in this scenario – and it went extremely well. Another stimulus came from Get Latest Version   : we have a project requiring some publishing mechanism, a good excuse for reviewing publishing tools and web technology.

Publishing using GitHub Actions

Using GitHub Actions is very easy: just add a YAML file in the .github/workflows diractory of your GitHub repository. That’s all. Have to say a big thanks to Shohei Ueda aka peaceiris   for the great job in creating simple and effective Actions.

The whole script is less than 20 lines which I will comment later.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
on:
  push:
    branches:
      - master
jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.68.3'
          extended: true
      - name: Build
        run: hugo --minify --gc --destination ./public
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.PUBLISH_GIULIOV_GITHUB_IO }}
          external_repository: giuliov/giuliov.github.io
          publish_branch: master
          publish_dir: ./public

There are a few notable things about the highlighted lines. Line 11 (submodules: true) guarantees that the Hugo theme is downloaded as well; if you don’t all formatting disappears. Lines 15 and 16 pick the desired Hugo version. I recommend being very explicit as new versions appear fast and sometimes require to update the theme or adapt existing code.

To publish the Hugo generated site (lines 19 to 25), I opted for a separate repository. This is more complex than other techniques, like using the gh-pages branch in the same repository, but I feel safer for future changes.

Enough for today, catch you soon.

comments powered by Disqus