Skip to content

Commit 9b9437a

Browse files
committed
hack: align install-tools.sh with samba-operator
Align install-tools.sh with latest samba-operator (commit: 47770c33) revision. Specifically, needed for the recently added 'gitlint' utility. Signed-off-by: Shachar Sharon <[email protected]>
1 parent a35d7c3 commit 9b9437a

File tree

2 files changed

+174
-4
lines changed

2 files changed

+174
-4
lines changed

.gitlint

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Edit this file as you like.
2+
#
3+
# All these sections are optional. Each section with the exception of [general] represents
4+
# one rule and each key in it is an option for that specific rule.
5+
#
6+
# Rules and sections can be referenced by their full name or by id. For example
7+
# section "[body-max-line-length]" could also be written as "[B1]". Full section names are
8+
# used in here for clarity.
9+
#
10+
[general]
11+
# Ignore certain rules, this example uses both full name and id
12+
# ignore=title-trailing-punctuation, T3
13+
14+
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
15+
verbosity=3
16+
17+
# By default gitlint will ignore merge, revert, fixup and squash commits.
18+
ignore-merge-commits=true
19+
# ignore-revert-commits=true
20+
# ignore-fixup-commits=true
21+
# ignore-squash-commits=true
22+
23+
# Ignore any data send to gitlint via stdin
24+
# ignore-stdin=true
25+
26+
# Fetch additional meta-data from the local repository when manually passing a
27+
# commit message to gitlint via stdin or --commit-msg. Disabled by default.
28+
# staged=true
29+
30+
# Enable debug mode (prints more output). Disabled by default.
31+
# debug=true
32+
33+
# Enable community contributed rules
34+
# See http://jorisroovers.github.io/gitlint/contrib_rules for details
35+
# contrib=contrib-body-requires-signed-off-by
36+
37+
# Set the extra-path where gitlint will search for user defined rules
38+
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
39+
# extra-path=examples/
40+
41+
# This is an example of how to configure the "title-max-length" rule and
42+
# set the line-length it enforces to 80
43+
[title-max-length]
44+
line-length=72
45+
46+
# Conversely, you can also enforce minimal length of a title with the
47+
# "title-min-length" rule:
48+
# [title-min-length]
49+
# min-length=5
50+
51+
[title-must-not-contain-word]
52+
# Comma-separated list of words that should not occur in the title. Matching is case
53+
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
54+
# will not cause a violation, but "WIP: my title" will.
55+
words=wip,WIP
56+
57+
[title-match-regex]
58+
# python-style regex that the commit-msg title must match
59+
# Note that the regex can contradict with other rules if not used correctly
60+
# (e.g. title-must-not-contain-word).
61+
regex=^.*
62+
63+
# [body-max-line-length]
64+
# line-length=72
65+
66+
# [body-min-length]
67+
# min-length=5
68+
69+
# [body-is-missing]
70+
# Whether to ignore this rule on merge commits (which typically only have a title)
71+
# default = True
72+
# ignore-merge-commits=false
73+
74+
# [body-changed-file-mention]
75+
# List of files that need to be explicitly mentioned in the body when they are changed
76+
# This is useful for when developers often erroneously edit certain files or git submodules.
77+
# By specifying this rule, developers can only change the file when they explicitly reference
78+
# it in the commit message.
79+
# files=gitlint/rules.py,README.md
80+
81+
# [body-match-regex]
82+
# python-style regex that the commit-msg body must match.
83+
# E.g. body must end in My-Commit-Tag: foo
84+
# regex=My-Commit-Tag: foo$
85+
86+
# [author-valid-email]
87+
# python-style regex that the commit author email address must match.
88+
# For example, use the following regex if you only want to allow email addresses from foo.com
89+
# regex=[^@][email protected]
90+
91+
# [ignore-by-title]
92+
# Ignore certain rules for commits of which the title matches a regex
93+
# E.g. Match commit titles that start with "Release"
94+
# regex=^Release(.*)
95+
96+
# Ignore certain rules, you can reference them by their id or by their full name
97+
# Use 'all' to ignore all rules
98+
# ignore=T1,body-min-length
99+
100+
# [ignore-by-body]
101+
# Ignore certain rules for commits of which the body has a line that matches a regex
102+
# E.g. Match bodies that have a line that that contain "release"
103+
# regex=(.*)release(.*)
104+
#
105+
# Ignore certain rules, you can reference them by their id or by their full name
106+
# Use 'all' to ignore all rules
107+
# ignore=T1,body-min-length
108+
109+
# [ignore-body-lines]
110+
# Ignore certain lines in a commit body that match a regex.
111+
# E.g. Ignore all lines that start with 'Co-Authored-By'
112+
# regex=^Co-Authored-By
113+
114+
# This is a contrib rule - a community contributed rule. These are disabled by default.
115+
# You need to explicitly enable them one-by-one by adding them to the "contrib" option
116+
# under [general] section above.
117+
# [contrib-title-conventional-commits]
118+
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
119+
# types = bugfix,user-story,epic

hack/install-tools.sh

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ _require_gobin() {
1212
mkdir -p "${GOBIN}"
1313
}
1414

15+
_require_go() {
16+
if [ -z "$GO_CMD" ]; then
17+
echo "error: go command required, but not found" >&2
18+
echo "(set GO_CMD to specify go command)" >&2
19+
exit 5
20+
fi
21+
}
22+
23+
_require_py() {
24+
if [ -z "$PY_CMD" ]; then
25+
echo "error: python3 command required, but not found" >&2
26+
echo "(set PY_CMD to specify python command)" >&2
27+
exit 5
28+
fi
29+
}
30+
1531
_install_tool() {
32+
_require_go
1633
GOBIN="${GOBIN}" ${GO_CMD} install "$1"
1734
}
1835

@@ -25,17 +42,42 @@ _install_controller_gen() {
2542
}
2643

2744
_install_revive() {
28-
_install_tool github.com/mgechev/revive@latest
45+
_install_tool github.com/mgechev/revive@v1.2.3
2946
}
3047

3148
_install_golangci_lint() {
32-
_install_tool github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
49+
_install_tool github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
3350
}
3451

3552
_install_yq() {
36-
_install_tool github.com/mikefarah/yq/v4@latest
53+
_install_tool github.com/mikefarah/yq/v4@v4.23.1
3754
}
3855

56+
_install_gosec() {
57+
_install_tool github.com/securego/gosec/v2/cmd/[email protected]
58+
}
59+
60+
_install_gitlint() {
61+
_require_gobin
62+
_require_py
63+
"${PY_CMD}" -m venv "${GOBIN}/.py"
64+
"${GOBIN}/.py/bin/pip" install "gitlint==0.19.1"
65+
ln -s "${GOBIN}/.py/bin/gitlint" "${GOBIN}/gitlint"
66+
}
67+
68+
GOBIN="${GOBIN:-${GOPATH}/bin}"
69+
70+
if [ -z "$GO_CMD" ]; then
71+
if ! GO_CMD="$(command -v go)"; then
72+
echo "warning: failed to find go command" >&2
73+
fi
74+
fi
75+
if [ -z "$PY_CMD" ]; then
76+
if ! PY_CMD="$(command -v python3)"; then
77+
echo "warning: failed to find python3 command" >&2
78+
fi
79+
fi
80+
3981
case "$1" in
4082
--kustomize)
4183
_require_gobin
@@ -57,14 +99,23 @@ case "$1" in
5799
_require_gobin
58100
_install_yq
59101
;;
102+
--gosec)
103+
_require_gobin
104+
_install_gosec
105+
;;
106+
--gitlint)
107+
_install_gitlint
108+
;;
60109
*)
61110
echo "usage: GOBIN=<dir> $0 --<tool-name>"
62111
echo ""
63-
echo "availabel tools:"
112+
echo "available tools:"
64113
echo " --kustomize"
65114
echo " --controller-gen"
66115
echo " --revive"
67116
echo " --golangci-lint"
68117
echo " --yq"
118+
echo " --gosec"
119+
echo " --gitlint"
69120
;;
70121
esac

0 commit comments

Comments
 (0)