JavaScriptを有効にしてください

【Github】Github Actions を利用して Hugo のブログを自動ビルド & 自動コミット

 ·  ☕ 1 分で読めます

Github Actions を利用して自動コミット

Github Actions を利用して Hugo を利用している当ブログを自動ビルド & 自動コミットしてみた。

サンプルコード

Hugoを利用した当ブログを以下の yml を使用して自動的にビルド & コミットするようにしてみました。

 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
26
27
28
29
30
31
32
33
34
35
36
name: github pages

on: push

jobs:
  deploy:
    # Ubuntu
    runs-on: ubuntu-latest
    steps:
      # Checkout
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      # Setup Hugo
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.83.1'
          extended: true

      # Hugo Build
      - name: Build
        run: |
          cd ./blog
          rm -rf ../docs
          hugo --minify
          mv -fv ./public/ ../docs/          

      # Commit
      - name: Update Hugo
        uses: stefanzweifel/git-auto-commit-action@v4.2.0
        with:
          commit_message: Update Build Files

最初は戸惑いましたが使用感としてはとても楽。
Github Actions の実行やログもGithub上で確認できます。

参考

Github Actions

Hugo Github Actions

共有

こぴぺたん
著者
こぴぺたん
Copy & Paste Engineer