forked from cloudfoundry/multiapps-cli-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·91 lines (79 loc) · 3.41 KB
/
build.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash -eux
function build() {
local version=$1
local platform=$2
local arch=$3
local plugin_name=$4
echo "building for $platform $arch"
GOOS=$platform GOARCH=$arch go build \
-ldflags "-X main.Version=${version}" \
-o "${plugin_name}"
}
function buildstatic() {
local version=$1
local platform=$2
local arch=$3
local plugin_name=$4
echo "building static for $platform $arch"
CGO_ENABLED=0 GOOS=$platform GOARCH=$arch go build -a \
-ldflags "-w -X main.Version=${version}" \
-o "${plugin_name}"
}
function movePluginsToBuildFolder() {
local folder=$1
mv $PLUGIN_NAME_NON_STATIC_WIN_32 $folder
mv $PLUGIN_NAME_NON_STATIC_WIN_64 $folder
mv $PLUGIN_NAME_NON_STATIC_LINUX_32 $folder
mv $PLUGIN_NAME_NON_STATIC_LINUX_64 $folder
mv $PLUGIN_NAME_NON_STATIC_LINUX_ARM64 $folder
mv $PLUGIN_NAME_NON_STATIC_OSX $folder
mv $PLUGIN_NAME_NON_STATIC_APPLE_ARM64 $folder
mv $PLUGIN_NAME_STATIC_WIN_32 $folder
mv $PLUGIN_NAME_STATIC_WIN_64 $folder
mv $PLUGIN_NAME_STATIC_LINUX_32 $folder
mv $PLUGIN_NAME_STATIC_LINUX_64 $folder
mv $PLUGIN_NAME_STATIC_LINUX_ARM64 $folder
mv $PLUGIN_NAME_STATIC_OSX $folder
mv $PLUGIN_NAME_STATIC_APPLE_ARM64 $folder
}
function createBuildMetadataFiles() {
local version=$1
local folder=$2
echo -n "v${version}" > ${folder}/version
grep -Pzoa "(?s)## v${version}(.*?)##" CHANGELOG.md | grep -va "##" | tr -s '\n' '\n' > ${folder}/changelog
}
script_dir="$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")")"
cd "${script_dir}"
BUILD_FOLDER=build
PLUGIN_NAME_NON_STATIC_WIN_32=multiapps-plugin-non-static.win32.exe
PLUGIN_NAME_NON_STATIC_WIN_64=multiapps-plugin-non-static.win64.exe
PLUGIN_NAME_NON_STATIC_LINUX_32=multiapps-plugin-non-static.linux32
PLUGIN_NAME_NON_STATIC_LINUX_64=multiapps-plugin-non-static.linux64
PLUGIN_NAME_NON_STATIC_LINUX_ARM64=multiapps-plugin-non-static.linuxarm64
PLUGIN_NAME_NON_STATIC_OSX=multiapps-plugin-non-static.osx
PLUGIN_NAME_NON_STATIC_APPLE_ARM64=multiapps-plugin-non-static.osxarm64
PLUGIN_NAME_STATIC_WIN_32=multiapps-plugin.win32.exe
PLUGIN_NAME_STATIC_WIN_64=multiapps-plugin.win64.exe
PLUGIN_NAME_STATIC_LINUX_32=multiapps-plugin.linux32
PLUGIN_NAME_STATIC_LINUX_64=multiapps-plugin.linux64
PLUGIN_NAME_STATIC_LINUX_ARM64=multiapps-plugin.linuxarm64
PLUGIN_NAME_STATIC_OSX=multiapps-plugin.osx
PLUGIN_NAME_STATIC_APPLE_ARM64=multiapps-plugin.osxarm64
version=$(<cfg/VERSION)
build "$version" linux 386 $PLUGIN_NAME_NON_STATIC_LINUX_32
build "$version" linux amd64 $PLUGIN_NAME_NON_STATIC_LINUX_64
build "$version" linux arm64 $PLUGIN_NAME_NON_STATIC_LINUX_ARM64
build "$version" windows 386 $PLUGIN_NAME_NON_STATIC_WIN_32
build "$version" windows amd64 $PLUGIN_NAME_NON_STATIC_WIN_64
build "$version" darwin amd64 $PLUGIN_NAME_NON_STATIC_OSX
build "$version" darwin arm64 $PLUGIN_NAME_NON_STATIC_APPLE_ARM64
buildstatic "$version" linux 386 $PLUGIN_NAME_STATIC_LINUX_32
buildstatic "$version" linux amd64 $PLUGIN_NAME_STATIC_LINUX_64
buildstatic "$version" linux arm64 $PLUGIN_NAME_STATIC_LINUX_ARM64
buildstatic "$version" windows 386 $PLUGIN_NAME_STATIC_WIN_32
buildstatic "$version" windows amd64 $PLUGIN_NAME_STATIC_WIN_64
buildstatic "$version" darwin amd64 $PLUGIN_NAME_STATIC_OSX
buildstatic "$version" darwin arm64 $PLUGIN_NAME_STATIC_APPLE_ARM64
mkdir -p $BUILD_FOLDER
createBuildMetadataFiles $version $BUILD_FOLDER
movePluginsToBuildFolder $BUILD_FOLDER