Feat: build all platform

pull/3/head
zijiren233 1 year ago
parent f84ee186d1
commit d1c05acf04

@ -30,7 +30,7 @@ jobs:
- name: Build
run: |
bash build.sh -v dev -P -p "windows/amd64,linux/amd64,linux/arm64,darwin/amd64,darwin/arm64"
bash build.sh -v dev -P -p "windows,linux,darwin"
- name: Upload artifact
uses: actions/upload-artifact@v3

@ -149,6 +149,16 @@ function CheckPlatform() {
function CheckAllPlatform() {
for platform in $(echo "$PLATFORM" | tr "," "\n"); do
if [ "$platform" == "all" ]; then
PLATFORM="all"
return 0
elif [ "$platform" == "linux" ]; then
continue
elif [ "$platform" == "darwin" ]; then
continue
elif [ "$platform" == "windows" ]; then
continue
fi
CheckPlatform "$platform"
if [ $? -ne 0 ]; then
echo "platform $platform not allowd"
@ -172,6 +182,10 @@ function Build() {
else
GOOS=$GOOS GOARCH=$GOARCH go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)-$GOOS-$GOARCH$EXT" .
fi
if [ $? -ne 0 ]; then
echo "build $GOOS/$GOARCH error"
exit 1
fi
}
function BuildSingle() {
@ -188,24 +202,31 @@ function BuildSingle() {
else
go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)$EXT" .
fi
if [ $? -ne 0 ]; then
echo "build $GOOS/$GOARCH error"
exit 1
fi
}
function BuildAll() {
if [ ! "$PLATFORM" ]; then
if [ ! "$1" ]; then
BuildSingle
return
elif [ "$PLATFORM" == "all" ]; then
PLATFORM="$ALLOWD_PLATFORM"
elif [ "$PLATFORM" == "linux" ]; then
PLATFORM="$LINUX_ALLOWED_PLATFORM"
elif [ "$PLATFORM" == "darwin" ]; then
PLATFORM="$DARWIN_ALLOWED_PLATFORM"
elif [ "$PLATFORM" == "windows" ]; then
PLATFORM="$WINDOWS_ALLOWED_PLATFORM"
else
for platform in $(echo "$1" | tr "," "\n"); do
if [ "$platform" == "all" ]; then
BuildAll "$ALLOWD_PLATFORM"
elif [ "$platform" == "linux" ]; then
BuildAll "$LINUX_ALLOWED_PLATFORM"
elif [ "$platform" == "darwin" ]; then
BuildAll "$DARWIN_ALLOWED_PLATFORM"
elif [ "$platform" == "windows" ]; then
BuildAll "$WINDOWS_ALLOWED_PLATFORM"
else
Build "$platform"
fi
done
fi
for platform in $(echo "$PLATFORM" | tr "," "\n"); do
Build "$platform"
done
}
ChToScriptFileDir
@ -213,4 +234,4 @@ Init
ParseArgs "$@"
FixArgs
InitDep
BuildAll
BuildAll "$PLATFORM"

@ -3,9 +3,7 @@ package bootstrap
import (
"errors"
"os"
"os/signal"
"sync"
"syscall"
log "github.com/sirupsen/logrus"
@ -46,37 +44,6 @@ func NewSysNotifyTask(name string, NotifyType NotifyType, task func() error) *Sy
}
}
func InitSysNotify() {
c = make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP /*1*/, syscall.SIGINT /*2*/, syscall.SIGQUIT /*3*/, syscall.SIGTERM /*15*/, syscall.SIGUSR1 /*10*/, syscall.SIGUSR2 /*12*/)
WaitCbk = func() {
once.Do(waitCbk)
}
}
func waitCbk() {
log.Info("wait sys notify")
for s := range c {
log.Infof("receive sys notify: %v", s)
switch s {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM:
tq, ok := TaskGroup.Load(NotifyTypeEXIT)
if ok {
log.Info("task: NotifyTypeEXIT running...")
runTask(tq)
}
return
case syscall.SIGUSR1, syscall.SIGUSR2:
tq, ok := TaskGroup.Load(NotifyTypeRELOAD)
if ok {
log.Info("task: NotifyTypeRELOAD running...")
runTask(tq)
}
}
log.Info("task: all done")
}
}
func runTask(tq *taskQueue) {
tq.notifyTaskLock.Lock()
defer tq.notifyTaskLock.Unlock()

@ -0,0 +1,43 @@
//go:build !windows
// +build !windows
package bootstrap
import (
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
)
func InitSysNotify() {
c = make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP /*1*/, syscall.SIGINT /*2*/, syscall.SIGQUIT /*3*/, syscall.SIGTERM /*15*/, syscall.SIGUSR1 /*10*/, syscall.SIGUSR2 /*12*/)
WaitCbk = func() {
once.Do(waitCbk)
}
}
func waitCbk() {
log.Info("wait sys notify")
for s := range c {
log.Infof("receive sys notify: %v", s)
switch s {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM:
tq, ok := TaskGroup.Load(NotifyTypeEXIT)
if ok {
log.Info("task: NotifyTypeEXIT running...")
runTask(tq)
}
return
case syscall.SIGUSR1, syscall.SIGUSR2:
tq, ok := TaskGroup.Load(NotifyTypeRELOAD)
if ok {
log.Info("task: NotifyTypeRELOAD running...")
runTask(tq)
}
}
log.Info("task: all done")
}
}

@ -0,0 +1,34 @@
package bootstrap
import (
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
)
func InitSysNotify() {
c = make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP /*1*/, syscall.SIGINT /*2*/, syscall.SIGQUIT /*3*/, syscall.SIGTERM /*15*/)
WaitCbk = func() {
once.Do(waitCbk)
}
}
func waitCbk() {
log.Info("wait sys notify")
for s := range c {
log.Infof("receive sys notify: %v", s)
switch s {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM:
tq, ok := TaskGroup.Load(NotifyTypeEXIT)
if ok {
log.Info("task: NotifyTypeEXIT running...")
runTask(tq)
}
return
}
log.Info("task: all done")
}
}
Loading…
Cancel
Save