blob: 3f52516c230bc901a300b2fd92c00161f4581285 [file] [log] [blame]
Joey Armstrong9956d972022-11-11 13:07:31 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong92ac4cf2022-12-27 07:39:37 -05003# Copyright 2023 Open Networking Foundation (ONF) and the ONF Contributors
4# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-FileCopyrightText: 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
19# SPDX-License-Identifier: Apache-2.0
20# -----------------------------------------------------------------------
21
22# -*- makefile -*-
23# -----------------------------------------------------------------------
Joey Armstrong9956d972022-11-11 13:07:31 -050024# Copyright 2017-2022 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo2da72782022-06-13 11:30:07 -070025# SPDX-FileCopyrightText: 2022-present Intel Corporation
26#
27# SPDX-License-Identifier: Apache-2.0
Joey Armstrong9956d972022-11-11 13:07:31 -050028# -----------------------------------------------------------------------
Matteo Scandolo2da72782022-06-13 11:30:07 -070029
Joey Armstrong9956d972022-11-11 13:07:31 -050030.DEFAULT_GOAL := test
Matteo Scandolo2da72782022-06-13 11:30:07 -070031
Joey Armstrong9956d972022-11-11 13:07:31 -050032dot ?= .
33TOP ?= $(dot)
34MAKEDIR ?= $(TOP)/makefiles
35
Joey Armstrong9956d972022-11-11 13:07:31 -050036jq = $(env-clean) jq
37jq-args += --exit-status
38
39YAMLLINT = $(shell which yamllint)
40yamllint := $(env-clean) $(YAMLLINT)
41yamllint-args := -c .yamllint
42
Joey Armstrong92ac4cf2022-12-27 07:39:37 -050043##--------------------##
44##---] INCLUDES [---##
45##--------------------##
46include $(MAKEDIR)/include.mk
47
Joey Armstrong9956d972022-11-11 13:07:31 -050048##-------------------##
49##---] TARGETS [---##
50##-------------------##
51all:
52
53lint += lint-json
54lint += lint-yaml
55
56lint : $(lint)
57test : lint
58
59## -----------------------------------------------------------------------
60## -----------------------------------------------------------------------
61lint-yaml yaml-lint:
62ifeq ($(null),$(shell which yamllint))
Matteo Scandolo2da72782022-06-13 11:30:07 -070063 $(error "Please install yamllint to run linting")
64endif
Joey Armstrong9956d972022-11-11 13:07:31 -050065 $(HIDE)$(env-clean) find . -name '*.yaml' -type f -print0 \
66 | xargs -0 -t -n1 $(yamllint) $(yamllint-args)
67
68## -----------------------------------------------------------------------
69## -----------------------------------------------------------------------
70lint-json:
71 $(HIDE)$(env-clean) find . -name '*.json' -type f -print0 \
72 | xargs -0 -t -n1 $(jq) $(jq-args) $(dot) >/dev/null
73
74## -----------------------------------------------------------------------
75## -----------------------------------------------------------------------
76pre-check:
77 @echo "[REQUIRED] Checking for linting tools"
78 $(HIDE)which jq
79 $(HIDE)which yamllint
80 @echo
81
82## -----------------------------------------------------------------------
83## -----------------------------------------------------------------------
Joey Armstrongffd93d22022-12-02 09:37:18 -050084.PHONY: pre-commit
85.PHONY: fixperms
86pre-commit: lint fixperms
87
88## -----------------------------------------------------------------------
89## Scrub volume messages from jenksins logs and help secure nodes.
90## WARNING: Kubernetes configuration file is group-readable. This is insecure
91## -----------------------------------------------------------------------
92fixperms-args :=$(null)
93fixperms-args += -name '*.conf'
94fixperms-args += -o -name '*.json'
95fixperms-args += -o -name '*.yaml'
96fixperms:
97 $(HIDE)find . \( $(fixperms-args) \) -print0 \
98 | xargs -0 chmod og-rwx
99
100## -----------------------------------------------------------------------
101## -----------------------------------------------------------------------
Joey Armstrong9956d972022-11-11 13:07:31 -0500102clean:
103
104## -----------------------------------------------------------------------
105## -----------------------------------------------------------------------
Joey Armstrong92ac4cf2022-12-27 07:39:37 -0500106help::
Joey Armstrong9956d972022-11-11 13:07:31 -0500107 @echo
108 @echo "USAGE: $(MAKE)"
109 @echo " lint perform syntax checks on source"
110 @echo " test perform syntax checks on source"
111 @echo " pre-check Verify tools and deps are available for testing"
112 @echo
113 @echo "[LINT]"
114 @echo " lint-json Syntax check .json sources"
115 @echo " lint-yaml Syntax check .yaml sources"
116 @echo
Joey Armstrongffd93d22022-12-02 09:37:18 -0500117 @echo "[PRE:check]"
118 @echo " pre-check Verify tools and deps are available for testing"
119 @echo
120 @echo "[PRE:commit]"
121 @echo " pre-commit Perform common repairs on source"
122 @echo " fixperms Remove group write permission on config files"
123 @echo
Joey Armstrong92ac4cf2022-12-27 07:39:37 -0500124
Joey Armstrong9956d972022-11-11 13:07:31 -0500125# [EOF]