blob: a76987ef7e0d7c302448da875c8c93cd8752a497 [file] [log] [blame]
Joey Armstrong03588972022-12-07 17:30:09 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2022 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20
21GIT ?= /usr/bin/git
22
23chart-version-check-sh := helm-repo-tools/chart_version_check.sh
24
25## -------------------------------------------------------------------
26## NOTE: This uglyness can go away with proper command line switch use
27## -------------------------------------------------------------------
28## o USE_LEGACY= (default)
29## - bridge logic: support existing behavior.
30## - helmlint.sh contains hardcoded branch='origin/opencord'
31## o TODO:
32## - infer values from repository checkout on disk.
33## - parameterize helmlint.sh
34## - use simple flags to toggle behavior:
35## MASTER_BRANCH=1 || --branch master (default)
36## LOCAL_BRANCH=1 || --branch local)
37## MY_BRANCH=1 || --branch local
38## - Better yet: when branch name is known simply pass it:
39## % make lint-helm BRANCH=alt-branch-name
40## -----------------------------------------------------------------------
41USE_LEGACY = 1
42ifdef USE_LEGACY
43 $(if $(DEBUG),$(info ifdef USE_LEGACY))
44
45 lint-helm-branch ?= $(shell cat .gitreview | grep branch | cut -d '=' -f2)
46
47else
48 $(if $(DEBUG),$(info not USE_LEGACY))
49
50 ifdef LOCAL_BRANCH
51 get-git-branch ?= $(shell $(GIT) branch --show-current)# empty if detached
52 get-git-branch ?= $(shell awk -F '/branch/ {print $$2}' .gitreview)
53 get-git-branch ?= $(error Detected detached head)
54
55 else # master
56 # refs/remotes/origin/HEAD => origin/master
57 get-git-branch ?= $(shell $(GIT) symbolic-ref --short refs/remotes/origin/HEAD)
58 endif
59
60 lint-helm-branch ?= $(COMPARISON_BRANCH)
61 lint-helm-branch ?= $(get-git-branch)
62
63 $(if $(DEBUG),$(info get-git-branch = $(get-git-branch)))
64 $(if $(DEBUG),$(info lint-branch=$(lint-branch)))
65endif
66
67##-------------------##
68##---] TARGETS [---##
69##-------------------##
70.PHONY : lint-helm
71lint : lint-helm
72
73## -----------------------------------------------------------------------
74## Intent: Lint helm charts
75## o This logic mirrors gerrit/jenkins commit hook behavior.
76## o Adding to stem incidents of late pull request jenkins failures.
77## o see: make help VERBOSE=1
78## -----------------------------------------------------------------------
79.PHONY: lint-helm
80lint-helm: $(chart-version-check-sh)# helm-repo-tools
81lint-helm:
82 COMPARISON_BRANCH="$(get-git-branch)" $(chart-version-check-sh)
83# COMPARISON_BRANCH="$(lint-helm-branch)" $(chart-version-check-sh)
84
85## -----------------------------------------------------------------------
86## Intent: repo:helm-repo-tools
87## o Use script as a dependency for on-demand cloning.
88## o Use of repo name (r-h-t) as a dependency is problematic.
89## -----------------------------------------------------------------------
90$(chart-version-check-sh):
91 $(GIT) clone "https://gerrit.opencord.org/helm-repo-tools"
92
93## -----------------------------------------------------------------------
94## Intent:
95## -----------------------------------------------------------------------
96# branch=`cat .gitreview | grep branch | cut -d '=' -f2`
97pre-commit :: lint-helm
98# $(chart-version-check-sh) clean
99# @COMPARISON_BRANCH=origin/$(branch) $(chart-version-check-sh)
100# $(chart-version-check-sh)
101
102## -----------------------------------------------------------------------
103## [TODO] Extract hardcoded values from lint.sh:
104## o pass as args
105## o pass through configs:
106## o consumer/makefile should prep then invoke htmllint:
107## + arbitrary repository commit hooks can match build behavior.
108## -----------------------------------------------------------------------
109lint-helm-deps:
110 helm repo add stable https://charts.helm.sh/stable
111 helm repo add rook-release https://charts.rook.io/release
112 helm repo add cord https://charts.opencord.org
113
114## -----------------------------------------------------------------------
115## Intent: Remove generated targets
116## -----------------------------------------------------------------------
117clean ::
118 $(chart-version-check-sh) clean
119
120## -----------------------------------------------------------------------
121## Intent: Remove all non-source targets
122## -----------------------------------------------------------------------
123sterile ::
124 $(RM) helm-repo-tools
125
126## -----------------------------------------------------------------------
127## Intent: Display target help with context
128## % make help
129## % make help VERBOSE=1
130## -----------------------------------------------------------------------
131help ::
132 @echo " lint-helm Syntax check helm charts"
133ifdef VERBOSE
134 @echo " lint-helm COMPARISON_BRANCH=1 Local/dev lint (branch != master)"
135endif
136ifdef VERBOSE
137 @echo " lint-helm-deps Configure dependent helm charts"
138endif
139
140## -----------------------------------------------------------------------
141## Intent: Future enhancement list
142## -----------------------------------------------------------------------
143todo ::
144 @ehco "[TODO: makefiles/helm/include.mk]"
145 @echo " o Generalize script logic, remove hardcoded values,"
146 @echo " o Update gerrit/jenkins/makefiles/interactive:"
147 @echo " Lint behavior should be consistent everywhere."
148 @echo " o Fix COMPARSION_BRANCH logic:"
149 @echo " helm-repo-tools/chart_version_check contains 'opencord/master'"
150 @echo " o Refactor 2 jenkins jobs and lint-helm-deps"
151 @echo " use everywhere: % make lint-helm"
152
153# [EOF]