Skip to content

Instantly share code, notes, and snippets.

@ryankurte
Created March 2, 2017 00:44
Show Gist options
  • Save ryankurte/13a9b53798bf4a488ff0ee42986157bb to your computer and use it in GitHub Desktop.
Save ryankurte/13a9b53798bf4a488ff0ee42986157bb to your computer and use it in GitHub Desktop.
Hugo static website generator helper makefile for github pages deployment
# A helper makefile for split master and gh-pages deployment with Hugo
# See https://gohugo.io/tutorials/github-pages-blog/#deployment-via-gh-pages-branch
# You must run:
# git checkout --orphan gh-pages
# git reset --hard
# git commit --allow-empty -m "Initializing gh-pages branch"
# git push upstream gh-pages
# git checkout master
# prior to using this makefile
BRANCH=gh-pages
BUILD_DIR=public
VERSION=$(shell git describe --dirty)
MESSAGE="Publishing $(VERSION) to gh-pages"
build:
@rm -rf $(BUILD_DIR)/*
hugo
publish: setup build
ifneq (,$(findstring dirty,$(VERSION)))
@echo "Working tree is dirty, please commit before publishing"
else
@echo "Adding files"
git -C $(BUILD_DIR) add -f --all
@echo "Creating commit"
git -C $(BUILD_DIR) commit -m $(MESSAGE)
@echo "Pushing new commit"
git -C $(BUILD_DIR) push origin $(BRANCH)
endif
setup:
@echo "Cleaning $(BUILD_DIR)"
@rm -rf $(BUILD_DIR)
@mkdir $(BUILD_DIR)
@git worktree prune -v
@rm -rf .git/worktrees/$(BUILD_DIR)
@echo "Adding worktree"
@git worktree add -B $(BRANCH) $(BUILD_DIR) origin/$(BRANCH)
@git worktree list
clean:
@rm -rf $(BUILD_DIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment