Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit ed05ac3

Browse files
authored
Merge pull request #15 from splunk/fix_lint
Install golangci-lint
2 parents 489ecf8 + 1e604e3 commit ed05ac3

File tree

2 files changed

+383
-2
lines changed

2 files changed

+383
-2
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ test: build
3131
gotestsum --junitfile $(TESTREPORT) --format standard-verbose -- -cover -v ./...
3232

3333
.PHONY: lint
34-
lint:
35-
golangci-lint run $(GOLANGCI_LINT_ARGS)
34+
lint: dep
35+
$(GOBIN)/golangci-lint run $(GOLANGCI_LINT_ARGS)
36+
37+
.PHONY: dep
38+
dep:
39+
./scripts/golangci-lint.sh -b $(GOBIN) v1.17.1
3640

3741
.PHONY: clean
3842
clean:

scripts/golangci-lint.sh

Lines changed: 377 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,377 @@
1+
#!/bin/sh
2+
set -e
3+
# Code generated by godownloader on 2019-06-13T12:03:03Z. DO NOT EDIT.
4+
#
5+
6+
usage() {
7+
this=$1
8+
cat <<EOF
9+
$this: download go binaries for golangci/golangci-lint
10+
11+
Usage: $this [-b] bindir [-d] [tag]
12+
-b sets bindir or installation directory, Defaults to ./bin
13+
-d turns on debug logging
14+
[tag] is a tag from
15+
https://github.com/golangci/golangci-lint/releases
16+
If tag is missing, then the latest will be used.
17+
18+
Generated by godownloader
19+
https://github.com/goreleaser/godownloader
20+
21+
EOF
22+
exit 2
23+
}
24+
25+
parse_args() {
26+
#BINDIR is ./bin unless set be ENV
27+
# over-ridden by flag below
28+
29+
BINDIR=${BINDIR:-./bin}
30+
while getopts "b:dh?x" arg; do
31+
case "$arg" in
32+
b) BINDIR="$OPTARG" ;;
33+
d) log_set_priority 10 ;;
34+
h | \?) usage "$0" ;;
35+
x) set -x ;;
36+
esac
37+
done
38+
shift $((OPTIND - 1))
39+
TAG=$1
40+
}
41+
# this function wraps all the destructive operations
42+
# if a curl|bash cuts off the end of the script due to
43+
# network, either nothing will happen or will syntax error
44+
# out preventing half-done work
45+
execute() {
46+
tmpdir=$(mktemp -d)
47+
log_debug "downloading files into ${tmpdir}"
48+
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
49+
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
50+
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
51+
srcdir="${tmpdir}/${NAME}"
52+
rm -rf "${srcdir}"
53+
(cd "${tmpdir}" && untar "${TARBALL}")
54+
test ! -d "${BINDIR}" && install -d "${BINDIR}"
55+
for binexe in $BINARIES; do
56+
if [ "$OS" = "windows" ]; then
57+
binexe="${binexe}.exe"
58+
fi
59+
install "${srcdir}/${binexe}" "${BINDIR}/"
60+
log_info "installed ${BINDIR}/${binexe}"
61+
done
62+
rm -rf "${tmpdir}"
63+
}
64+
get_binaries() {
65+
case "$PLATFORM" in
66+
darwin/386) BINARIES="golangci-lint" ;;
67+
darwin/amd64) BINARIES="golangci-lint" ;;
68+
linux/386) BINARIES="golangci-lint" ;;
69+
linux/amd64) BINARIES="golangci-lint" ;;
70+
windows/386) BINARIES="golangci-lint" ;;
71+
windows/amd64) BINARIES="golangci-lint" ;;
72+
*)
73+
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
74+
exit 1
75+
;;
76+
esac
77+
}
78+
tag_to_version() {
79+
if [ -z "${TAG}" ]; then
80+
log_info "checking GitHub for latest tag"
81+
else
82+
log_info "checking GitHub for tag '${TAG}'"
83+
fi
84+
REALTAG=$(github_release "$OWNER/$REPO" "${TAG}") && true
85+
if test -z "$REALTAG"; then
86+
log_crit "unable to find '${TAG}' - use 'latest' or see https://github.com/${PREFIX}/releases for details"
87+
exit 1
88+
fi
89+
# if version starts with 'v', remove it
90+
TAG="$REALTAG"
91+
VERSION=${TAG#v}
92+
}
93+
adjust_format() {
94+
# change format (tar.gz or zip) based on OS
95+
case ${OS} in
96+
windows) FORMAT=zip ;;
97+
esac
98+
true
99+
}
100+
adjust_os() {
101+
# adjust archive name based on OS
102+
true
103+
}
104+
adjust_arch() {
105+
# adjust archive name based on ARCH
106+
true
107+
}
108+
109+
cat /dev/null <<EOF
110+
------------------------------------------------------------------------
111+
https://github.com/client9/shlib - portable posix shell functions
112+
Public domain - http://unlicense.org
113+
https://github.com/client9/shlib/blob/master/LICENSE.md
114+
but credit (and pull requests) appreciated.
115+
------------------------------------------------------------------------
116+
EOF
117+
is_command() {
118+
command -v "$1" >/dev/null
119+
}
120+
echoerr() {
121+
echo "$@" 1>&2
122+
}
123+
log_prefix() {
124+
echo "$0"
125+
}
126+
_logp=6
127+
log_set_priority() {
128+
_logp="$1"
129+
}
130+
log_priority() {
131+
if test -z "$1"; then
132+
echo "$_logp"
133+
return
134+
fi
135+
[ "$1" -le "$_logp" ]
136+
}
137+
log_tag() {
138+
case $1 in
139+
0) echo "emerg" ;;
140+
1) echo "alert" ;;
141+
2) echo "crit" ;;
142+
3) echo "err" ;;
143+
4) echo "warning" ;;
144+
5) echo "notice" ;;
145+
6) echo "info" ;;
146+
7) echo "debug" ;;
147+
*) echo "$1" ;;
148+
esac
149+
}
150+
log_debug() {
151+
log_priority 7 || return 0
152+
echoerr "$(log_prefix)" "$(log_tag 7)" "$@"
153+
}
154+
log_info() {
155+
log_priority 6 || return 0
156+
echoerr "$(log_prefix)" "$(log_tag 6)" "$@"
157+
}
158+
log_err() {
159+
log_priority 3 || return 0
160+
echoerr "$(log_prefix)" "$(log_tag 3)" "$@"
161+
}
162+
log_crit() {
163+
log_priority 2 || return 0
164+
echoerr "$(log_prefix)" "$(log_tag 2)" "$@"
165+
}
166+
uname_os() {
167+
os=$(uname -s | tr '[:upper:]' '[:lower:]')
168+
case "$os" in
169+
msys_nt) os="windows" ;;
170+
esac
171+
echo "$os"
172+
}
173+
uname_arch() {
174+
arch=$(uname -m)
175+
case $arch in
176+
x86_64) arch="amd64" ;;
177+
x86) arch="386" ;;
178+
i686) arch="386" ;;
179+
i386) arch="386" ;;
180+
aarch64) arch="arm64" ;;
181+
armv5*) arch="armv5" ;;
182+
armv6*) arch="armv6" ;;
183+
armv7*) arch="armv7" ;;
184+
esac
185+
echo ${arch}
186+
}
187+
uname_os_check() {
188+
os=$(uname_os)
189+
case "$os" in
190+
darwin) return 0 ;;
191+
dragonfly) return 0 ;;
192+
freebsd) return 0 ;;
193+
linux) return 0 ;;
194+
android) return 0 ;;
195+
nacl) return 0 ;;
196+
netbsd) return 0 ;;
197+
openbsd) return 0 ;;
198+
plan9) return 0 ;;
199+
solaris) return 0 ;;
200+
windows) return 0 ;;
201+
esac
202+
log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib"
203+
return 1
204+
}
205+
uname_arch_check() {
206+
arch=$(uname_arch)
207+
case "$arch" in
208+
386) return 0 ;;
209+
amd64) return 0 ;;
210+
arm64) return 0 ;;
211+
armv5) return 0 ;;
212+
armv6) return 0 ;;
213+
armv7) return 0 ;;
214+
ppc64) return 0 ;;
215+
ppc64le) return 0 ;;
216+
mips) return 0 ;;
217+
mipsle) return 0 ;;
218+
mips64) return 0 ;;
219+
mips64le) return 0 ;;
220+
s390x) return 0 ;;
221+
amd64p32) return 0 ;;
222+
esac
223+
log_crit "uname_arch_check '$(uname -m)' got converted to '$arch' which is not a GOARCH value. Please file bug report at https://github.com/client9/shlib"
224+
return 1
225+
}
226+
untar() {
227+
tarball=$1
228+
case "${tarball}" in
229+
*.tar.gz | *.tgz) tar -xzf "${tarball}" ;;
230+
*.tar) tar -xf "${tarball}" ;;
231+
*.zip) unzip "${tarball}" ;;
232+
*)
233+
log_err "untar unknown archive format for ${tarball}"
234+
return 1
235+
;;
236+
esac
237+
}
238+
http_download_curl() {
239+
local_file=$1
240+
source_url=$2
241+
header=$3
242+
if [ -z "$header" ]; then
243+
code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url")
244+
else
245+
code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url")
246+
fi
247+
if [ "$code" != "200" ]; then
248+
log_debug "http_download_curl received HTTP status $code"
249+
return 1
250+
fi
251+
return 0
252+
}
253+
http_download_wget() {
254+
local_file=$1
255+
source_url=$2
256+
header=$3
257+
if [ -z "$header" ]; then
258+
wget -q -O "$local_file" "$source_url"
259+
else
260+
wget -q --header "$header" -O "$local_file" "$source_url"
261+
fi
262+
}
263+
http_download() {
264+
log_debug "http_download $2"
265+
if is_command curl; then
266+
http_download_curl "$@"
267+
return
268+
elif is_command wget; then
269+
http_download_wget "$@"
270+
return
271+
fi
272+
log_crit "http_download unable to find wget or curl"
273+
return 1
274+
}
275+
http_copy() {
276+
tmp=$(mktemp)
277+
http_download "${tmp}" "$1" "$2" || return 1
278+
body=$(cat "$tmp")
279+
rm -f "${tmp}"
280+
echo "$body"
281+
}
282+
github_release() {
283+
owner_repo=$1
284+
version=$2
285+
test -z "$version" && version="latest"
286+
giturl="https://github.com/${owner_repo}/releases/${version}"
287+
json=$(http_copy "$giturl" "Accept:application/json")
288+
test -z "$json" && return 1
289+
version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//')
290+
test -z "$version" && return 1
291+
echo "$version"
292+
}
293+
hash_sha256() {
294+
TARGET=${1:-/dev/stdin}
295+
if is_command gsha256sum; then
296+
hash=$(gsha256sum "$TARGET") || return 1
297+
echo "$hash" | cut -d ' ' -f 1
298+
elif is_command sha256sum; then
299+
hash=$(sha256sum "$TARGET") || return 1
300+
echo "$hash" | cut -d ' ' -f 1
301+
elif is_command shasum; then
302+
hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
303+
echo "$hash" | cut -d ' ' -f 1
304+
elif is_command openssl; then
305+
hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
306+
echo "$hash" | cut -d ' ' -f a
307+
else
308+
log_crit "hash_sha256 unable to find command to compute sha-256 hash"
309+
return 1
310+
fi
311+
}
312+
hash_sha256_verify() {
313+
TARGET=$1
314+
checksums=$2
315+
if [ -z "$checksums" ]; then
316+
log_err "hash_sha256_verify checksum file not specified in arg2"
317+
return 1
318+
fi
319+
BASENAME=${TARGET##*/}
320+
want=$(grep "${BASENAME}" "${checksums}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1)
321+
if [ -z "$want" ]; then
322+
log_err "hash_sha256_verify unable to find checksum for '${TARGET}' in '${checksums}'"
323+
return 1
324+
fi
325+
got=$(hash_sha256 "$TARGET")
326+
if [ "$want" != "$got" ]; then
327+
log_err "hash_sha256_verify checksum for '$TARGET' did not verify ${want} vs $got"
328+
return 1
329+
fi
330+
}
331+
cat /dev/null <<EOF
332+
------------------------------------------------------------------------
333+
End of functions from https://github.com/client9/shlib
334+
------------------------------------------------------------------------
335+
EOF
336+
337+
PROJECT_NAME="golangci-lint"
338+
OWNER=golangci
339+
REPO="golangci-lint"
340+
BINARY=golangci-lint
341+
FORMAT=tar.gz
342+
OS=$(uname_os)
343+
ARCH=$(uname_arch)
344+
PREFIX="$OWNER/$REPO"
345+
346+
# use in logging routines
347+
log_prefix() {
348+
echo "$PREFIX"
349+
}
350+
PLATFORM="${OS}/${ARCH}"
351+
GITHUB_DOWNLOAD=https://github.com/${OWNER}/${REPO}/releases/download
352+
353+
uname_os_check "$OS"
354+
uname_arch_check "$ARCH"
355+
356+
parse_args "$@"
357+
358+
get_binaries
359+
360+
tag_to_version
361+
362+
adjust_format
363+
364+
adjust_os
365+
366+
adjust_arch
367+
368+
log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}"
369+
370+
NAME=${BINARY}-${VERSION}-${OS}-${ARCH}
371+
TARBALL=${NAME}.${FORMAT}
372+
TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
373+
CHECKSUM=${PROJECT_NAME}-${VERSION}-checksums.txt
374+
CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}
375+
376+
377+
execute

0 commit comments

Comments
 (0)