forked from filebrowser/filebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwizard.sh
executable file
Β·130 lines (104 loc) Β· 2.15 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
#!/usr/bin/env sh
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
pnpm ci
else
pnpm install
fi
# pnpm run lint
pnpm 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
CGO_ENABLED=0 GOOS=linux go build -a -o filebrowser -ldflags "-s -w -X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$COMMIT_SHA"
}
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
echo "π§Ό Tidying up go modules"
go mod tidy
echo "π Creating a new commit for the new release"
git commit --allow-empty -am "chore: version $semver"
git tag "$1"
git push
git push --tags origin
echo "π¦ Done! $semver released."
}
usage() {
echo "Usage: $0 [-a] [-c] [-b] [-r <string>]" 1>&2
exit 1
}
DEBUG="false"
[ $# -ne 1 ] && usage
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