forked from asterisk/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
203 lines (172 loc) · 6.38 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# NOTE: For readability, two space characters are used to
# indent the contents of make ifeq/ifneq statements.
# Don;y confuse these with tabs used to indent rule
# recipies.
#
SHELL := /usr/bin/bash
DEPLOY_BRANCH ?= gh-pages
BUILD_DIR ?= ./temp
GH=gh
JOB_DATE ?= $(shell date +%F)
include Makefile.inc
ifneq ($(BRANCH),)
-include Makefile.$(BRANCH).inc
endif
# 'make' has a realpath function but it only works on
# existing files and directories.
SITE_DIR ?= $(shell realpath $(BUILD_DIR)/site)
ifeq ($(NO_MINIFY),)
MINIFY_REGEX := /\#\s+-\s+minify:/,/^$$/ s/^\# / /g
else
MINIFY_REGEX := /\s+-\s+minify:/,/^$$/ s/^ /\# /g
endif
all:: build
branch-check:
@if [ -z "$(BRANCH)" ] ; then \
echo "You must supply 'BRANCH=<branch>' on the make command line" ;\
exit 1 ;\
fi
no-branch-check:
@if [ -n "$(BRANCH)" ] ; then \
echo "You can't specify a branch with the build or deploy targets" ;\
exit 1 ;\
fi
$(BUILD_DIR):
@echo "Creating $(BUILD_DIR)"
@mkdir -p $(BUILD_DIR)
ifneq ($(BRANCH),)
BRANCH_DIR := $(BUILD_DIR)/build-$(subst /,-,$(BRANCH))
$(BRANCH_DIR): $(BUILD_DIR)
@echo "Creating $(BRANCH_DIR)"
@mkdir -p $(BRANCH_DIR)
ifeq ($(findstring certified,$(BRANCH)),certified)
BRANCH_DOC_DIR := Certified-Asterisk_$(subst certified/,,$(BRANCH))_Documentation
else
BRANCH_DOC_DIR := Asterisk_$(BRANCH)_Documentation
endif
endif
$(BUILD_DIR)/mkdocs.yml: mkdocs.yml
@cp mkdocs.yml $(BUILD_DIR)/mkdocs.yml
static-setup:: $(BUILD_DIR) $(BUILD_DIR)/mkdocs.yml
@echo "Setting Up Static Documentation"
ifeq ($(NO_STATIC),)
@echo " Copying docs/ to temp build"
@rsync -vaH --delete-after docs/. $(BUILD_DIR)/docs/
else
@echo " Copying only docs/index.md and favicon.ico to temp build"
@mkdir -p $(BUILD_DIR)/docs
@cp docs/index.md docs/favicon.ico $(BUILD_DIR)/docs/
endif
@[ -L $(BUILD_DIR)/mkdocs.yml ] && rm $(BUILD_DIR)/mkdocs.yml || :
@cp mkdocs.yml $(BUILD_DIR)/mkdocs.yml
@[ -L $(BUILD_DIR)/overrides ] && rm $(BUILD_DIR)/overrides || :
@ln -sfr overrides $(BUILD_DIR)/overrides
@touch $(BUILD_DIR)/.site_built
$(BUILD_DIR)/.site_built:
@$(MAKE) --no-print-directory $(if $(NO_STATIC),NO_STATIC=yes,) static-setup
$(BUILD_DIR)/docs: $(BUILD_DIR)/.site_built
dynamic-setup:
@branches=$(BRANCHES) ;\
IFS=',' ;\
for branch in $${branches} ; do \
echo "Building branch $${branch}" ;\
$(MAKE) --no-print-directory BRANCH=$${branch} $(if $(NO_STATIC),NO_STATIC=yes,) dynamic-branch-setup ;\
done
dynamic-branch-setup: branch-check dynamic-core-setup $(if $(SKIP_ARI),,dynamic-ari-setup)
NEEDS_DOWNLOAD := no
ifneq ($(BRANCH),)
ifeq ($(findstring $(MAKECMDGOALS),clean static-setup serve deploy),)
ifeq ($(ASTERISK_XML_FILE),)
NEEDS_DOWNLOAD := yes
endif
ifeq ($(SKIP_ARI),)
ifeq ($(ASTERISK_ARI_DIR),)
NEEDS_DOWNLOAD := yes
endif
endif
endif
endif
ifeq ($(NEEDS_DOWNLOAD),yes)
$(info Finding last CreateDocs job)
LAST_JOB := $(shell $(GH) --repo asterisk/asterisk run list -w CreateDocs -s success --json databaseId,conclusion,updatedAt --created $(JOB_DATE) --jq '.[0].databaseId')
endif
ifneq ($(ASTERISK_XML_FILE),)
XML_PREREQ := $(ASTERISK_XML_FILE)
else
XML_PREREQ := download-from-job
ASTERISK_XML_FILE := $(BRANCH_DIR)/source/asterisk-docs.xml
endif
dynamic-core-setup: branch-check $(BUILD_DIR)/docs $(BRANCH_DIR) $(XML_PREREQ)
@echo "Setting Up Core Dynamic Documentation for branch '$(BRANCH)'"
@echo " Generating markdown from Asterisk XML"
@mkdir -p $(BUILD_DIR)/docs/$(BRANCH_DOC_DIR)
@utils/astxml2markdown.py --file=$(ASTERISK_XML_FILE) \
--xslt=utils/astxml2markdown.xslt \
--directory=$(BRANCH_DIR)/docs/ --branch=$(BRANCH) --version=GIT
@[ -L $(BUILD_DIR)/docs/$(BRANCH_DOC_DIR)/API_Documentation ] && \
rm $(BUILD_DIR)/docs/$(BRANCH_DOC_DIR)/API_Documentation || :
@ln -sfr $(BRANCH_DIR)/docs $(BUILD_DIR)/docs/$(BRANCH_DOC_DIR)/API_Documentation
ifneq ($(ASTERISK_ARI_DIR),)
ARI_PREREQ := $(ASTERISK_ARI_DIR)/_Asterisk_REST_Data_Models.md
else
ARI_PREREQ := download-from-job
ASTERISK_ARI_DIR := $(BRANCH_DIR)/source/
endif
dynamic-ari-setup: branch-check $(BUILD_DIR)/docs $(BRANCH_DIR) $(ARI_PREREQ)
@echo "Setting Up ARI Dynamic Documentation for branch '$(BRANCH)'"
@echo " Copying ARI markdown"
@mkdir -p $(BRANCH_DIR)/docs/Asterisk_REST_Interface
@rsync -aH $(ASTERISK_ARI_DIR)/*.md $(BRANCH_DIR)/docs/Asterisk_REST_Interface/
@cp overrides/.copy-in/ari.pages $(BRANCH_DIR)/docs/Asterisk_REST_Interface/.pages
@echo "# Asterisk REST Interface" > $(BRANCH_DIR)/docs/Asterisk_REST_Interface/index.md
download-from-job: $(BRANCH_DIR) branch-check
@if [ -z "$(LAST_JOB)" ] ; then \
echo "No current docs job" ;\
exit 1 ;\
fi
@echo "Retrieving documentation from job $(LAST_JOB) for branch: $(BRANCH)"
@[ -d $(BRANCH_DIR)/source ] && rm -rf $(BRANCH_DIR)/source || :
@mkdir -p $(BRANCH_DIR)/source
@$(GH) run download --repo asterisk/asterisk $(LAST_JOB) \
-n documentation-$(subst /,-,$(BRANCH)) -D $(BRANCH_DIR)/source
ifeq ($(BRANCH),)
build: static-setup dynamic-setup
@echo Building to $(SITE_DIR)
@[ ! -f $(BUILD_DIR)/mkdocs.yml ] && \
{ echo "Can't build. '$(BUILD_DIR)/mkdocs.yml' not found" ; exit 1 ; } || :
@sed -i -r -e "$(MINIFY_REGEX)" $(BUILD_DIR)/mkdocs.yml
@mkdocs build -f $(BUILD_DIR)/mkdocs.yml -d $(SITE_DIR)
else
build: BRANCH = $(BRANCH)
build: dynamic-branch-setup
@echo Building to $(SITE_DIR)
@[ ! -f $(BUILD_DIR)/mkdocs.yml ] && \
{ echo "Can't build. '$(BUILD_DIR)/mkdocs.yml' not found" ; exit 1 ; } || :
@sed -i -r -e "$(MINIFY_REGEX)" $(BUILD_DIR)/mkdocs.yml
@mkdocs build -f $(BUILD_DIR)/mkdocs.yml -d $(SITE_DIR)
endif
deploy: no-branch-check
@if [ -z "$(DEPLOY_REMOTE)" ] ; then \
echo "No DEPLOY_REMOTE was defined in Makefile.inc" ;\
exit 1 ;\
fi
@echo Deploying to remote '$(DEPLOY_REMOTE)'
@[ ! -f $(BUILD_DIR)/mkdocs.yml ] && \
{ echo "Can't deploy. '$(BUILD_DIR)/mkdocs.yml' not found" ; exit 1 ; } || :
@sed -i -r -e "$(MINIFY_REGEX)" $(BUILD_DIR)/mkdocs.yml
@mkdocs gh-deploy -r $(DEPLOY_REMOTE) -b $(DEPLOY_BRANCH) \
-d $(SITE_DIR) --no-history -f $(BUILD_DIR)/mkdocs.yml
serve:
@mkdocs serve -f $(BUILD_DIR)/mkdocs.yml $(SERVE_OPTS)
clean:
ifneq ($(BRANCH_DIR),)
@rm -rf $(BRANCH_DIR) || :
else
@rm -rf $(BUILD_DIR) || :
endif
siteclean:
@rm -rf $(SITE_DIR) || :
.PHONY: all clean siteclean branch-check no-branch-check \
static-setup dynamic-setup dynamic-branch-setup dynamic-core-setup dynamic-ari-setup \
download-from-job build deploy