TL;DR

GitHub ActionsでHugoを使ってbuildする際にextendが必要となった場合、GitHub Actionsのymlファイルにextend: trueを書くと解消します。

はじめに

HugoのレポジトリでPull Requestを作成した際やMergeされた際にGitHub Actionsでレポジトリに登録されたコードをHugoでbuildすることができます。 Hugoでsetup(GitHub ActionsでHugoを使えるようにする)、setupしたHugoでbuildが大きな流れになります。

本ページの参考に記載した各ウェブサイトにてHugoでのsetupを参考にさせていただきましたが、Hugo extendedの対応について書かれているところが管理人は見つからなかったので、このページでまとます(他に書いているところがあったらすみません)。

GitHub ActionsでのHugo deployの仕方

やりたかったことは下記のとおりです。

  1. Pull Request作成
  2. GitHub Actions開始
  3. Pull Requestを作ったレポジトリのブランチをチェックアウト(https://github.com/actions/checkout)
  4. Hugoをset up(https://github.com/peaceiris/actions-hugo)
  5. Hugoでbuild
  6. Firebaseでpreviewページをデプロイ(https://github.com/FirebaseExtended/action-hosting-deploy)

上記中で忘れがちなところは、3の最新のブランチのチェックアウトでsubmoduleもcheckoutすることとです。 これは他のサイトでも説明されています。 GitHub Actionsとしては下記のように記載します。

~略~
      - uses: actions/checkout@v2
        with:
          submodules: true
~略~

今回は、5.のHugo buildのところでエラーになりました。 GitHub Actionsで表示されたエラーは下記になります。

WARN XXXX/XX/XX XX:XX:XX Module "theme-name" is not compatible with this Hugo version; run "hugo mod graph" for more information.
Start building sites … 
hugo v0.91.2-1798BD3F linux/amd64 BuildDate=2021-12-23T15:33:34Z VendorInfo=gohugoio
Error: Error building site: TOCSS: failed to transform "scss/style.scss" (text/x-scss). Check your Hugo installation; you need the extended version to build SCSS/SASS.: this feature is not available in your current Hugo version, see https://goo.gl/YMrWcn for more information
Total in 1101 ms

エラーメッセージに記載されているリンク先はextendedを使うためにgoのコマンドでオプションを使いましょうと記載されているので今回のGitHub Actionsではここでは使えないかと思いますので注意です(もしかしたらGoからインストールすればできるかもしれませんが、Stepをできるだけ簡易化したかったので試みませんでした)。 そこでGitHub ActionsでHugoを参照しているrepositoryのREADMEを確認し、extendedをtrueにするとextendedが使えるようになるのでそちらを利用すれば上記のbuild時のエラーは解消されました。 extendedの記載の仕方は上記READMEにも記載ありますが、下記にも該当箇所を抜粋します。

~略~
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true
~略~

上記を利用することでHugo extendedを使う場合でもbuild errorが表示されず、無事buildができました。

参考

https://gohugo.io/troubleshooting/faq/#i-get-tocss--this-feature-is-not-available-in-your-current-hugo-version

https://sh0e1.com/posts/2020/10/29/ci-cd-using-github-actions-with-hugo-firebae-hosting/

https://masakagen.com/posts/tech/hugo-firebase-hosting/

https://dev.classmethod.jp/articles/github-actions-hugo-firebase/

https://github.com/peaceiris/actions-hugo