forked from ConnorChristie/filebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwizard.sh
executable file
·140 lines (113 loc) · 2.54 KB
/
wizard.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
set -e
untracked="(untracked)"
REPO=$(cd $(dirname $0); pwd)
COMMIT_SHA=$(git rev-parse --short HEAD)
ASSETS="false"
BINARY="false"
RELEASE=""
debugInfo () {
echo "Repo: $REPO"
echo "Build assets: $ASSETS"
echo "Build binary: $BINARY"
echo "Release: $RELEASE"
}
buildAssets () {
cd $REPO
rm -rf frontend/dist
rm -f http/rice-box.go
cd $REPO/frontend
if [ "$CI" = "true" ]; then
npm ci
else
npm install
fi
npm run lint
npm run build
}
buildBinary () {
if ! [ -x "$(command -v rice)" ]; then
go install github.com/GeertJohan/go.rice/rice
fi
cd $REPO/http
rm -rf rice-box.go
rice embed-go
cd $REPO
rm -rf out
platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64" "linux/arm64" "linux/arm")
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name='filebrowser-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
env GOOS=$GOOS GOARCH=$GOARCH go build -a -o out/$output_name -ldflags "-s -w -X github.com/ConnorChristie/filebrowser/v2/version.CommitSHA=$COMMIT_SHA"
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done
}
release () {
cd $REPO
echo "👀 Checking semver format"
if [ $# -ne 1 ]; then
echo "❌ This release script requires a single argument corresponding to the semver to be released. See semver.org"
exit 1
fi
GREP="grep"
if [ -x "$(command -v ggrep)" ]; then
GREP="ggrep"
fi
semver=$(echo "$1" | $GREP -P '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)')
if [ $? -ne 0 ]; then
echo "❌ Not valid semver format. See semver.org"
exit 1
fi
go get github.com/tcnksm/ghr
ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME -c $CIRCLE_SHA1 -delete $semver ./out/
}
usage() {
echo "Usage: $0 [-a] [-c] [-b] [-r <string>]" 1>&2;
exit 1;
}
DEBUG="false"
while getopts "bacr:d" o; do
case "${o}" in
b)
ASSETS="true"
BINARY="true"
;;
a)
ASSETS="true"
;;
c)
BINARY="true"
;;
r)
RELEASE=${OPTARG}
;;
d)
DEBUG="true"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ "$DEBUG" = "true" ]; then
debugInfo
fi
if [ "$ASSETS" = "true" ]; then
buildAssets
fi
if [ "$BINARY" = "true" ]; then
buildBinary
fi
if [ "$RELEASE" != "" ]; then
release $RELEASE
fi