Use carpentries/lesson-docker for docker-serve make rule (#461)
[rnaseq-cwl-training.git] / Makefile
1 # Use /bin/bash instead of /bin/sh
2 export SHELL = /bin/bash
3
4 ## ========================================
5 ## Commands for both workshop and lesson websites.
6
7 # Settings
8 MAKEFILES=Makefile $(wildcard *.mk)
9 JEKYLL=bundle install --path .vendor/bundle && bundle update && bundle exec jekyll
10 PARSER=bin/markdown_ast.rb
11 DST=_site
12
13 # Check Python 3 is installed and determine if it's called via python3 or python
14 # (https://stackoverflow.com/a/4933395)
15 PYTHON3_EXE := $(shell which python3 2>/dev/null)
16 ifneq (, $(PYTHON3_EXE))
17   ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
18     PYTHON := python3
19   endif
20 endif
21
22 ifeq (,$(PYTHON))
23   PYTHON_EXE := $(shell which python 2>/dev/null)
24   ifneq (, $(PYTHON_EXE))
25     PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
26     PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
27     ifneq (3, ${PYTHON_VERSION_MAJOR})
28       $(error "Your system does not appear to have Python 3 installed.")
29     endif
30     PYTHON := python
31   else
32       $(error "Your system does not appear to have any Python installed.")
33   endif
34 endif
35
36
37 # Controls
38 .PHONY : commands clean files
39
40 # Default target
41 .DEFAULT_GOAL := commands
42
43 ## I. Commands for both workshop and lesson websites
44 ## =================================================
45
46 ## * serve            : render website and run a local server
47 serve : lesson-md
48         ${JEKYLL} serve
49
50 ## * site             : build website but do not run a server
51 site : lesson-md
52         ${JEKYLL} build
53
54 ## * docker-serve     : use Docker to serve the site
55 docker-serve :
56         docker pull carpentries/lesson-docker:latest
57         docker run --rm -it \
58                 -v $${PWD}:/home/rstudio \
59                 -p 4000:4000 \
60                 -p 8787:8787 \
61                 -e USERID=$$(id -u) \
62                 -e GROUPID=$$(id -g) \
63                 carpentries/lesson-docker:latest
64
65 ## * repo-check       : check repository settings
66 repo-check :
67         @${PYTHON} bin/repo_check.py -s .
68
69 ## * clean            : clean up junk files
70 clean :
71         @rm -rf ${DST}
72         @rm -rf .sass-cache
73         @rm -rf bin/__pycache__
74         @find . -name .DS_Store -exec rm {} \;
75         @find . -name '*~' -exec rm {} \;
76         @find . -name '*.pyc' -exec rm {} \;
77
78 ## * clean-rmd        : clean intermediate R files (that need to be committed to the repo)
79 clean-rmd :
80         @rm -rf ${RMD_DST}
81         @rm -rf fig/rmd-*
82
83
84 ##
85 ## II. Commands specific to workshop websites
86 ## =================================================
87
88 .PHONY : workshop-check
89
90 ## * workshop-check   : check workshop homepage
91 workshop-check :
92         @${PYTHON} bin/workshop_check.py .
93
94
95 ##
96 ## III. Commands specific to lesson websites
97 ## =================================================
98
99 .PHONY : lesson-check lesson-md lesson-files lesson-fixme
100
101 # RMarkdown files
102 RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
103 RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
104
105 # Lesson source files in the order they appear in the navigation menu.
106 MARKDOWN_SRC = \
107   index.md \
108   CODE_OF_CONDUCT.md \
109   setup.md \
110   $(sort $(wildcard _episodes/*.md)) \
111   reference.md \
112   $(sort $(wildcard _extras/*.md)) \
113   LICENSE.md
114
115 # Generated lesson files in the order they appear in the navigation menu.
116 HTML_DST = \
117   ${DST}/index.html \
118   ${DST}/conduct/index.html \
119   ${DST}/setup/index.html \
120   $(patsubst _episodes/%.md,${DST}/%/index.html,$(sort $(wildcard _episodes/*.md))) \
121   ${DST}/reference/index.html \
122   $(patsubst _extras/%.md,${DST}/%/index.html,$(sort $(wildcard _extras/*.md))) \
123   ${DST}/license/index.html
124
125 ## * lesson-md        : convert Rmarkdown files to markdown
126 lesson-md : ${RMD_DST}
127
128 _episodes/%.md: _episodes_rmd/%.Rmd
129         @bin/knit_lessons.sh $< $@
130
131 # * lesson-check     : validate lesson Markdown
132 lesson-check : lesson-fixme
133         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
134
135 ## * lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace
136 lesson-check-all :
137         @${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
138
139 ## * unittest         : run unit tests on checking tools
140 unittest :
141         @${PYTHON} bin/test_lesson_check.py
142
143 ## * lesson-files     : show expected names of generated files for debugging
144 lesson-files :
145         @echo 'RMD_SRC:' ${RMD_SRC}
146         @echo 'RMD_DST:' ${RMD_DST}
147         @echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
148         @echo 'HTML_DST:' ${HTML_DST}
149
150 ## * lesson-fixme     : show FIXME markers embedded in source files
151 lesson-fixme :
152         @fgrep -i -n FIXME ${MARKDOWN_SRC} || true
153
154 ##
155 ## IV. Auxililary (plumbing) commands
156 ## =================================================
157
158 ## * commands         : show all commands.
159 commands :
160         @sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)