-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix:go编译选项去掉-i,新增version文件 #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
***************************************************** | ||
# DESC : echo stream parser | ||
# AUTHOR : Alex Stocks | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2016-09-04 13:08 | ||
# FILE : readwriter.go | ||
***************************************************** | ||
*/ | ||
|
||
package main | ||
|
||
var ( | ||
Version = "1.0.0" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,28 +11,28 @@ | |
|
||
rm -rf target/ | ||
|
||
PROJECT_HOME=`pwd` | ||
PROJECT_HOME=$(pwd) | ||
TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} | ||
|
||
TARGET_SBIN_NAME=${TARGET_EXEC_NAME} | ||
version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` | ||
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') | ||
if [[ ${GOOS} == "windows" ]]; then | ||
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe | ||
fi | ||
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} | ||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||
# GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 | ||
# GFLAGS=-gcflags "-N -l" -race -v | ||
# GFLAGS="-gcflags \"-N -l\" -v" | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for directory changes The cd commands should handle potential failures to prevent script from continuing in wrong directory. Apply these changes: - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1
+ GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME}
+ cd - || exit 1
- cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1
+ GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME}
+ cd - || exit 1 Also applies to: 32-32 🧰 Tools🪛 Shellcheck[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. (SC2164) |
||
else | ||
# -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), | ||
# -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, | ||
# -w基本没啥损失。-s的损失就有点大了。 | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - | ||
fi | ||
|
||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} | ||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE} | ||
|
||
mkdir -p ${TARGET_FOLDER}/${TAR_NAME} | ||
|
||
|
@@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR} | |
cd ${TARGET_FOLDER} | ||
|
||
tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
***************************************************** | ||
# DESC : echo stream parser | ||
# AUTHOR : Alex Stocks | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2016-09-04 13:08 | ||
# FILE : readwriter.go | ||
***************************************************** | ||
*/ | ||
|
||
package main | ||
|
||
var ( | ||
Version = "1.0.0" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,28 +11,28 @@ | |
|
||
rm -rf target/ | ||
|
||
PROJECT_HOME=`pwd` | ||
PROJECT_HOME=$(pwd) | ||
TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} | ||
|
||
TARGET_SBIN_NAME=${TARGET_EXEC_NAME} | ||
version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` | ||
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') | ||
if [[ ${GOOS} == "windows" ]]; then | ||
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe | ||
fi | ||
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} | ||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||
# GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 | ||
# GFLAGS=-gcflags "-N -l" -race -v | ||
# GFLAGS="-gcflags \"-N -l\" -v" | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for cd commands The Apply these changes: - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1
+ GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME}
+ cd - || exit 1
- cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1
+ GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME}
+ cd - || exit 1 Also applies to: 32-32 🧰 Tools🪛 Shellcheck[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. (SC2164) |
||
else | ||
# -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), | ||
# -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, | ||
# -w基本没啥损失。-s的损失就有点大了。 | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - | ||
fi | ||
|
||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} | ||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE} | ||
|
||
mkdir -p ${TARGET_FOLDER}/${TAR_NAME} | ||
|
||
|
@@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR} | |
cd ${TARGET_FOLDER} | ||
|
||
tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
***************************************************** | ||
# DESC : echo stream parser | ||
# AUTHOR : Alex Stocks | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2016-09-04 13:08 | ||
# FILE : readwriter.go | ||
***************************************************** | ||
*/ | ||
|
||
package main | ||
|
||
var ( | ||
Version = "1.0.0" | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,28 +11,28 @@ | |||||
|
||||||
rm -rf target/ | ||||||
|
||||||
PROJECT_HOME=`pwd` | ||||||
PROJECT_HOME=$(pwd) | ||||||
TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} | ||||||
|
||||||
TARGET_SBIN_NAME=${TARGET_EXEC_NAME} | ||||||
version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` | ||||||
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') | ||||||
if [[ ${GOOS} == "windows" ]]; then | ||||||
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe | ||||||
fi | ||||||
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} | ||||||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||||||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||||||
# GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 | ||||||
# GFLAGS=-gcflags "-N -l" -race -v | ||||||
# GFLAGS="-gcflags \"-N -l\" -v" | ||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - | ||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for directory changes The current cd commands could fail silently, potentially causing unexpected behavior. Add error handling: -cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - || exit 1 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. (SC2164) |
||||||
else | ||||||
# -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), | ||||||
# -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, | ||||||
# -w基本没啥损失。-s的损失就有点大了。 | ||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - | ||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for directory changes Similar to the development build command, this cd command needs error handling. Add error handling: -cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - || exit 1 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck[warning] 32-32: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. (SC2164) |
||||||
fi | ||||||
|
||||||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} | ||||||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE} | ||||||
|
||||||
mkdir -p ${TARGET_FOLDER}/${TAR_NAME} | ||||||
|
||||||
|
@@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR} | |||||
cd ${TARGET_FOLDER} | ||||||
|
||||||
tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||
***************************************************** | ||||||||||||||||||||||||||||||||||||||||||
# DESC : echo stream parser | ||||||||||||||||||||||||||||||||||||||||||
# AUTHOR : Alex Stocks | ||||||||||||||||||||||||||||||||||||||||||
# LICENCE : Apache License 2.0 | ||||||||||||||||||||||||||||||||||||||||||
# EMAIL : [email protected] | ||||||||||||||||||||||||||||||||||||||||||
# MOD : 2016-09-04 13:08 | ||||||||||||||||||||||||||||||||||||||||||
# FILE : readwriter.go | ||||||||||||||||||||||||||||||||||||||||||
***************************************************** | ||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File header comment needs to be updated The current file header contains incorrect information:
Apply this diff to fix the header: /*
*****************************************************
-# DESC : echo stream parser
+# DESC : Version information for UDP echo server
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
-# MOD : 2016-09-04 13:08
-# FILE : readwriter.go
+# MOD : 2024-11-xx xx:xx
+# FILE : version.go
*****************************************************
*/ 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
package main | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
var ( | ||||||||||||||||||||||||||||||||||||||||||
Version = "1.0.0" | ||||||||||||||||||||||||||||||||||||||||||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,28 +11,28 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
rm -rf target/ | ||||||||||||||||||||||
|
||||||||||||||||||||||
PROJECT_HOME=`pwd` | ||||||||||||||||||||||
PROJECT_HOME=$(pwd) | ||||||||||||||||||||||
TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} | ||||||||||||||||||||||
|
||||||||||||||||||||||
TARGET_SBIN_NAME=${TARGET_EXEC_NAME} | ||||||||||||||||||||||
version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` | ||||||||||||||||||||||
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make version extraction more robust The current version extraction method is fragile and could fail silently if the format of -version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
+if [ ! -f "app/version.go" ]; then
+ echo "Error: version.go not found"
+ exit 1
+fi
+version=$(grep -Po 'Version = "\K[^"]*' app/version.go)
+if [ -z "$version" ]; then
+ echo "Error: Could not extract version"
+ exit 1
+fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
if [[ ${GOOS} == "windows" ]]; then | ||||||||||||||||||||||
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} | ||||||||||||||||||||||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||||||||||||||||||||||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||||||||||||||||||||||
# GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 | ||||||||||||||||||||||
# GFLAGS=-gcflags "-N -l" -race -v | ||||||||||||||||||||||
# GFLAGS="-gcflags \"-N -l\" -v" | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
else | ||||||||||||||||||||||
# -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), | ||||||||||||||||||||||
# -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, | ||||||||||||||||||||||
# -w基本没啥损失。-s的损失就有点大了。 | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
|
||||||||||||||||||||||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} | ||||||||||||||||||||||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE} | ||||||||||||||||||||||
|
||||||||||||||||||||||
mkdir -p ${TARGET_FOLDER}/${TAR_NAME} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR} | |||||||||||||||||||||
cd ${TARGET_FOLDER} | ||||||||||||||||||||||
|
||||||||||||||||||||||
tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
***************************************************** | ||
# DESC : echo stream parser | ||
# AUTHOR : Alex Stocks | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2016-09-04 13:08 | ||
# FILE : readwriter.go | ||
***************************************************** | ||
*/ | ||
|
||
package main | ||
|
||
var ( | ||
Version = "1.0.0" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
***************************************************** | ||
# DESC : echo stream parser | ||
# AUTHOR : Alex Stocks | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2016-09-04 13:08 | ||
# FILE : readwriter.go | ||
***************************************************** | ||
*/ | ||
|
||
package main | ||
|
||
var ( | ||
Version = "1.0.0" | ||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,28 +11,28 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
rm -rf target/ | ||||||||||||||||||||||
|
||||||||||||||||||||||
PROJECT_HOME=`pwd` | ||||||||||||||||||||||
PROJECT_HOME=$(pwd) | ||||||||||||||||||||||
TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} | ||||||||||||||||||||||
|
||||||||||||||||||||||
TARGET_SBIN_NAME=${TARGET_EXEC_NAME} | ||||||||||||||||||||||
version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` | ||||||||||||||||||||||
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for version extraction The version extraction assumes -version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
+if [ ! -f app/version.go ]; then
+ echo "Error: app/version.go not found"
+ exit 1
+fi
+version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
+if [ -z "$version" ]; then
+ echo "Error: Failed to extract version from app/version.go"
+ exit 1
+fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
if [[ ${GOOS} == "windows" ]]; then | ||||||||||||||||||||||
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} | ||||||||||||||||||||||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||||||||||||||||||||||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||||||||||||||||||||||
# GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 | ||||||||||||||||||||||
# GFLAGS=-gcflags "-N -l" -race -v | ||||||||||||||||||||||
# GFLAGS="-gcflags \"-N -l\" -v" | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for directory changes The - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1
+ GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME}
+ cd - || exit 1
- cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1
+ GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME}
+ cd - || exit 1 Also applies to: 32-32 🧰 Tools🪛 Shellcheck[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. (SC2164) |
||||||||||||||||||||||
else | ||||||||||||||||||||||
# -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), | ||||||||||||||||||||||
# -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, | ||||||||||||||||||||||
# -w基本没啥损失。-s的损失就有点大了。 | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
|
||||||||||||||||||||||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} | ||||||||||||||||||||||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE} | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add validation for required environment variables The script uses several environment variables (GOOS, GOARCH, PROFILE, TARGET_EXEC_NAME) but doesn't validate their presence. Consider adding validation at the start of the script. +# Add at the beginning of the script
+required_vars=("GOOS" "GOARCH" "PROFILE" "TARGET_EXEC_NAME" "BUILD_PACKAGE")
+for var in "${required_vars[@]}"; do
+ if [ -z "${!var}" ]; then
+ echo "Error: Required environment variable $var is not set"
+ exit 1
+ fi
+done
|
||||||||||||||||||||||
|
||||||||||||||||||||||
mkdir -p ${TARGET_FOLDER}/${TAR_NAME} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR} | |||||||||||||||||||||
cd ${TARGET_FOLDER} | ||||||||||||||||||||||
|
||||||||||||||||||||||
tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
***************************************************** | ||
# DESC : echo stream parser | ||
# AUTHOR : Alex Stocks | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2016-09-04 13:08 | ||
# FILE : readwriter.go | ||
***************************************************** | ||
*/ | ||
|
||
package main | ||
|
||
var ( | ||
Version = "1.0.0" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,28 +11,28 @@ | |
|
||
rm -rf target/ | ||
|
||
PROJECT_HOME=`pwd` | ||
PROJECT_HOME=$(pwd) | ||
TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} | ||
|
||
TARGET_SBIN_NAME=${TARGET_EXEC_NAME} | ||
version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` | ||
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}') | ||
if [[ ${GOOS} == "windows" ]]; then | ||
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe | ||
fi | ||
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} | ||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then | ||
# GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 | ||
# GFLAGS=-gcflags "-N -l" -race -v | ||
# GFLAGS="-gcflags \"-N -l\" -v" | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for directory changes The Apply this fix to both lines: - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+ cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - || exit 1 Also applies to: 32-32 🧰 Tools🪛 Shellcheck[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. (SC2164) |
||
else | ||
# -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), | ||
# -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, | ||
# -w基本没啥损失。-s的损失就有点大了。 | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - | ||
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - | ||
fi | ||
|
||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} | ||
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE} | ||
|
||
mkdir -p ${TARGET_FOLDER}/${TAR_NAME} | ||
|
||
|
@@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR} | |
cd ${TARGET_FOLDER} | ||
|
||
tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Missing version.go file in expected location
The build script is looking for version.go in the
app
directory relative to where the build script is executed, but this file doesn't exist in the expected location. The directory structure shows that version.go files exist in other locations:The build script needs to be updated to use the correct path to version.go or the file needs to be created in the expected location.
🔗 Analysis chain
Verify version.go file existence
Since the build script relies on reading the version from app/version.go, let's verify its existence and content.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 129
Script:
Length of output: 8121