forked from SESYNC-ci/tidyverse-lesson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
81 lines (71 loc) · 2.93 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
SHELL := /bin/bash
.DEFAULT_GOAL := slides
# look up lesson number and slides in Jekyll _config.yml
LESSON := $(shell ruby -e "require 'yaml';puts YAML.load_file('docs/_config.yml')['lesson']")
SLIDES := $(shell ruby -e "require 'yaml';puts YAML.load_file('docs/_config.yml')['slide_sorter']")
SLIDES := $(SLIDES:%=docs/_slides/%.md)
# list available Markdown, RMarkdown and Pweave slides
SLIDES_MD := $(shell find . -path "./docs/_slides_md/*.md")
SLIDES_RMD := $(shell find . -path "./docs/_slides_Rmd/*.Rmd")
SLIDES_PMD := $(shell find . -path "./docs/_slides_pmd/*.md")
# look up files for trainees in Jekyll _config.yml
HANDOUTS := $(shell ruby -e "require 'yaml';puts YAML.load_file('docs/_config.yml')['handouts']")
# do not run rules in parallel
## because bin/build_slides.R (.py) runs over all .Rmd (.pmd) slides
.NOTPARALLEL:
.PHONY: course origin slides archive preview
# target to synchronize with GitHub
origin: | .git/refs/remotes/upstream
git pull
git fetch upstream master:upstream
git merge --no-edit upstream
git push
.git/refs/remotes/upstream:
git remote add upstream "[email protected]:sesync-ci/lesson-style.git"
git fetch upstream
git checkout -b upstream upstream/master
git checkout master
# target to just update docs/_slides
slides: $(SLIDES)
$(SLIDES): | docs/_slides
docs/_slides:
mkdir -p docs/_slides
## cannot use a pattern as the next three targets, because
## the targets are only a subset of docs/_slides/%.md and
## they have different recipes
$(subst _md,,$(SLIDES_MD)): docs/_slides/%: docs/_slides_md/%
cp $< $@
$(subst _Rmd,,$(SLIDES_RMD:.Rmd=.md)): docs/_slides/%.md: docs/_slides_Rmd/%.Rmd bin/build_slides.R
@bin/build_slides.R
$(subst _pmd,,$(SLIDES_PMD)): docs/_slides/%.md: docs/_slides_pmd/%.md
@bin/build_slides.py
# targets keep jekyll site up to date
preview: slides | docs/_site
export GEM_HOME=$(HOME)/.gem
SITE = $(shell find ./docs/ ! -name _site)
docs/_site: $(SITE) | docs/Gemfile.lock
pushd docs && bundle exec jekyll build --baseurl=/p/4000 && popd
touch docs/_site
docs/Gemfile.lock:
pushd docs && bundle install && popd
# target that brings this lesson into a course
## make target "course" is called within the handouts Makefile,
## assumed to be at ../../Makefile
course: origin slides $(addprefix ../../handouts/,$(HANDOUTS:worksheet%=worksheet-$(LESSON)%))
## copy lesson handouts to the ../../handouts/ directory
## while adding lesson numbers to worksheets
../../handouts/worksheet-$(LESSON)%: worksheet%
cp $< $@
../../handouts/%: %
mkdir -p $(dir $@)
cp -r $< $@
# target to archive a lesson
## call the archive target with a command line parameter for DATE
archive:
@curl -L "https://sesync-ci.github.io/$${PWD##*/}/course/archive.html" -o docs/_posts/$(DATE)-index.html
# target to create binary for GitHub release
release:
ln -s . handouts
if [ -f *.Rproj ]; then ln *.Rproj handouts.Rproj; fi
zip -FSr handouts handouts/handouts.Rproj $(addprefix handouts/,$(HANDOUTS))
rm -f handouts handouts.Rproj