Files
filebrowser/wizard.sh
T

130 lines
2.1 KiB
Bash
Raw Normal View History

2019-05-11 22:40:11 +01:00
#!/usr/bin/env sh
2019-01-05 22:44:33 +00:00
set -e
untracked="(untracked)"
REPO=$(cd $(dirname $0); pwd)
2019-05-11 22:40:11 +01:00
COMMIT_SHA=$(git rev-parse --short HEAD)
ASSETS="false"
BINARY="false"
2019-01-05 22:44:33 +00:00
RELEASE=""
debugInfo () {
2019-05-11 22:40:11 +01:00
echo "Repo: $REPO"
echo "Build assets: $ASSETS"
echo "Build binary: $BINARY"
echo "Release: $RELEASE"
2019-01-05 22:44:33 +00:00
}
2019-05-11 22:40:11 +01:00
buildAssets () {
2019-01-05 22:44:33 +00:00
cd $REPO
2019-05-11 22:40:11 +01:00
rm -rf frontend/dist
rm -f http/rice-box.go
2019-01-05 22:44:33 +00:00
2019-05-11 22:40:11 +01:00
cd $REPO/frontend
2019-05-12 09:23:11 +01:00
if [ "$CI" = "true" ]; then
npm ci
else
npm install
fi
npm run lint
2019-05-11 22:40:11 +01:00
npm run build
2019-01-05 22:44:33 +00:00
}
2019-05-11 22:40:11 +01:00
buildBinary () {
if ! [ -x "$(command -v rice)" ]; then
go install github.com/GeertJohan/go.rice/rice
2019-01-05 22:44:33 +00:00
fi
2019-05-11 22:40:11 +01:00
cd $REPO/http
rm -rf rice-box.go
rice embed-go
2019-01-05 22:44:33 +00:00
2019-05-11 22:40:11 +01:00
cd $REPO
2019-05-12 21:08:43 +01:00
go build -a -o filebrowser -ldflags "-s -w -X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$COMMIT_SHA"
2019-01-05 22:44:33 +00:00
}
release () {
cd $REPO
2019-05-11 23:15:52 +01:00
echo "👀 Checking semver format"
2019-01-05 22:44:33 +00:00
if [ $# -ne 1 ]; then
2019-05-11 23:15:52 +01:00
echo "❌ This release script requires a single argument corresponding to the semver to be released. See semver.org"
2019-01-05 22:44:33 +00:00
exit 1
fi
2019-05-11 23:15:52 +01:00
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*)')
2019-01-05 22:44:33 +00:00
if [ $? -ne 0 ]; then
2019-05-11 23:15:52 +01:00
echo "❌ Not valid semver format. See semver.org"
2019-01-05 22:44:33 +00:00
exit 1
fi
2019-05-12 09:23:52 +01:00
echo "🧼 Tidying up go modules"
go mod tidy
2019-05-12 21:08:43 +01:00
echo "🐑 Creating a new commit for the new release"
git commit --allow-empty -am "chore: version $semver"
2019-01-05 22:44:33 +00:00
git tag "$1"
2019-05-11 23:22:05 +01:00
git push
2019-05-11 23:50:17 +01:00
git push --tags origin
2019-01-05 22:44:33 +00:00
2019-05-11 23:15:52 +01:00
echo "📦 Done! $semver released."
2019-01-05 22:44:33 +00:00
}
usage() {
2019-05-11 22:40:11 +01:00
echo "Usage: $0 [-a] [-c] [-b] [-r <string>]" 1>&2;
2019-01-05 22:44:33 +00:00
exit 1;
}
DEBUG="false"
2019-05-11 22:40:11 +01:00
while getopts "bacr:d" o; do
2019-01-05 22:44:33 +00:00
case "${o}" in
b)
2019-05-11 22:40:11 +01:00
ASSETS="true"
BINARY="true"
;;
a)
ASSETS="true"
;;
c)
BINARY="true"
2019-01-05 22:44:33 +00:00
;;
r)
RELEASE=${OPTARG}
;;
d)
DEBUG="true"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ "$DEBUG" = "true" ]; then
debugInfo
fi
2019-05-11 22:40:11 +01:00
if [ "$ASSETS" = "true" ]; then
buildAssets
2019-01-05 22:44:33 +00:00
fi
2019-05-11 22:40:11 +01:00
if [ "$BINARY" = "true" ]; then
buildBinary
2019-01-05 22:44:33 +00:00
fi
if [ "$RELEASE" != "" ]; then
2019-05-11 22:40:11 +01:00
release $RELEASE
2019-01-05 22:44:33 +00:00
fi