-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·55 lines (46 loc) · 1.23 KB
/
build.sh
File metadata and controls
executable file
·55 lines (46 loc) · 1.23 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
#!/usr/bin/env bash
set -euo pipefail
APP="simpleauth"
FILE_VERSION=$(cat VERSION 2>/dev/null | tr -d '[:space:]')
GIT_DIRTY=$(git diff --quiet 2>/dev/null && echo "" || echo "-dirty")
VERSION="${VERSION:-${FILE_VERSION:-0.0.0}${GIT_DIRTY}}"
BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS="-s -w -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME}"
OUT_DIR="dist"
# Platforms: os/arch pairs
PLATFORMS=(
"linux/amd64"
"linux/arm64"
"darwin/amd64"
"darwin/arm64"
"windows/amd64"
)
echo "Building ${APP} ${VERSION}"
echo "---"
rm -rf "${OUT_DIR}"
mkdir -p "${OUT_DIR}"
for platform in "${PLATFORMS[@]}"; do
GOOS="${platform%/*}"
GOARCH="${platform#*/}"
output="${OUT_DIR}/${APP}-${GOOS}-${GOARCH}"
if [ "${GOOS}" = "windows" ]; then
output="${output}.exe"
fi
echo " ${GOOS}/${GOARCH} -> ${output}"
CGO_ENABLED=0 GOOS="${GOOS}" GOARCH="${GOARCH}" go build \
-ldflags "${LDFLAGS}" \
-trimpath \
-o "${output}" \
.
done
echo "---"
# Generate checksums
cd "${OUT_DIR}"
if command -v sha256sum &>/dev/null; then
sha256sum ${APP}-* > checksums.txt
elif command -v shasum &>/dev/null; then
shasum -a 256 ${APP}-* > checksums.txt
fi
cd ..
echo "Done. Artifacts in ${OUT_DIR}/"
ls -lh "${OUT_DIR}/"