To ensure your site benefits from the most recent features and corrections, it’s crucial to keep it updated with the latest theme version. This article will guide you through the process of establishing a GitHub workflow that will automatically update the theme version. This action will perform daily checks for any updates to the theme. If an update is detected, it will generate a PR to update your site to the most recent theme version.

Setup Github Workflow

Now, create a theme-update.yml file in the .github/workflows folder of your repository with the following content:

name: "Theme Update"

on:
  schedule:
    - cron: "0 0 * * *"

jobs:
  update-theme:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: main

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: "latest"
          extended: true

      - name: Update hugo modules
        run: |
          # update to latest version of all modules
          hugo mod get -u

          # update the npm dependencies
          hugo mod npm pack

          # cleanup go.sum file
          hugo mod tidy          

      - name: Install node modules
        run: npm install

      - name: Build
        run: |
          # build the site
          hugo --minify
          # remove file generated by the build
          rm -rf public/          

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v7
        with:
          base: main
          title: Update theme
          labels: automerge

You’re good to go. From now on, this action will execute on a daily basis and generate a Pull Request if any updates to the theme are detected.