...

Text file src/github.com/opencontainers/image-spec/Makefile

Documentation: github.com/opencontainers/image-spec

     1EPOCH_TEST_COMMIT ?= v0.2.0
     2
     3DOCKER ?= $(shell command -v docker 2>/dev/null)
     4PANDOC ?= $(shell command -v pandoc 2>/dev/null)
     5
     6GOPATH:=$(shell go env GOPATH)
     7
     8OUTPUT_DIRNAME	?= output
     9DOC_FILENAME	?= oci-image-spec
    10
    11PANDOC_CONTAINER ?= ghcr.io/opencontainers/pandoc:2.9.2.1-8.fc33.x86_64@sha256:5d81ff930a043295a557be8b003ece2a33d14e91b28c50d368413b83372f8d28
    12ifeq "$(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
    24endif
    25
    26# These docs are in an order that determines how they show up in the PDF/HTML docs.
    27DOC_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
    41FIGURE_FILES := \
    42	img/media-types.png
    43
    44MARKDOWN_LINT_VER?=v0.8.1
    45
    46TOOLS := gitvalidation
    47
    48default: check-license lint test
    49
    50.PHONY: fmt
    51fmt: ## 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
    55docs: $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf $(OUTPUT_DIRNAME)/$(DOC_FILENAME).html ## generate a PDF/HTML version of the OCI image specification
    56
    57ifeq "$(strip $(PANDOC))" ''
    58$(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
    59	$(error cannot build $@ without either pandoc or docker)
    60else
    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 $@)
    71endif
    72
    73header.html: .tool/genheader.go specs-go/version.go
    74	go run .tool/genheader.go > $@
    75
    76.PHONY: validate-examples
    77validate-examples: schema/schema.go ## validate examples in the specification markdown files
    78	go test -run TestValidate ./schema
    79
    80.PHONY: check-license
    81check-license: ## check license headers in source files
    82	@echo "checking license headers"
    83	@./.tool/check-license
    84
    85.PHONY: lint
    86
    87.PHONY: lint
    88lint: lint-go lint-md ## Run all linters
    89
    90.PHONY: lint-go
    91lint-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
    96lint-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
   101test: ## run the unit tests
   102	go test -race -cover $(shell go list ./... | grep -v /vendor/)
   103
   104img/%.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)
   111ifdef GITHUB_SHA
   112	$(GOPATH)/bin/git-validation -q -run DCO,short-subject,dangling-whitespace -range $(GITHUB_SHA)..HEAD
   113else
   114	$(GOPATH)/bin/git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD
   115endif
   116
   117.PHONY: .install.tools
   118install.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/golangci-lint@v1.47.3;; \
   124	go1.19.*)	go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1;; \
   125	*) go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest;; \
   126	esac
   127
   128.PHONY: .install.gitvalidation
   129.install.gitvalidation:
   130	go install github.com/vbatts/git-validation@latest
   131
   132.PHONY: clean
   133clean: ## clean all generated and compiled artifacts
   134	rm -rf *~ $(OUTPUT_DIRNAME) header.html
   135
   136.PHONY: help
   137help: # Display help
   138	@awk -F ':|##' '/^[^\t].+?:.*?##/ { printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF }' $(MAKEFILE_LIST)

View as plain text