Commit ee707a01 authored by wei.xuan's avatar wei.xuan

feat: uodate build script

parent d329a542
.idea .idea
echo-cli echo-cli
dist/config.yaml dist/config.yaml
\ No newline at end of file dist
majora-cli
\ No newline at end of file
project_name: majora-go
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- netbsd
- openbsd
goarch:
- amd64
- arm
- arm64
goarm:
- 6
- 7
binary: majora-cli
ignore:
- goos: darwin
goarch: 386
- goos: windows
goarch: 386
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
asmflags:
- all=-trimpath={{.Env.GOPATH}}
gcflags:
- all=-trimpath={{.Env.GOPATH}}
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
UNAME := $(shell uname)
# LDFLAGS := '-s -w --extldflags "-static -fpic"'
LDFLAGS := '-s -w --extldflags "-fpic"'
# BUILD_MODE := '--buildmode=c-archive'
BUILD_MODE := '--buildmode=c-shared'
BUILD_CMD := go build -trimpath -ldflags $(LDFLAGS) $(BUILD_MODE)
LIB := lib/sdk.go
# linux 64
cc_linux := /home/xuan/musl-cross/x86_64-linux/bin/x86_64-linux-musl-gcc
cxx_linux := /home/xuan/musl-cross/x86_64-linux/bin/x86_64-linux-musl-g++
# arm64
cc_aarch64 := /home/xuan/musl-cross/aarch64-linux/bin/aarch64-linux-musl-gcc
cxx_aarch64 := /home/xuan/musl-cross/aarch64-linux/bin/aarch64-linux-musl-g++
# 树莓派
cc_armhf_linux := /home/xuan/musl-cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc
cxx_armhf_linux := /home/xuan/musl-cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++
# armv6
cc_armv6_linux := /home/xuan/musl-cross/armv6-linux-musleabi/bin/armv6-linux-musleabi-gcc
cxx_armv6_linux := /home/xuan/musl-cross/armv6-linux-musleabi/bin/armv6-linux-musleabi-g++
# win64
cc_win := /home/xuan/musl-cross/i686-w64-mingw32/bin/i686-w64-mingw32-gcc
cxx_win := /home/xuan/musl-cross/i686-w64-mingw32/bin/i686-w64-mingw32-g++
buildlocal:
CGO_ENABLE=0 go build -trimpath -ldflags "-w -s -X main.Version=v0.0.1" -o majora-cli
releaselocal:
goreleaser build --rm-dist --snapshot --single-target
releaseall:
goreleaser build --rm-dist --snapshot
sdk_mac:
CGO_ENABLED=1 go build -trimpath -ldflags $(LDFLAGS) $(BUILD_MODE) -o lib/libmajora_mac.so $(LIB)
sdk_linux:
CGO_ENABLED=1 CC=${cc_linux} CXX=${cxx_linux} GOOS=linux GOARCH=amd64 $(BUILD_CMD) -o lib/libmajora_linux_amd64.so $(LIB)
sdk_aarch64:
CGO_ENABLED=1 CC=${cc_aarch64} CXX=${cxx_aarch64} GOOS=linux GOARCH=arm64 $(BUILD_CMD) -o lib/libmajora_linux_aarch64.so $(LIB)
sdk_armv6:
CGO_ENABLED=1 CC=${cc_armv6_linux} CXX=${cxx_armv6_linux} GOOS=linux GOARCH=arm $(BUILD_CMD) -o lib/libmajora_linux_armv6.so $(LIB)
sdk_armhf:
CGO_ENABLED=1 CC=${cc_armhf_linux} CXX=${cxx_armhf_linux} GOOS=linux GOARCH=arm $(BUILD_CMD) -o lib/libmajora_linux_aarch64.so $(LIB)
sdk_win:
CGO_ENABLED=1 CC=${cc_win} CXX=${cxx_win} GOOS=windows GOARCH=amd64 $(BUILD_CMD) -o lib/libmajora_win_amd64.dll $(LIB)
clean:
rm -fr dist
rm -fr majora-cli
rm -fr libmajora.so
rm -fr libmajora.h
#!/usr/bin/env bash
export GO111MODULE="on"
export GOPROXY="https://goproxy.cn,https://goproxy.io,direct"
export CGO_ENABLE=1
DATE=$(date "+%Y%m%d-%H%M%S")
mkdir "$1"
BINARY=majora
VERSION=$1
GOVER=latest
BUILDINFO="-X main.Version=$VERSION -X main.Date=$DATE"
EXTFLAG="--extldflags \"-static -fpic\""
OUTDIR=dist/$1
OUT=$OUTDIR/$BINARY-$1
TOKEN=Aau6PvRI4o0OTYrgpQHzxG7qEDkADx6CaUAJV2
TOKENONLINE=456734sdlasysdhf293r23r
echo "$OUTDIR"
echo "$OUT"
build_local() {
echo "build local..."
go build -a -trimpath -ldflags "-w -s $BUILDINFO" -o $BINARY
if [ $? -ne 0 ]; then
echo "build local fail"
exit 1
fi
echo "build success"
}
build_release() {
xgo -x -out "$OUT" -goproxy $GOPROXY -go $GOVER -ldflags="-s -w $EXTFLAG $BUILDINFO" /home/xuan/code/gcode/majora-go
}
upload() {
sudo chown -R xuan dist
cd "$OUTDIR"
for file in `ls | grep majora`; do
newfile=$(echo "${file}" | sed 's/-10.12//g;s/-4.0//g')
echo "uploading $newfile ..."
curl -F file=@"${file}" -F filename="${newfile}" -F token=$TOKEN http://81.70.224.147:10010/version
curl -F file=@"${file}" -F filename="${newfile}" -F token=$TOKENONLINE https://oss.virjar.com/majora/bin
done
touch latest.txt
echo "$VERSION" > latest.txt
curl -F file=@latest.txt -F token=$TOKEN http://81.70.224.147:10010/version
curl -F file=@latest.txt -F token=$TOKENONLINE https://oss.virjar.com/majora/bin
}
build_local
build_release
upload
\ No newline at end of file
...@@ -30,7 +30,7 @@ var ( ...@@ -30,7 +30,7 @@ var (
var ( var (
Version string Version string
date = "unknown" Date string
) )
func init() { func init() {
...@@ -69,8 +69,6 @@ func initPprof() { ...@@ -69,8 +69,6 @@ func initPprof() {
} }
func update() { func update() {
logger.Debug().Msgf("check update %v ...", disableUpdate)
if disableUpdate { if disableUpdate {
return return
} }
...@@ -83,7 +81,7 @@ func update() { ...@@ -83,7 +81,7 @@ func update() {
func main() { func main() {
initPprof() initPprof()
logger.SetLogLevel(logLevel) logger.SetLogLevel(logLevel)
logger.Info().Msgf("current Version %s, build at %s", Version, date) logger.Info().Msgf("current Version %s, build at %s", Version, Date)
update() update()
logger.Info().Msgf("hostinfo os:%s, arch:%s", runtime.GOOS, runtime.GOARCH) logger.Info().Msgf("hostinfo os:%s, arch:%s", runtime.GOOS, runtime.GOARCH)
client.NewClient(client.WithNatServerAddr(natServer), client.NewClient(client.WithNatServerAddr(natServer),
......
...@@ -5,7 +5,7 @@ const ( ...@@ -5,7 +5,7 @@ const (
) )
const ( const (
UpdateServer = "http://172.16.28.131:8888" UpdateServer = "http://81.70.224.147:10010"
Latest = "latest.txt" Latest = "latest.txt"
UpdateBinaryPath = "/version/" UpdateBinaryPath = "/version/"
// VersionTpl majora-v0.0.1-linux-arm64 name-version-os-arch // VersionTpl majora-v0.0.1-linux-arm64 name-version-os-arch
......
#!/usr/bin/env bash
cd `dirname $0`
# only runing on virjar PC
cp -r dist/* ~/Desktop/file_server/majora/bin/
cp -r lib/*.h ~/Desktop/file_server/majora/sdk/
cp -r lib/*.so ~/Desktop/file_server/majora/sdk/
File deleted
...@@ -80,9 +80,8 @@ func restart() { ...@@ -80,9 +80,8 @@ func restart() {
logger.Debug().Msgf("restart ... %+v", cmd) logger.Debug().Msgf("restart ... %+v", cmd)
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
os.Exit(1) logger.Error().Msgf("restart error %+v", err)
} }
os.Exit(0)
} }
func UpdateCore(name, latestVer, targetFile string) (bool, error) { func UpdateCore(name, latestVer, targetFile string) (bool, error) {
...@@ -110,11 +109,9 @@ func UpdateCore(name, latestVer, targetFile string) (bool, error) { ...@@ -110,11 +109,9 @@ func UpdateCore(name, latestVer, targetFile string) (bool, error) {
} }
func getLatestVersion() (string, error) { func getLatestVersion() (string, error) {
url := common.UpdateServer + common.UpdateBinaryPath + common.Latest url := common.UpdateServer + common.UpdateBinaryPath + common.Latest
logger.Debug().Msgf("getLatestVersion from %s", url) logger.Debug().Msgf("getLatestVersion from %s", url)
resp, err := http.DefaultClient.Get(url) resp, err := http.DefaultClient.Get(url) //nolint:bodyclose
if err != nil || resp == nil { if err != nil || resp == nil {
return "", err return "", err
} }
...@@ -142,6 +139,12 @@ func needUpdate(curVer string) (bool, string) { ...@@ -142,6 +139,12 @@ func needUpdate(curVer string) (bool, string) {
logger.Error().Msgf("getLatestVersion with error %s", err.Error()) logger.Error().Msgf("getLatestVersion with error %s", err.Error())
return false, "" return false, ""
} }
if len(latestVer) == 0 {
logger.Error().Msgf("getLatestVersion with empty")
return false, ""
}
if curVer[0] == 'v' || curVer[0] == 'V' { if curVer[0] == 'v' || curVer[0] == 'V' {
curVer = curVer[1:] curVer = curVer[1:]
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment