2019-05-11 21:40:11 +00: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 21:40:11 +00: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 21:40:11 +00:00
|
|
|
echo "Repo: $REPO"
|
|
|
|
echo "Build assets: $ASSETS"
|
|
|
|
echo "Build binary: $BINARY"
|
|
|
|
echo "Release: $RELEASE"
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateVersion () {
|
|
|
|
from=$1
|
|
|
|
to=$2
|
|
|
|
|
2019-05-11 22:15:52 +00:00
|
|
|
echo "🎁 Updating version from \"$from\" to \"$to\""
|
2019-01-05 22:44:33 +00:00
|
|
|
sed -i.bak "s|$from|$to|g" $REPO/version/version.go
|
|
|
|
}
|
|
|
|
|
2019-05-11 21:40:11 +00:00
|
|
|
buildAssets () {
|
2019-01-05 22:44:33 +00:00
|
|
|
cd $REPO
|
2019-05-11 21:40:11 +00:00
|
|
|
rm -rf frontend/dist
|
|
|
|
rm -f http/rice-box.go
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2019-05-11 21:40:11 +00:00
|
|
|
cd $REPO/frontend
|
|
|
|
npm install
|
|
|
|
npm run build
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2019-05-11 21:40:11 +00: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 21:40:11 +00:00
|
|
|
cd $REPO/http
|
|
|
|
rm -rf rice-box.go
|
|
|
|
rice embed-go
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2019-05-11 21:40:11 +00:00
|
|
|
cd $REPO
|
|
|
|
updateVersion $untracked "($COMMIT_SHA)"
|
|
|
|
go build -a -o filebrowser
|
|
|
|
updateVersion "($COMMIT_SHA)" $untracked
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
release () {
|
|
|
|
cd $REPO
|
|
|
|
|
2019-05-11 22:15:52 +00:00
|
|
|
echo "👀 Checking semver format"
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
if [ $# -ne 1 ]; then
|
2019-05-11 22:15:52 +00: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 22:15:52 +00: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 22:15:52 +00:00
|
|
|
echo "❌ Not valid semver format. See semver.org"
|
2019-01-05 22:44:33 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-05-11 22:15:52 +00:00
|
|
|
echo "🐑 Fetching 'master' on 'frontend' and creating new tag"
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
cd frontend
|
|
|
|
git fetch --all
|
2019-05-11 22:15:52 +00:00
|
|
|
git checkout master
|
|
|
|
git tag $semver
|
|
|
|
git push --tags
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2019-05-11 22:15:52 +00:00
|
|
|
echo "🐑 Updating submodule ref to $semver"
|
2019-01-05 22:44:33 +00:00
|
|
|
updateVersion $untracked $1
|
|
|
|
git commit -am "chore: version $semver"
|
|
|
|
git tag "$1"
|
|
|
|
git push --tags
|
|
|
|
|
2019-05-11 22:15:52 +00:00
|
|
|
echo "🐑 Commiting untracked version notice..."
|
2019-01-05 22:44:33 +00:00
|
|
|
updateVersion $1 $untracked
|
|
|
|
git commit -am "chore: setting untracked version [ci skip]"
|
|
|
|
git push
|
|
|
|
|
2019-05-11 22:15:52 +00:00
|
|
|
echo "📦 Done! $semver released."
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2019-05-11 21:40:11 +00: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 21:40:11 +00:00
|
|
|
while getopts "bacr:d" o; do
|
2019-01-05 22:44:33 +00:00
|
|
|
case "${o}" in
|
|
|
|
b)
|
2019-05-11 21:40:11 +00: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 21:40:11 +00:00
|
|
|
if [ "$ASSETS" = "true" ]; then
|
|
|
|
buildAssets
|
2019-01-05 22:44:33 +00:00
|
|
|
fi
|
|
|
|
|
2019-05-11 21:40:11 +00:00
|
|
|
if [ "$BINARY" = "true" ]; then
|
|
|
|
buildBinary
|
2019-01-05 22:44:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$RELEASE" != "" ]; then
|
2019-05-11 21:40:11 +00:00
|
|
|
release $RELEASE
|
2019-01-05 22:44:33 +00:00
|
|
|
fi
|