Skip to content

Hugo - Add Theme

Hugo - Add Theme #4

name: Hugo - Add Theme
# Original source: htts://github.com/boochtek/hugo-add-theme
# Original author: Craig Buchek (@booch) with help from ChatGPT.
on:
# Run this workflow manually from the Actions tab.
workflow_dispatch:
inputs:
theme_author:
description: "Theme Author (GitHub username)"
required: true
type: string
default: "gohugoio"
theme_name:
description: "Theme Name (Repository name)"
required: true
type: string
default: "hugoThemes"
# Set permissions of the GITHUB_TOKEN to allow pushing.
permissions:
contents: write
defaults:
run:
shell: bash
jobs:
hugo-add-theme:
runs-on: ubuntu-latest
steps:
- name: Install Hugo CLI
run: |
HUGO_LATEST_RELEASE_JSON=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest)
HUGO_VERSION=$(echo $HUGO_LATEST_RELEASE_JSON | jq -r '.tag_name')
HUGO_DEB_URL="https://github.com/gohugoio/hugo/releases/download/${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb"
wget -O "${{ runner.temp }}/hugo.deb" "$HUGO_DEB_URL" \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Add git submodule pointing at the theme
run: |
THEME_AUTHOR="${{ github.event.inputs.theme_author }}"
THEME_NAME="${{ github.event.inputs.theme_name }}"
git submodule add https://github.com/$THEME_AUTHOR/$THEME_NAME.git themes/$THEME_NAME
git submodule update --init --recursive
# NOTE: This assumes we're using the new default `hugo.toml` as our config file.
- name: Add theme to config
run: |
THEME_NAME="${{ github.event.inputs.theme_name }}"
CONFIG_FILE="hugo.toml"
sed -i "s/^theme = \".*\"/theme = \"$THEME_NAME\"/" $CONFIG_FILE
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
message: "Add Hugo theme: ${{ inputs.theme_name }}"