Debian Codegraph @

Makefile

raw
1 EPOCH_TEST_COMMIT ?= v0.2.0
2
3 DOCKER ?= $(shell command -v docker 2>/dev/null)
4 PANDOC ?= $(shell command -v pandoc 2>/dev/null)
5
6 GOPATH:=$(shell go env GOPATH)
7
8 OUTPUT_DIRNAME ?= output
9 DOC_FILENAME ?= oci-image-spec
10
11 PANDOC_CONTAINER ?= ghcr.io/opencontainers/pandoc:2.9.2.1-8.fc33.x86_64@sha256:5d81ff930a043295a557be8b003ece2a33d14e91b28c50d368413b83372f8d28
12 ifeq "$(strip $(PANDOC))" ''
13 ifneq "$(strip $(DOCKER))" ''
14 PANDOC = $(DOCKER) run \
15 --rm \
16 -v $(shell pwd)/:/input/:ro \
17 -v $(shell pwd)/$(OUTPUT_DIRNAME)/:/$(OUTPUT_DIRNAME)/ \
18 -u $(shell id -u) \
19 --workdir /input \
20 $(PANDOC_CONTAINER)
21 PANDOC_SRC := /input/
22 PANDOC_DST := /
23 endif
24 endif
25
26 # These docs are in an order that determines how they show up in the PDF/HTML docs.
27 DOC_FILES := \
28 spec.md \
29 media-types.md \
30 descriptor.md \
31 image-layout.md \
32 manifest.md \
33 image-index.md \
34 layer.md \
35 config.md \
36 annotations.md \
37 conversion.md \
38 considerations.md \
39 implementations.md
40
41 FIGURE_FILES := \
42 img/media-types.png
43
44 MARKDOWN_LINT_VER?=v0.8.1
45
46 TOOLS := gitvalidation
47
48 default: check-license lint test
49
50 .PHONY: fmt
51 fmt: ## format the json with indentation
52 for i in schema/*.json ; do jq --indent 2 -M . "$${i}" > xx && cat xx > "$${i}" && rm xx ; done
53
54 .PHONY: docs
55 docs: $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf $(OUTPUT_DIRNAME)/$(DOC_FILENAME).html ## generate a PDF/HTML version of the OCI image specification
56
57 ifeq "$(strip $(PANDOC))" ''
58 $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
59 $(error cannot build $@ without either pandoc or docker)
60 else
61 $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
62 @mkdir -p $(OUTPUT_DIRNAME)/ && \
63 $(PANDOC) -f gfm -t latex --pdf-engine=xelatex -V geometry:margin=0.5in,bottom=0.8in -V block-headings -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
64 ls -sh $(realpath $@)
65
66 $(OUTPUT_DIRNAME)/$(DOC_FILENAME).html: header.html $(DOC_FILES) $(FIGURE_FILES)
67 @mkdir -p $(OUTPUT_DIRNAME)/ && \
68 cp -ap img/ $(shell pwd)/$(OUTPUT_DIRNAME)/&& \
69 $(PANDOC) -f gfm -t html5 -H $(PANDOC_SRC)header.html --standalone -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
70 ls -sh $(realpath $@)
71 endif
72
73 header.html: .tool/genheader.go specs-go/version.go
74 go run .tool/genheader.go > $@
75
76 .PHONY: validate-examples
77 validate-examples: schema/schema.go ## validate examples in the specification markdown files
78 go test -run TestValidate ./schema
79
80 .PHONY: check-license
81 check-license: ## check license headers in source files
82 @echo "checking license headers"
83 @./.tool/check-license
84
85 .PHONY: lint
86
87 .PHONY: lint
88 lint: lint-go lint-md ## Run all linters
89
90 .PHONY: lint-go
91 lint-go: .install.lint ## lint check of Go files using golangci-lint
92 @echo "checking Go lint"
93 @GO111MODULE=on $(GOPATH)/bin/golangci-lint run
94
95 .PHONY: lint-md
96 lint-md: ## Run linting for markdown
97 docker run --rm -v "$(PWD):/workdir:ro" docker.io/davidanson/markdownlint-cli2:$(MARKDOWN_LINT_VER) \
98 "**/*.md" "#vendor"
99
100 .PHONY: test
101 test: ## run the unit tests
102 go test -race -cover $(shell go list ./... | grep -v /vendor/)
103
104 img/%.png: img/%.dot ## generate PNG from dot file
105 dot -Tpng $^ > $@
106
107 # When this is running in GitHub, it will only check the commit range
108 .PHONY: .gitvalidation
109 .gitvalidation:
110 @which git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found. Consider 'make install.tools' target" && false)
111 ifdef GITHUB_SHA
112 $(GOPATH)/bin/git-validation -q -run DCO,short-subject,dangling-whitespace -range $(GITHUB_SHA)..HEAD
113 else
114 $(GOPATH)/bin/git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD
115 endif
116
117 .PHONY: .install.tools
118 install.tools: $(TOOLS:%=.install.%)
119
120 .PHONY: .install.lint
121 .install.lint:
122 case "$$(go env GOVERSION)" in \
123 go1.18.*) go install github.com/golangci/golangci-lint/cmd/[email protected];; \
124 go1.19.*) go install github.com/golangci/golangci-lint/cmd/[email protected];; \
125 go1.20.*) go install github.com/golangci/golangci-lint/cmd/[email protected];; \
126 go1.21.*) go install github.com/golangci/golangci-lint/cmd/[email protected];; \
127 *) go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest;; \
128 esac
129
130 .PHONY: .install.gitvalidation
131 .install.gitvalidation:
132 go install github.com/vbatts/git-validation@latest
133
134 .PHONY: clean
135 clean: ## clean all generated and compiled artifacts
136 rm -rf *~ $(OUTPUT_DIRNAME) header.html
137
138 .PHONY: help
139 help: # Display help
140 @awk -F ':|##' '/^[^\t].+?:.*?##/ { printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF }' $(MAKEFILE_LIST)