Deploy Jekyll site to GitHub Pages branch

March 5, 2020

Pushing code and letting GitHub build your Jekyll website is nice and simple. However, you’re limited to subset of plugins supported by GitHub, found here.

It’s easy enough to build your website locally or through a CI/CD pipeline. Here is a dead simple example using make.

TS      ?= $(shell date -u)
COMMIT  ?= $(shell git rev-parse --short HEAD)
JEKYLL  := bundle exec jekyll

DEPLOY_ORIGIN := $(shell git config remote.origin.url)
DEPLOY_BRANCH := gh-pages
DEPLOY_DIR    := _site

.PHONY: clean
clean:  ## Clean local compiled site.
	@$(JEKYLL) clean

.PHONY: deploy
deploy: clean  ## Build and deploy site.
	@(git clone -b $(DEPLOY_BRANCH) $(DEPLOY_ORIGIN) $(DEPLOY_DIR) && \
		JEKYLL_ENV=production $(JEKYLL) build && \
		cd $(DEPLOY_DIR) && \
		git add -A && \
		git commit -am "Deployed $(COMMIT) at $(TS)" && \
		git push origin $(DEPLOY_BRANCH))

Usage: $ make deploy.

Take a look at the gh-pages branch or the Makefile for this website as examples.

Return home