Skip to content

Commit

Permalink
GitHub Actions: fix Hugo - Add Theme
Browse files Browse the repository at this point in the history
- Prompt for theme name and user separately
    - Easier than having to extract the name from the URL
- Determine the latest Hugo version using GitHub API
- Update config file to use the new theme
- Add a commit
  • Loading branch information
booch committed Mar 4, 2024
1 parent 7b34fbb commit f66d3ff
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions .github/workflows/hugo-add-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ on:
# Run this workflow manually from the Actions tab.
workflow_dispatch:
inputs:
theme_url:
description: "URL of the theme to add"
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

Expand All @@ -20,26 +27,38 @@ defaults:
shell: bash

jobs:
gugo-add-theme:
hugo-add-theme:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.120.2
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
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/v${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_URL="${{ inputs.theme_url }}"
THEME_NAME="$(basename ${THEME_URL%.*})"
git submodule add "$THEME_URL" "themes/${THEME_NAME}"
git submodule update --init --recursive
- name: Add theme to config # TODO
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: |
echo "OK"
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 }}

0 comments on commit f66d3ff

Please sign in to comment.