
.PHONY: dev hugo publish

dev: hugo
	hugo server --buildDrafts --verbose

hugo:
	@(which hugo &> /dev/null) || (echo "Hugo not installed. Please see https://gohugo.io/getting-started/installing/" && false)


ifeq ($(strip $(JENKINS_HOME)),)

publish:
	echo "Publishing only allowed from Jenkins."

else

PUBLISH_PATH=$(CURDIR)/public
BIN=$(CURDIR)/_bin
hugo := $(BIN)/hugo

publish: $(hugo)
	rm -rf $(PUBLISH_PATH)
	git clone git@git.xarth.tv:points/docs.git $(PUBLISH_PATH)
	$(hugo) -d $(PUBLISH_PATH)
	cd $(PUBLISH_PATH) && \
	  git checkout -b gh-pages && \
	  git add -A && \
	  git -c user.email=root@jenkins.internal.justin.tv -c user.name='Jenkins' \
	    commit -m "Publishing to gh-pages" && \
	  git push --force git@git.xarth.tv:points/docs.git gh-pages

$(hugo):
	mkdir -p $(BIN)
	wget -O $(BIN)/hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0.82.0/hugo_0.82.0_Linux-64bit.tar.gz
	cd $(BIN) && tar -xzf hugo.tar.gz

endif