-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
110 lines (94 loc) · 3.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
.PHONY: build clean deploy release site watch
all: site
#############
# Variables #
#############
# Path to the directory that `stack` uses to install binaries locally.
STACK_LOCAL_INSTALL_PATH ?= $(shell stack path --local-install-root)
# Path to the `site` binary.
SITE_PROG_PATH = $(STACK_LOCAL_INSTALL_PATH)/site
# The current commit's git hash.
GIT_HASH = $(shell git rev-parse --short HEAD)
################################
## Targets for specific files ##
################################
# target for the `site` binary. This binary is used to actually create the
# html files.
$(SITE_PROG_PATH): src/site.hs
@echo "Building..."
@stack build
@echo "Built."
#####################
## General targets ##
#####################
# Build the `site` binary. The `site` binary is used to build the actual .html
# files for the site.
build: $(SITE_PROG_PATH)
# Clean all generated files.
clean:
@echo "Cleaning..."
-@stack exec -- site clean 2>/dev/null || true
@rm -rf .hakyll-cache/ generated-site/
@stack clean
@echo "Clean."
# Deploy the site.
# Commit the generated-site directory to the gh-pages git branch.
# The way this is done is pretty hacky, but it works.
deploy: site
# Make sure this temporary working directory is empty.
# (TODO: Really we should be using a directory with a random filename,
# generated with something like mktemp.)
rm -rf /tmp/haskell-jp-blog-deploy/
mkdir /tmp/haskell-jp-blog-deploy/
# Copy the generated site to the temp directory.
cp -r generated-site /tmp/haskell-jp-blog-deploy/
# Checkout the gh-pages branch.
ifdef GITHUB_TOKEN
git remote set-url origin "https://${GITHUB_TOKEN}@github.com/haskell-jp/blog.git"
git fetch origin gh-pages
git checkout -b gh-pages FETCH_HEAD
else
git checkout -t origin/gh-pages
endif
# Remove the pages for the current site.
git rm -r -f --ignore-unmatch *
git status
# Copy all of the generated site's files to the current directory.
cp -r /tmp/haskell-jp-blog-deploy/generated-site/* ./
# Disable Jekyll to serve files whose names begin with `_`.
# https://help.github.com/articles/files-that-start-with-an-underscore-are-missing/
touch ./.nojekyll
# Add everything back. (A lot of files probably won't change, so, for
# instance, they won't show up on 'git status' even though we just did 'git
# rm -rf *'. A 'git rm -rf FILE' followed by 'git add FILE' is a noop if
# the file hasn't changed.)
git add -A .
git status
# Do the commit and push.
@git diff --exit-code; \
rc=$?; if [ $rc != 0 ] ; then \
git commit -m "Release $(GIT_HASH) on `date`."; \
git push -f origin gh-pages; \
else \
echo "Skip commit and push to gh-pages"; \
fi
ifndef GITHUB_TOKEN
# Go back to master.
git checkout master
endif
rm -rf /tmp/haskell-jp-blog-deploy
# Alias for deploy.
release: deploy
# Generate the .html files for our blog.
site: $(SITE_PROG_PATH)
@# We don't actually need to use rebuild here, we could just use build.
@# If this blog becomes really big and produces tons of pages, then switching
@# to 'build' here (and adding an additional site-rebuild target) would be a
@# good idea.
stack exec -- site rebuild
test:
stack test
# Run a test webserver on http://0.0.0.0:8000 serving up the content of our
# blog. If the content changes, it is automatically rebuilt.
watch: $(SITE_PROG_PATH)
stack exec -- site watch --host 0.0.0.0