forked from coreos/butane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·78 lines (67 loc) · 2.25 KB
/
test
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
#!/usr/bin/env bash
set -euo pipefail
SRC=$(find . -name '*.go' -not -path "./vendor/*")
echo "checking gofmt"
res=$(gofmt -d $SRC)
if [ -n "$res" ]; then
echo "$res"
exit 1
fi
echo "checking govet"
PKG_VET=$(go list ./... | grep --invert-match vendor)
# tests widely use unkeyed fields in composite literals. golangci-lint
# in CI does a more nuanced check.
go vet -composites=false $PKG_VET
source ./build
echo "Running tests"
go test ./... -cover
csplit=""
head=""
if [ "$(go env GOOS)" = linux ]; then
csplit="csplit"
head="head"
elif [ "$(go env GOOS)" = darwin ]; then
# macOS has BSD versions of csplit and head that behave differently;
# check whether brew/macports supplied GNU versions exist
if hash gcsplit &> /dev/null; then
csplit="gcsplit"
fi
if hash ghead &> /dev/null; then
head="ghead"
fi
elif [ "$(go env GOOS)" = windows ]; then
# if we find a Bash on Windows we can comparatively safely assume
# Git Bash with GNU utils is being used
csplit="csplit"
head="head"
fi
if [ -n "${csplit}" ] && [ -n "${head}" ]; then
echo "Checking docs"
shopt -s nullglob
mkdir tmpdocs
trap 'rm -r tmpdocs' EXIT
# Create files-dir contents expected by configs
mkdir -p tmpdocs/files-dir/tree
touch tmpdocs/files-dir/{config.ign,ca.pem,example.conf,example.service,file,file-epilogue,local-file3}
echo "ssh-rsa AAAA" > tmpdocs/files-dir/id_rsa.pub
echo "ssh-ed25519 AAAA" > tmpdocs/files-dir/id_ed25519.pub
for doc in docs/*md
do
echo "Checking ${doc}"
# split each doc into a bunch of tmpfiles then run butane on them
sed -n '/^<!-- butane-config -->/,/^```$/ p' <"${doc}" \
| ${csplit} - '/<!-- butane-config -->/' '{*}' -z --prefix "tmpdocs/config_$(basename ${doc%.*})_" -q
for i in tmpdocs/config_*
do
echo "Checking ${i}"
tail -n +3 "${i}" | ${head} -n -1 \
| "${BIN_PATH}/${NAME}" --check --strict --files-dir tmpdocs/files-dir \
|| (cat -n "${i}" && false)
done
rm -f tmpdocs/config_*
done
else
# Avoid dealing with presence/behavior of csplit and head
echo "skipping docs check because GNU csplit and head are unavailable"
fi
echo ok