-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild_inner.sh
More file actions
110 lines (93 loc) · 3.77 KB
/
Copy pathbuild_inner.sh
File metadata and controls
110 lines (93 loc) · 3.77 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
# This file is called by build.sh inside the goreleaser Docker image
set -eu
do_test_and_build() {
echo "-- Checking goreleaser.yml file"
goreleaser check "${GORELEASER_CONFIG}"
if [ "${SKIP_GO_TEST}" != "1" ]; then
echo "--- Runnning Go test..."
go test ./...
# When the Go cache isn't persisted between runs, the build cache produced
# by the tests is never reused by the build below (test and build caches
# don't overlap). Drop it before building to lower peak disk usage
# (~1.7 GiB) on CI.
if [ "${SKIP_GO_BUILD}" != "1" ] && [ "${GO_CACHE_PERSISTED:-1}" != "1" ]; then
echo "--- Dropping Go test cache (not persisted between runs)"
go clean -cache
fi
fi
if [ "${SKIP_GO_BUILD}" != "1" ]; then
echo "--- Building Go binary..."
GORELEASER_SKIP=""
if [ "$TARGET_TO_BUILD" != "release" ] && [ "${GOOS}" != "linux" ]; then
GORELEASER_SKIP="--skip=nfpm"
fi
goreleaser release --config "${GORELEASER_CONFIG}" --clean --snapshot --parallelism 2 --timeout 45m ${GORELEASER_SKIP}
fi
if [ "$TARGET_TO_BUILD" != "release" ] && [ "${GOOS}" = "linux" ]; then
# Ensure binary for other arch exists, because Docker image building assume glouton binaries for all arch exists.
createEmptyGloutonBinary() {
local dirname
local target="$1"
if [ ! -e "$target" ]; then
dirname="$(dirname "$target")"
if [ ! -d "$dirname" ]; then
mkdir "$dirname"
fi
touch "$target"
fi
}
createEmptyGloutonBinary dist/glouton_linux_amd64_v1/glouton
createEmptyGloutonBinary dist/glouton_linux_arm64_v8.0/glouton
createEmptyGloutonBinary dist/glouton_linux_arm_6/glouton
fi
}
create_single_target_config() {
TARGET="${GOOS}_${GOARCH}"
if [ "$GOARCH" = "arm" ]; then
TARGET="${GOOS}_arm_6"
fi
TEMPLATE_CONFIG=".goreleaser.yml"
if [ "$TARGET_TO_BUILD" = "single-target-race" ]; then
TEMPLATE_CONFIG=".goreleaser-race.yml"
elif [ "$TARGET_TO_BUILD" = "single-target-debug" ] || [ "$TARGET_TO_BUILD" = "single-target-debug-no-optimize" ]; then
TEMPLATE_CONFIG=".goreleaser-dbg.yml"
fi
# Removes all targets from .goreleaser.yml and re-add only $TARGET.
# This result in "--single-target" (option of `goreleaser build`) but working
# on `gorelease release`.
awk -v target="$TARGET" '
/^[[:space:]]+targets:/ {
match($0, /^[[:space:]]+/)
indent = substr($0, 1, RLENGTH)
print indent "targets:"
print indent " - " target
in_targets = 1
next
}
in_targets && /^[[:space:]]+-/ { next }
{ in_targets = 0; print }
' ${TEMPLATE_CONFIG} > work/goreleaser-single-target.yml
if [ "$TARGET_TO_BUILD" = "single-target-debug-no-optimize" ]; then
sed -i "s/# gcflags: \[/gcflags: \[/" work/goreleaser-single-target.yml
fi
}
if [ "$TARGET_TO_BUILD" != "release" ]; then
# For non release build, we need to alter goreleaser.yml file, because we want
# to do "goreleaser release --single-target", but it's not supported.
# So we take input .goreleaser.yml and remove all targets but the one we want.
GORELEASER_CONFIG="work/goreleaser-single-target.yml"
GOOS="${GOOS:-$(go env GOOS)}"
GOARCH="${GOARCH:-$(go env GOARCH)}"
create_single_target_config
else
GORELEASER_CONFIG=".goreleaser.yml"
fi
if [ "${TARGET_TO_BUILD}" = "interactive-shell" ]; then
echo "--- Opening interactive shell in build container"
# Reset TARGET_TO_BUILD to single-target-debug, so you could easily run a build.
echo " * If you need to do a build (which will ensure dependencies are fetched), you can run"
echo "sh build_inner.sh"
exec bash
fi
do_test_and_build