From f47fbd0252cbdb9a81c73046432ca0e399c0db4d Mon Sep 17 00:00:00 2001 From: bjdgyc Date: Mon, 29 Jan 2024 14:30:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20release.sh=20=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{release-tag-version.yml => release.yml} | 6 +- .goreleaser.yaml | 2 +- build.sh | 54 ++------------ release.sh | 74 +++++++++++++++++++ 4 files changed, 84 insertions(+), 52 deletions(-) rename .github/workflows/{release-tag-version.yml => release.yml} (82%) create mode 100644 release.sh diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release.yml similarity index 82% rename from .github/workflows/release-tag-version.yml rename to .github/workflows/release.yml index 47dcf2b..6214a53 100644 --- a/.github/workflows/release-tag-version.yml +++ b/.github/workflows/release.yml @@ -38,10 +38,8 @@ jobs: run: | mkdir server/ui touch server/ui/index.html - sudo apt-get install -y -q gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - aarch64-linux-gnu-gcc -v - aarch64-linux-gnu-g++ -v - bash build.sh github_action + #sudo apt-get install -y -q gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + bash Z:\goweb\anylink\release.sh # Docker: # name: build-docker diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f2de675..eeb9cc6 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,7 +6,7 @@ # GOPROXY=https://goproxy.cn -# docker run -it --rm -v $PWD:/app -v /go:/go -w /app --platform=linux/arm64 +# docker run -it --rm -v $PWD:/app -v /go:/go -w /app --platform=linux/arm64 golang:alpine3.19 # docker run -it --rm -v $PWD:/app -v /go:/go -w /app goreleaser/goreleaser-cross build --skip=validate --clean --debug diff --git a/build.sh b/build.sh index 55bd8d0..f09945d 100644 --- a/build.sh +++ b/build.sh @@ -1,7 +1,5 @@ #!/bin/bash -github_action=$1 - set -x function RETVAL() { rt=$1 @@ -14,22 +12,16 @@ function RETVAL() { #当前目录 cpath=$(pwd) -#ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'` ver=$(cat version) echo "当前版本 $ver" echo "编译前端项目" cd $cpath/web + #国内可替换源加快速度 #npx browserslist@latest --update-db -if [ "$github_action" == "github_action" ]; then - yarn install -else - yarn install --registry=https://registry.npmmirror.com -fi - +yarn install --registry=https://registry.npmmirror.com yarn run build - RETVAL $? echo "编译二进制文件" @@ -37,49 +29,17 @@ cd $cpath/server rm -rf ui cp -rf $cpath/web/ui . -flags="-v -trimpath -tags osusergo,netgo,sqlite_omit_load_extension" +# -tags osusergo,netgo,sqlite_omit_load_extension +flags="-v -trimpath" ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date --iso-8601=seconds)" -if [ "$github_action" == "github_action" ]; then - echo "github_action" -else - #国内可替换源加快速度 - export GOPROXY=https://goproxy.io - go mod tidy - go build -o anylink "$flags" -ldflags "$ldflags" - exit 0 -fi - -#github action +#国内可替换源加快速度 +export GOPROXY=https://goproxy.io go mod tidy -go build -o anylink_amd64 $flags -ldflags "$ldflags" - -#arm64交叉编译 -CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ go build -o anylink_arm64 $flags -ldflags "$ldflags" - -./anylink_amd64 -v -./anylink_arm64 -v - -exit 0 +go build -o anylink "$flags" -ldflags "$ldflags" cd $cpath -echo "整理部署文件" -deploy="anylink-deploy" -rm -rf $deploy ${deploy}.tar.gz -mkdir $deploy -mkdir $deploy/log - -cp -r server/anylink $deploy -cp -r server/bridge-init.sh $deploy -cp -r server/conf $deploy - -cp -r systemd $deploy -cp -r LICENSE $deploy -cp -r home $deploy - -tar zcvf ${deploy}.tar.gz $deploy - #注意使用root权限运行 #cd anylink-deploy #sudo ./anylink --conf="conf/server.toml" diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..9d43bf9 --- /dev/null +++ b/release.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +#github action release.sh + +set -x +function RETVAL() { + rt=$1 + if [ $rt != 0 ]; then + echo $rt + exit 1 + fi +} + +#当前目录 +cpath=$(pwd) + +#ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'` +ver=$(cat version) +echo "当前版本 $ver" + +echo "编译前端项目" +cd $cpath/web +#国内可替换源加快速度 +#npx browserslist@latest --update-db +#yarn install +#yarn run build +#RETVAL $? +#rm -rf $cpath/server/ui +#cp -rf $cpath/web/ui . $cpath/server/ui + +echo "编译二进制文件" +cd $cpath/server + +# -tags osusergo,netgo,sqlite_omit_load_extension +flags="-v -trimpath" +ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date --iso-8601=seconds)" + +#github action +gopath=$(go env GOPATH) +go mod tidy + +#使用 musl-dev 编译 +docker run -it --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/amd64 \ + golang:1.20-alpine3.19 go build -o anylink_amd64 $flags -ldflags "$ldflags" +#arm64交叉编译 +docker run -it --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/arm64 \ + golang:1.20-alpine3.19 go build -o anylink_amd64 $flags -ldflags "$ldflags" + +./anylink_amd64 -v +./anylink_arm64 -v + +exit 0 + +cd $cpath + +echo "整理部署文件" +deploy="anylink-deploy" +rm -rf $deploy ${deploy}.tar.gz +mkdir $deploy +mkdir $deploy/log + +cp -r server/anylink $deploy +cp -r server/bridge-init.sh $deploy +cp -r server/conf $deploy + +cp -r systemd $deploy +cp -r LICENSE $deploy +cp -r home $deploy + +tar zcvf ${deploy}.tar.gz $deploy + +#注意使用root权限运行 +#cd anylink-deploy +#sudo ./anylink --conf="conf/server.toml"