bashhub-server/scripts/build.sh

86 lines
2.6 KiB
Bash
Raw Normal View History

2020-02-10 09:35:51 +08:00
#!/usr/bin/env bash
# Copyright © 2020 nicksherron <nsherron90@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
2020-02-10 09:35:51 +08:00
set -eou pipefail
version="$(git tag | sort --version-sort -r | head -1)"
last_tag_ref=$(git log --decorate | grep $version | cut -d' ' -f 2 | head -c 7)
last_commit_ref="$(git log -1 --oneline | cut -d' ' -f 1)"
commit=$(git rev-parse HEAD)
build_date=$( date '+%Y-%m-%d-%H:%M:%S')
echo $version $last_tag_ref $last_commit_ref
if [ ! $last_tag_ref == $last_commit_ref ]; then
echo "last commit is not last tag"
echo "last tag: $version"
fi
rm -rf dist.bk/
[ -d dist/ ] && mv dist/ dist.bk/
export GO111MODULE=on
xgo \
2020-02-10 09:37:41 +08:00
-out="bashhub-server-${version}" \
2020-02-10 09:35:51 +08:00
--targets="windows/*,darwin/amd64,linux/386,linux/amd64" \
--dest=dist \
2020-02-10 09:37:41 +08:00
-ldflags "-X github.com/nicksherron/bashhub-server/cmd.Version=${version}
2020-02-10 09:49:00 +08:00
-X github.com/nicksherron/bashhub-server/cmd.GitCommit=${commit}
2020-02-10 09:37:41 +08:00
-X github.com/nicksherron/bashhub-server/cmd.BuildDate=${build_date}" \
2020-02-10 09:35:51 +08:00
-v -x \
2020-02-10 09:37:41 +08:00
github.com/nicksherron/bashhub-server
2020-02-10 09:35:51 +08:00
sudo chown -R $USER: dist/
2020-02-10 09:37:41 +08:00
darwin_amd64=bashhub-server_${version}_darwin_amd64
linux_386=bashhub-server_${version}_linux_386
linux_amd64=bashhub-server_${version}_linux_amd64
windows_386=bashhub-server_${version}_windows_386
windows_amd64=bashhub-server_${version}_windows_amd64
2020-02-10 09:35:51 +08:00
mkdir dist/{$darwin_amd64,$linux_386,$linux_amd64,$windows_386,$windows_amd64}
pushd dist
2020-02-10 09:37:41 +08:00
mv bashhub-server-${version}-darwin-10.6-amd64 ${darwin_amd64}/bashhub-server \
2020-02-10 09:35:51 +08:00
&& tar -czvf ${darwin_amd64}.tar.gz ${darwin_amd64}
2020-02-10 09:37:41 +08:00
mv bashhub-server-${version}-linux-386 ${linux_386}/bashhub-server \
2020-02-10 09:35:51 +08:00
&& tar czvf ${linux_386}.tar.gz ${linux_386}
2020-02-10 09:37:41 +08:00
mv bashhub-server-${version}-linux-amd64 ${linux_amd64}/bashhub-server \
2020-02-10 09:35:51 +08:00
&& tar czvf ${linux_amd64}.tar.gz ${linux_amd64}
2020-02-10 09:37:41 +08:00
mv bashhub-server-${version}-windows-4.0-386.exe ${windows_386}/bashhub-server \
2020-02-10 09:35:51 +08:00
&& zip -r ${windows_386}.zip ${windows_386}
2020-02-10 09:37:41 +08:00
mv bashhub-server-${version}-windows-4.0-amd64.exe ${windows_amd64}/bashhub-server \
2020-02-10 09:35:51 +08:00
&& zip -r ${windows_amd64}.zip ${windows_amd64}
rm -rf {$darwin_amd64,$linux_386,$linux_amd64,$windows_386,$windows_amd64}
2020-02-10 09:37:41 +08:00
shasum -a 256 * > bashhub-server_${version}_checksums.txt
2020-02-10 09:35:51 +08:00
popd