1# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
2#
3# The original version of this file is located in the https://github.com/istio/common-files repo.
4# If you're looking at this file in a different repo and want to make a change, please go to the
5# common-files repo, make the change there and check it in. Then come back to this repo and run
6# "make update-common".
7
8# Copyright Istio Authors
9#
10# Licensed under the Apache License, Version 2.0 (the "License");
11# you may not use this file except in compliance with the License.
12# You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16# Unless required by applicable law or agreed to in writing, software
17# distributed under the License is distributed on an "AS IS" BASIS,
18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19# See the License for the specific language governing permissions and
20# limitations under the License.
21
22FINDFILES=find . \( -path ./common-protos -o -path ./.git -o -path ./out -o -path ./.github -o -path ./licenses -o -path ./vendor \) -prune -o -type f
23XARGS = xargs -0 -r
24
25lint-dockerfiles:
26	@${FINDFILES} -name 'Dockerfile*' -print0 | ${XARGS} hadolint -c ./common/config/.hadolint.yml
27
28lint-scripts:
29	@${FINDFILES} -name '*.sh' -print0 | ${XARGS} shellcheck
30
31# TODO(nmittler): disabled pipefail due to grep failing when no files contain "{{". Need to investigate options.
32lint-yaml:
33	@set +o pipefail; ${FINDFILES} \( -name '*.yml' -o -name '*.yaml' \) -print0 | ${XARGS} grep -L -e "{{" | xargs -r yamllint -c ./common/config/.yamllint.yml
34
35lint-helm:
36	@${FINDFILES} -name 'Chart.yaml' -print0 | ${XARGS} -L 1 dirname | xargs -r helm lint --strict
37
38lint-copyright-banner:
39	@${FINDFILES} \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' -o -name '*.py' -o -name '*.sh' \) \( ! \( -name '*.gen.go' -o -name '*.pb.go' -o -name '*_pb2.py' \) \) -print0 |\
40		${XARGS} common/scripts/lint_copyright_banner.sh
41
42lint-go:
43	@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} common/scripts/lint_go.sh
44
45lint-python:
46	@${FINDFILES} -name '*.py' \( ! \( -name '*_pb2.py' \) \) -print0 | ${XARGS} autopep8 --max-line-length 160 --exit-code -d
47
48lint-markdown:
49	@${FINDFILES} -name '*.md' -print0 | ${XARGS} mdl --ignore-front-matter --style common/config/mdl.rb
50
51lint-links:
52	@${FINDFILES} -name '*.md' -print0 | ${XARGS} awesome_bot --skip-save-results --allow_ssl --allow-timeout --allow-dupe --allow-redirect --white-list ${MARKDOWN_LINT_WHITELIST}
53
54lint-sass:
55	@${FINDFILES} -name '*.scss' -print0 | ${XARGS} sass-lint -c common/config/sass-lint.yml --verbose
56
57lint-typescript:
58	@${FINDFILES} -name '*.ts' -print0 | ${XARGS} tslint -c common/config/tslint.json
59
60lint-protos:
61	@if test -d common-protos; then $(FINDFILES) -name '*.proto' -print0 | $(XARGS) -L 1 prototool lint --protoc-bin-path=/usr/bin/protoc --protoc-wkt-path=common-protos; fi
62
63lint-licenses: mod-download-go
64	@license-lint --config common/config/license-lint.yml
65
66lint-all: lint-dockerfiles lint-scripts lint-yaml lint-helm lint-copyright-banner lint-go lint-python lint-markdown lint-sass lint-typescript lint-protos lint-licenses
67
68tidy-go:
69	@go mod tidy
70
71mod-download-go:
72	@-GOFLAGS="-mod=readonly" go mod download
73
74format-go: tidy-go
75	@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} goimports -w -local "istio.io"
76
77format-python:
78	@${FINDFILES} -name '*.py' -print0 | ${XARGS} autopep8 --max-line-length 160 --aggressive --aggressive -i
79
80format-protos:
81	@$(FINDFILES) -name '*.proto' -print0 | $(XARGS) -L 1 prototool format -w
82
83dump-licenses: mod-download-go
84	@license-lint --config common/config/license-lint.yml --report
85
86dump-licenses-csv: mod-download-go
87	@license-lint --config common/config/license-lint.yml --csv
88
89mirror-licenses: mod-download-go
90	@rm -fr licenses
91	@license-lint --mirror
92
93TMP := $(shell mktemp -d -u)
94UPDATE_BRANCH ?= "release-1.6"
95
96update-common:
97	@mkdir -p $(TMP)
98	@git clone -q --depth 1 --single-branch --branch $(UPDATE_BRANCH) https://github.com/istio/common-files $(TMP)/common-files
99	@cd $(TMP)/common-files ; git rev-parse HEAD >files/common/.commonfiles.sha
100	@rm -fr common
101	@cp -a $(TMP)/common-files/files/* $(shell pwd)
102	@rm -fr $(TMP)/common-files
103
104update-common-protos:
105	@mkdir -p $(TMP)
106	@git clone -q --depth 1 --single-branch --branch $(UPDATE_BRANCH) https://github.com/istio/common-files $(TMP)/common-files
107	@cd $(TMP)/common-files ; git rev-parse HEAD > common-protos/.commonfiles.sha
108	@rm -fr common-protos
109	@cp -a $(TMP)/common-files/common-protos $(shell pwd)
110	@rm -fr $(TMP)/common-files
111
112check-clean-repo:
113	@common/scripts/check_clean_repo.sh
114
115tidy-docker:
116	@docker image prune --all --force --filter="label=io.istio.repo=https://github.com/istio/tools" --filter="label!=io.istio.version=$(IMAGE_VERSION)"
117
118
119.PHONY: lint-dockerfiles lint-scripts lint-yaml lint-copyright-banner lint-go lint-python lint-helm lint-markdown lint-sass lint-typescript lint-protos lint-all format-go format-python format-protos update-common update-common-protos lint-licenses dump-licenses dump-licenses-csv check-clean-repo tidy-docker tidy-go mod-download-go
120