alist/build.sh

106 lines
2.8 KiB
Bash
Raw Normal View History

2021-11-03 11:51:19 +00:00
#!/bin/bash
2021-11-09 08:46:03 +00:00
if [ "$1" == "web" ]; then
git clone https://github.com/Xhofe/alist-web.git
cd alist-web || exit
yarn
yarn build
2021-11-09 11:35:46 +00:00
mv dist/* ../public
2021-11-09 08:46:03 +00:00
cd ..
exit 0
fi
2021-11-09 13:36:27 +00:00
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,https://goproxy.io,direct
2021-11-09 08:46:03 +00:00
if [ "$1" == "docker" ]; then
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
2021-11-09 09:54:38 +00:00
gitTag=$(git describe --long --tags --dirty --always)
2021-11-09 08:46:03 +00:00
ldflags="\
-w -s \
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
"
go build -o ./bin/alist -ldflags="$ldflags" alist.go
exit 0
fi
2021-11-03 11:51:19 +00:00
2021-11-05 11:03:54 +00:00
cd alist-web || exit
webCommit=$(git log --pretty=format:"%h" -1)
echo "web commit id: $webCommit"
yarn
if [ "$1" == "release" ]; then
yarn build --base="https://cdn.jsdelivr.net/gh/Xhofe/alist-web@cdn/v2/$webCommit"
mv dist/assets ..
else
yarn build
fi
cd ..
cd alist
2021-11-03 11:51:19 +00:00
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
2021-11-09 09:54:38 +00:00
gitTag=$(git describe --long --tags --dirty --always)
2021-11-03 11:51:19 +00:00
2021-11-04 10:42:27 +00:00
echo "build version: $gitTag"
2021-11-03 11:51:19 +00:00
ldflags="\
-w -s \
2021-11-04 05:23:17 +00:00
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
2021-11-03 11:51:19 +00:00
"
cp -R ../alist-web/dist/* public
2021-11-04 05:23:17 +00:00
if [ "$1" == "release" ]; then
xgo -out alist -ldflags="$ldflags" .
else
2021-11-13 16:30:15 +00:00
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" .
2021-11-04 05:23:17 +00:00
fi
2021-11-03 11:51:19 +00:00
mkdir "build"
mv alist-* build
cd build || exit
upx -9 ./*
find . -type f -print0 | xargs -0 md5sum > md5.txt
2021-11-04 13:34:52 +00:00
cat md5.txt
2021-11-03 11:51:19 +00:00
# compress file (release)
if [ "$1" == "release" ]; then
mkdir compress
mv md5.txt compress
for i in `find . -type f -name "$appName-linux-*"`
do
tar -czvf compress/"$i".tar.gz "$i"
done
for i in `find . -type f -name "$appName-darwin-*"`
do
tar -czvf compress/"$i".tar.gz "$i"
done
for i in `find . -type f -name "$appName-windows-*"`
do
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
done
2021-11-05 11:03:54 +00:00
fi
cd ../..
if [ "$1" == "release" ]; then
cd alist-web
git checkout cdn
mkdir "v2/$webCommit"
mv ../assets/ v2/$webCommit
git add .
git config --local user.email "i@nn.ci"
git config --local user.name "Xhofe"
git commit --allow-empty -m "upload $webCommit assets files" -a
cd ..
2021-11-03 11:51:19 +00:00
fi