-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
122 lines (99 loc) · 3.12 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
.PHONY: all clean
.DEFAULT_GOAL:=all
MAKEFILE:=$(abspath $(lastword $(MAKEFILE_LIST)))
MAKEDIR:=$(dir $(MAKEFILE))
ROOT:=$(patsubst %/,%,$(MAKEDIR))
TESTDRIVE_DIR=$(MAKEDIR)/src
OBJ:=$(ROOT)/obj
vpath
EXT_ADOC:=$(foreach adoc,$(ADOC),$(OBJ)/ext/$(notdir $(adoc)))
vpath %.adoc $(foreach adoc,$(ADOC),$(dir $(adoc)))
EXT_PNG:=$(foreach png,$(PNG),$(OBJ)/images/$(notdir $(png)))
vpath %.png $(foreach png,$(PNG),$(dir $(png)))
BUILDER:=podman
IMAGE:=quay.io/redhat-cop/ubi8-asciidoctor:v2.1
LANGUAGE:=en_US
ifndef CONFIG
$(error CONFIG must be supplied with the filename of your test report JSON config)
endif
REPORT_DATETIME:=$(shell date -u -Iseconds)
REPORT_DATE:=$(shell date -u -I)
GIT_HASH:=$(shell jq -r .githash "$(CONFIG)" | cut -c -8)
TITLE:=$(shell jq -r .title "$(CONFIG)")
SUBTITLE:=$(shell jq -r .subtitle "$(CONFIG)")
SUBJECT:=$(TITLE): $(SUBTITLE)
DESCRIPTION:=$(SUBTITLE)
ADOC_ATTRIBUTES:=$(foreach attribute,$(ATTRIBUTES),--attribute="$(attribute)")
ifdef TIMESTAMP_FILENAME
PDF:=$(OBJ)/test-report_$(shell echo $(REPORT_DATETIME) | sed -e s/://g -e s/-//g -e s/+0000/Z/).pdf
else
PDF:=$(OBJ)/test-report.pdf
endif
ADOC_PDF:=\
asciidoctor-pdf \
-r asciidoctor-diagram \
--failure-level=WARN \
--attribute=lang="$(LANGUAGE)" \
--attribute=reportdatetime="$(REPORT_DATETIME)" \
--attribute=reportdate="$(REPORT_DATE)" \
--attribute=githash="$(GIT_HASH)" \
--attribute=subject="$(SUBJECT)" \
--attribute=description="$(DESCRIPTION)" \
--attribute=revdate="$(date +'%Y-%m-%d')" \
$(ADOC_ATTRIBUTES)
define this-user-id =
$(shell id -u)
endef
define build-pdf-podman =
podman run --rm --name asciidoctor \
--user="$(this-user-id)" \
--userns=keep-id \
-v "$(shell dirname $@):/documents:Z" \
-w "/documents" \
$(IMAGE) \
$(ADOC_PDF) -o "$(shell basename $@)" "$(shell basename $<)"
endef
define build-pdf-docker =
docker run --rm --name asciidoctor \
--user "$(this-user-id)" \
-v "$(shell dirname $@):/documents:Z" \
-w "/documents" \
$(IMAGE) \
$(ADOC_PDF) -o "$(shell basename $@)" "$(shell basename $<)"
endef
define build-pdf-native =
$(ADOC_PDF) -o "$@" "$<"
endef
$(OBJ):
@echo +++++ preparing $@ +++++
mkdir -p $@
for DIRNAME in src pdf-assets vars; do cp -r $(ROOT)/$${DIRNAME} $(OBJ)/; done
@echo
$(OBJ)/ext: | $(OBJ)
@echo +++++ preparing $@ +++++
mkdir -p $@
@echo
$(OBJ)/ext/%.adoc: %.adoc | $(OBJ)/ext
@echo +++++ staging $@ +++++
cp $< $@
@echo
$(OBJ)/images/%.png: %.png | $(OBJ)
@echo +++++ staging $@ +++++
cp $< $@
@echo
$(OBJ)/test-report.adoc: $(EXT_ADOC) $(EXT_PNG) $(CONFIG) $(JUNIT) | $(OBJ) $(OBJ)/ext
@echo +++++ generating $@ +++++
echo 'include::src/test-report-head.adoc[]' >$@
echo >>$@
for ADOC in $(EXT_ADOC); do printf 'include::ext/%s[]\n\n' "$$(basename "$$ADOC")"; done >>$@
env PYTHONPATH=$(TESTDRIVE_DIR) python3 -m testdrive.asciidoc $(shell dirname $@) $(CONFIG) $(JUNIT) >>$@
echo >>$@
echo 'include::src/test-report-tail.adoc[]' >>$@
@echo
$(PDF): $(OBJ)/test-report.adoc $(CONFIG)
@echo +++++ building $@ using builder $(BUILDER) +++++
$(build-pdf-$(BUILDER))
@echo
all: $(PDF)
clean:
@rm -rf "$(OBJ)/"