Skip to content
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

feat: add github action GTest #54

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/pikiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ jobs:

- name: Build
run: |
sh build.sh
sh build.sh

- name: GTest
working-directory: ${{ github.workspace }}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest
28 changes: 26 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/bin/bash

#color code
C_RED="\033[31m"
C_GREEN="\033[32m"

C_END="\033[0m"

BUILD_TIME=$(git log -1 --format=%ai)
BUILD_TIME=${BUILD_TIME: 0: 10}

COMMIT_ID=$(git rev-parse HEAD)
SHORT_COMMIT_ID=${COMMIT_ID: 0: 8}

if [ ! -f "/proc/cpuinfo" ];then
CPU_CORE=$(sysctl -n hw.ncpu)
else
CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l)
fi
if [ ${CPU_CORE} -eq 0 ]; then
CPU_CORE=1
fi

echo "cpu core ${CPU_CORE}"

if [ -z "$SHORT_COMMIT_ID" ]; then
echo "no git commit id"
SHORT_COMMIT_ID="pikiwidb"
Expand All @@ -14,5 +31,12 @@ fi
echo "BUILD_TIME:" $BUILD_TIME
echo "COMMIT_ID:" $SHORT_COMMIT_ID

cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build
cmake --build build -- -j 32
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要改回release不,还有就是我之前想的一个是这里要不要接收一个参数来选择编译的模式,默认是release

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

疏忽了, 原来在我本地用release模式编译不过, 后来给gcc加了一个参数可以了, 这里忘记改回去了, 等我晚上回去改一下

要不要接收一个参数来选择编译的模式

我想的是加一个环境变量如何, 通过 export PIKIWIDB=DEBUG 设置环境变量, build.sh中读取环境变量, 如果读到DEBUG 使用debug模式, 没有就默认 release模式

这个方案怎么样

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

疏忽了, 原来在我本地用release模式编译不过, 后来给gcc加了一个参数可以了, 这里忘记改回去了, 等我晚上回去改一下

要不要接收一个参数来选择编译的模式

我想的是加一个环境变量如何, 通过 export PIKIWIDB=DEBUG 设置环境变量, build.sh中读取环境变量, 如果读到DEBUG 使用debug模式, 没有就默认 release模式

这个方案怎么样

感觉挺好的,之前看有一些项目可以用类似这种sh build.sh --debug这种来debug编译,或许可以参考下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉挺好的,之前看有一些项目可以用类似这种sh build.sh --debug这种来debug编译,或许可以参考下

感觉这个比环境变量要好, 可以改成这种方式

cmake --build build -- -j ${CPU_CORE} pikiwidb

if [ $? -eq 0 ]; then
echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}"
else
echo -e "${C_RED} pika compile fail ${C_END}"
exit 1
fi