-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
235 lines (189 loc) · 6.16 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
.DELETE_ON_ERROR:
.SUFFIXES:
.SECONDARY:
# environment variables
.EXPORT_ALL_VARIABLES:
include config.public.mk
RUN = poetry run
# List all schema files matching oscem_schemas_*.yaml in the schema directory
SCHEMA_FILES := $(wildcard src/oscem_schemas/schema/oscem_schemas_*.yaml)
# Extract schema names without the directory and extension
SCHEMA_NAMES := $(notdir $(basename $(SCHEMA_FILES)))
SCHEMA_NAMES := $(patsubst oscem_schemas_%,%,$(SCHEMA_NAMES))
SRC = src
DEST = project
DOCDIR = docs
EXAMPLEDIR = examples
SITE = site
PERMDOCS = perm_docs
CONFIG_YAML =
ifdef LINKML_GENERATORS_CONFIG_YAML
CONFIG_YAML = ${LINKML_GENERATORS_CONFIG_YAML}
endif
GEN_DOC_ARGS =
ifdef LINKML_GENERATORS_DOC_ARGS
GEN_DOC_ARGS = ${LINKML_GENERATORS_DOC_ARGS}
endif
# basename of a YAML file in model/
.PHONY: setup gen-project git-init-add git-init git-add git-commit git-status
# note: "help" MUST be the first target in the file,
# when the user types "make" they should get help info
help: status
@echo ""
@echo "make setup -- initial setup (run this first)"
@echo "make site -- makes site locally"
@echo "make install -- install dependencies"
@echo "make test -- runs tests"
@echo "make lint -- perform linting"
@echo "make testdoc -- builds docs and runs local test server"
@echo "make deploy -- deploys site"
@echo "make update -- updates linkml version"
@echo "make help -- show this help"
@echo ""
status: check-config
@echo "Project: $(SCHEMA_NAME)"
@echo "Source: $(SOURCE_SCHEMA_PATH)"
check-config:
ifndef LINKML_SCHEMA_NAME
$(error **Project not configured**:\n\n - See '.env.public'\n\n)
else
$(info Ok)
endif
# generate products and add everything to github
setup: check-config git-init install gen-project gen-examples gendoc git-add git-commit
# install any dependencies required for building
install:
poetry install
.PHONY: install
# ---
# Project Synchronization
# ---
#
# check we are up to date
check: cruft-check
cruft-check:
cruft check
cruft-diff:
cruft diff
update: update-template update-linkml
update-template:
cruft update
# todo: consider pinning to template
update-linkml:
poetry add -D linkml@latest
# Generate code for all schemas
.PHONY: gen-project
gen-project: $(SCHEMA_NAMES:%=gen-project-%)
gen-project-%:
@echo "Generating code for schema $*"
mkdir -p $(DEST)/$*
$(RUN) gen-project $(CONFIG_YAML) -d $(DEST)/$* src/oscem_schemas/schema/oscem_schemas_$*.yaml
# Generate documentation for all schemas
.PHONY: gendoc
gendoc: $(SCHEMA_NAMES:%=gendoc-%)
gendoc-%:
@echo "Generating documentation for schema $*"
mkdir -p $(DOCDIR)/$*
cp -rf $(SRC)/docs/files/* $(DOCDIR)/$*
$(RUN) gen-doc $(GEN_DOC_ARGS) -d $(DOCDIR)/$* src/oscem_schemas/schema/oscem_schemas_$*.yaml
cp $(PERMDOCS)/* $(DOCDIR)/
# Generate examples for all schemas
.PHONY: gen-examples
gen-examples: $(SCHEMA_NAMES:%=gen-examples-%)
gen-examples-%:
@echo "Copying examples for schema $*"
mkdir -p $(EXAMPLEDIR)
cp -r src/data/examples/example_valid_$*.yaml $(EXAMPLEDIR)/example_valid_$*.yaml 2>/dev/null || true
# Run tests for all schemas
test-python: $(SCHEMA_NAMES:%=test-%)
test-lint: $(SCHEMA_NAMES:%=lint-%)
test-examples: $(SCHEMA_NAMES:%=examples-%)
test: test-lint test-examples
.PHONY: test test-lint test-examples
test-%:
@echo "Running tests for schema $*"
@if [ -f tests/test_$*.py ]; then \
$(RUN) pytest tests/test_$*.py; \
else \
echo "No tests found for schema $*"; \
fi
lint-%:
@echo "Running lint for schema $*"
$(RUN) linkml-lint --validate --all --ignore-warnings src/oscem_schemas/schema/oscem_schemas_$*.yaml; \
examples-%:
@echo "Validating examples against schema $*"
@if [ -f src/data/examples/example_valid_$*.yaml ]; then \
$(RUN) linkml-validate -s src/oscem_schemas/schema/oscem_schemas_$*.yaml src/data/examples/example_valid_$*.yaml ; \
else \
echo "No example found"; \
fi
## $(RUN) python -m unittest discover; \
prepare-mkdocs: $(SCHEMA_NAMES:%=prepare-mkdocs-%)
# two options, see which works better: 1 project/$*/$(DOCDIR) 2 $(DOCDIR)/$*
prepare-mkdocs-%:
@echo "Preparing MkDocs configuration for schema $*"
@mkdir -p $(DOCDIR)/$*
@echo "site_name: 'OSC-EM_$*_Documentation'" > $(DOCDIR)/$*/mkdocs.yml
@echo "theme:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " name: material" >> $(DOCDIR)/$*/mkdocs.yml
@echo " features:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - content.tabs.link" >> $(DOCDIR)/$*/mkdocs.yml
@echo "plugins:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - search" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - mermaid2" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - mermaid2:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " version: 10.9.0" >> $(DOCDIR)/$*/mkdocs.yml
@echo "docs_dir: '.'" >> $(DOCDIR)/$*/mkdocs.yml
@echo "site_dir: ../../$(SITE)/$*" >> $(DOCDIR)/$*/mkdocs.yml
@echo "nav:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - Home: index.md" >> $(DOCDIR)/$*/mkdocs.yml
@echo "site_url: https://osc-em.github.io/OSCEM-schemas_$*" >> $(DOCDIR)/$*/mkdocs.yml
@echo "repo_url: https://github.com/osc-em/OSCEM_Schemas" >> $(DOCDIR)/$*/mkdocs.yml
# Build Independent MkDocs Sites
mkdocs-build:
prepare-mkdocs $(SCHEMA_NAMES:%=build-%)
build-test-%:
@echo "Building site for $*"
$(RUN) mkdocs build -f $(DOCDIR)/$*/mkdocs.yml
# $(DOCDIR)/$*/
#-d $(SITE)/$*
build:
@echo "Building site for $*"
$(RUN) mkdocs build -f mkdocs.yml
# Serve a Specific Schema Locally
serve-test-%:
@echo "Serving site for $*"
$(RUN) mkdocs serve -f $(DOCDIR)/$*/mkdocs.yml -a 0.0.0.0:8000
serve:
$(RUN) mkdocs serve -f mkdocs.yml -a 0.0.0.0:8000
# Serve All Schemas Simultaneously
serve-all: $(SCHEMA_NAMES:%=serve-%)
.PHONY: serve prepare-mkdocs mkdocs-build serve-all serve-test build-test
MKDOCS = $(RUN) mkdocs
mkd-%:
$(MKDOCS) $*
mkdocs-deploy: $(MKDOCS) gh-deploy
git-init-add: git-init git-add git-commit git-status
git-init:
git init
git-add: .cruft.json
git add .
git-commit:
git commit -m 'chore: make setup was run' -a
git-status:
git status
# Clean generated files
.PHONY: clean
clean:
rm -rf $(DEST)/*
rm -rf $(DOCDIR)/* $(SITE)/*
rm -rf $(EXAMPLEDIR)/*
# rm -f mkdocs.yml
# Default target
.PHONY: all
all: gen-project gen-examples gendoc test
deploy: all mkdocs-deploy