Skip to content

Commit

Permalink
Add build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
yakumo-saki committed Jul 31, 2022
1 parent 02fd108 commit 7e001de
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
b-route-reader-go
__debug_bin
.env
build

# Binaries for programs and plugins
*.exe
Expand Down
59 changes: 59 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash -eu

SCRIPT_DIR=$(cd $(dirname $0); pwd)

# Get version from global/version.go
VERSION=`cat ./src/global/version.go | grep -o "Version.*\".*\"" | sed -e 's/.*=\s//g' -e 's/"//g'`
COMMIT=`git rev-parse --short HEAD`
if ! git diff --quiet; then
COMMIT="${COMMIT}-working"
fi

BIN_BASENAME=b-route-reader-go
ENTRYPOINT=main.go

BUILD_DIR=./build
BIN_DIR=${SCRIPT_DIR}/${BUILD_DIR}/bin
WORK_DIR=${SCRIPT_DIR}/${BUILD_DIR}/work
RELEASE_DIR=${SCRIPT_DIR}/${BUILD_DIR}/release

# MAIN
sed -i src/global/version.go -e 's/GitBuild = ".*"/GitBuild = "$COMMIT"/g'

# delete build dir
rm -rf ${BUILD_DIR}

mkdir -p ${BIN_DIR}
mkdir -p ${RELEASE_DIR}
mkdir -p ${WORK_DIR}

cp LICENSE ${WORK_DIR}
cp README.md ${WORK_DIR}

function build_unixlike () {
# $1 OS $2 ARCH
echo Building $1 $2 binary

FINAL_PATH=${RELEASE_DIR}/${BIN_BASENAME}_${VERSION}_$1_$2.tar.gz
GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o ${BIN_DIR}/${BIN_BASENAME} ${ENTRYPOINT}

# copy bin to work
cp ${BIN_DIR}/${BIN_BASENAME} ${WORK_DIR}/

# copyback bin
cp ${BIN_DIR}/${BIN_BASENAME} ${BIN_DIR}/${BIN_BASENAME}_$1_$2

ORG_DIR=`pwd`
cd ${WORK_DIR}
tar -cvzf ${FINAL_PATH} --exclude *.tar.gz ./*
cd ${ORG_DIR}

echo "done => ${FINAL_PATH}"
}

# Unixlike
build_unixlike linux amd64
build_unixlike linux arm
build_unixlike linux arm64

git checkout src/global/version.go
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/yakumo-saki/b-route-reader-go/src/bp35a1"
"github.com/yakumo-saki/b-route-reader-go/src/config"
"github.com/yakumo-saki/b-route-reader-go/src/global"
"github.com/yakumo-saki/b-route-reader-go/src/logger"
)

Expand All @@ -28,7 +29,8 @@ func run() int {
config.Initialize()
logger.Initiallize()

log.Info().Msg("Start")
log.Info().Msgf("Version %s. Build %s", global.Version, global.GitBuild)
log.Info().Msgf("%s", global.Url)
err := bp35a1.Connect()
if err != nil {
log.Err(err).Msg("Serial port open error. Exiting.")
Expand Down

0 comments on commit 7e001de

Please # to comment.