Skip to content
arrow-up-circle

GitHub Action

Update Hugo Version Pin in Netlify Config

v0.1.0 Latest version

Update Hugo Version Pin in Netlify Config

arrow-up-circle

Update Hugo Version Pin in Netlify Config

Update the version pin for Hugo in a netlify.toml file if needed.

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Update Hugo Version Pin in Netlify Config

uses: platenio/[email protected]

Learn more about this action in platenio/action-netlify-toml-update-hugo

Choose a version

Netlify TOML Update Hugo

A GitHub action for keeping the hugo version pins in netlify.toml up to date.

Sets up hugo-extended at the latest version and checks to see if the latest version is newer than the version(s) pinned in the Netlify TOML config, updating them.

Particularly useful when paired with the create-pull-request action to automatically submit a PR with the changes to the repository or as a step before building/testing a hugo site.

Usage

      - uses: actions/checkout@v2
      - name: Update Hugo Version for Netlify
        uses: platenio/action-netlify-toml-update-hugo@v1

You can also pin to a specific release version in the format @v1.2.3

Action Inputs

Name Description Default
no-install Specify to skip the hugo install step false
no-write Specify to skip writing the updated netlify.toml false
line-endings Whether to write LF or CRLF line endings in netlify.toml LF
netlify-toml-path Path to the netlify.toml config file from project root ./netlify.toml

Action Outputs

The following output can be used by subsequent workflow steps.

  • updatedConfig - Whether or not this action updated the netlify.toml config file
  • latestVersion - The latest version of hugo available if installed via this action

Action Behavior

The default behavior of this action is to install the latest version of hugo-extended, compare all version pins for Hugo in netlify.toml against that version, and update the netlify.toml config file to use the latest version.

Without Installing Hugo

If the no-install parameter is specified as true, it will skip installing hugo-extended and rely on the latest version of hugo installed by other means.

Without Writing the Config

If the no-write parameter is specified as true, it will skip writing the updated netlify.toml even if a newer version of Hugo is available than is pinned in the config.

With Specific Line Endings

If the line-endings parameter is specified as CRLF it will join the lines in the to-be-written netlify.toml file with a carriage return and new line instead of only a new line.

With Alternate Config Path

If the netlify-toml-path parameter is specified the action will look for an update that file instead of ./netlify.toml.

Reference Example

The following workflow explicates all of the parameters for reference purposes. Check the defaults to avoid setting inputs unnecessarily.

jobs:
  buildWithLatestHugo:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true
      - name: Update Hugo Version For Netlify
        id: update-hugo-version-netlify
        uses: platenio/action-netlify-toml-update-hugo@v1
        with:
          no-install: true
          no-write: true
          line-endings: CRLF
          netlify-toml-path: ./site/netlify.toml
      - name: Check Hugo Version Pins
        run: |
          "Latest Version: ${{ steps.update-hugo-version-netlify.outputs.latestVersion }}"
          "Updated Config? ${{ steps.update-hugo-version-netlify.outputs.updatedConfig }}"

Repository Update PR Example

The following workflow is an example of using this action to keep your hugo project repository's dependencies up to date on a schedule; it uses the create-pull-request action for the last step.

name: Update Hugo Netlify Toml

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

jobs:
  update_hugo_netlify:
    runs-on: windows-2019
    steps:
      - uses: actions/checkout@v2
      - name: Update Hugo Version for Netlify
        id: update-hugo-version-netlify
        uses: platenio/action-netlify-toml-update-hugo@v1
      - name: Create Pull Request
        id: createpr
        uses: peter-evans/create-pull-request@v3
        with:
          commit-message: (MAINT) Update Hugo version pin in Netlify TOML
          title: (MAINT) Update Hugo version pin in Netlify TOML
          body: |
            Updated Hugo version pin in netlify config file to: `${{ steps.update-hugo-version-netlify.outputs.latestVersion }}`

            Auto-generated by [create-pull-request][1] and [update-hugo-netlify-toml][1]

            [1]: https://github.com/peter-evans/create-pull-request
            [2]: https://github.com/platenio/action-update-hugo-netlify-toml
          branch: update-hugo-netlify-toml
          base: main
          delete-branch: true

License

MIT