-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·74 lines (63 loc) · 1.82 KB
/
release.sh
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
#!/usr/bin/env bash
#################################################################
#
# file: release.sh
# brief: release.sh is a script to create a github release.
# It build the release asset and the upload it to the release.
# author: tenfyzhong
# email: [email protected]
# created: 2023-01-06 11:43:12
#
#################################################################
CWD=$(pwd)
COMMAND=st2
CMD_PATH=cmd/st2
OUTPUT=${CWD}/output
VERSION_KEY=github.com/tenfyzhong/st2/cmd/st2/config.Version
VERSION=$(git describe --tags --abbrev=0 2>/dev/null)
if [ $? -ne 0 ]; then
echo 'Version not found'
exit 1
fi
GIT_TAG_MESSAGE=$(git tag -l --format='%(contents)' "$VERSION" 2>/dev/null)
gobuild() {
OS=$1
ARCH=$2
SUFFIX=""
if [ "$OS" == "windows" ]; then
SUFFIX=.exe
fi
o="${OUTPUT}/${COMMAND}-${OS}-${ARCH}${SUFFIX}"
echo "go build $o"
CGO_ENABLED=0 GOOS="$OS" GOARCH="$ARCH" go build -ldflags "-X '${VERSION_KEY}=${VERSION}'" -o "$o"
}
build() {
declare -a OS_ARRAY=(linux windows)
declare -a ARCH_ARRAY=(amd64 386 arm)
cd "${CWD}/${CMD_PATH}" || exit
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT"
go install -ldflags "-X '${VERSION_KEY}=${VERSION}'"
gobuild darwin amd64
for OS in "${OS_ARRAY[@]}"; do
for ARCH in "${ARCH_ARRAY[@]}"; do
gobuild "$OS" "$ARCH"
done
done
cd "$CWD" || exit
}
release() {
echo "gh release create $VERSION"
gh release create "$VERSION" --verify-tag -n "$GIT_TAG_MESSAGE" "$OUTPUT"/*
}
echo "Release $VERSION"
echo "========================================"
echo "Release Message"
echo "----------------------------------------"
echo "$GIT_TAG_MESSAGE"
echo "========================================"
echo "Release step:"
echo "----------------------------------------"
build
echo ""
release