forked from apptainer/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-linter
executable file
·93 lines (75 loc) · 2.39 KB
/
run-linter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
set -e
golangci_lint_version=1.40.1
golangci_lint_install_url=https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
info() {
printf 'I: %s\n' "$*"
}
warn() {
printf 'W: %s\n' "$*"
}
error() {
printf 'E: %s\n' "$*"
}
cd_to_toplevel() {
local toplevel="$(git rev-parse --show-toplevel 2> /dev/null)"
if test -n "${toplevel}" ; then
cd "${toplevel}"
return
fi
# failed to get toplevel directory, we are not inside a git
# repo? Fall back to current directory.
toplevel=$PWD
if test ! -f "${toplevel}/VERSION" ; then
# No VERSION file found, we are not looking at a release
# tarball ether? Bail out.
error 'Cannot identify toplevel directory. Abort.'
exit 1
fi
# already in the top level directory, return
}
check_golangci_lint() {
bindir=$1
if ! command -v golangci-lint >/dev/null 2>&1 ; then
warn 'golangci-lint not found in $PATH. Downloading...'
mkdir -p "${bindir}"
curl -sfL "${golangci_lint_install_url}" |
sh -s -- -b "${bindir}" "v${golangci_lint_version}"
fi
if ! command -v golangci-lint >/dev/null 2>&1 ; then
error 'golangci-lint not found in $PATH even after trying to install it. Abort.'
info ''
info 'Looked in the following directories, in order:'
info ''
IFS=:
for dir in ${PATH} ; do
info " ${dir}"
done
exit 1
elif golangci-lint version 2>&1 | grep -q -F "golangci-lint has version ${golangci_lint_version} " ; then
# Found expected golangci-lint version
return
elif golangci-lint version 2>&1 | grep -q -F 'golangci-lint has version (devel) ' ; then
warn 'Using development version of golangci-lint.'
else
warn ''
warn '********************************************************************************************'
warn "Singularity's CI checks will use version ${golangci_lint_version} of golangci-lint."
warn "Your installed version differs. Please use ${golangci_lint_version} if you experience issues."
info ''
info 'The output of "golangci-lint version" is:'
info ''
info " $(golangci-lint version 2>&1)"
info ''
info 'It was found in the following location:'
info ''
info " $(command -v golangci-lint)"
info '********************************************************************************************'
info ''
fi
}
cd_to_toplevel
bindir=$PWD/builddir/bin
PATH=${bindir}:$PATH
check_golangci_lint "${bindir}"
exec golangci-lint "$@"