From e9e177a04291b68d3aa2e3d68e3c41791248f6bc Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 13:11:17 +0100 Subject: [PATCH 1/4] Add on dispatch trigger --- .github/workflows/debug.yml | 2 ++ .github/workflows/release.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index c678507..4414940 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -5,6 +5,8 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: + branches: [ master ] jobs: build: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ac4e09..378b704 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,8 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: + branches: [ master ] jobs: build: From 6f79e2481ee5fe47859b71b07738b0ba873237b2 Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 13:23:02 +0100 Subject: [PATCH 2/4] Fix build for Linux and use the latest gtest version --- .github/workflows/debug.yml | 27 +++++++++++++++++---------- .github/workflows/release.yml | 27 +++++++++++++++++---------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 4414940..c24c2e7 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -9,15 +9,22 @@ on: branches: [ master ] jobs: - build: + build-linux: runs-on: ubuntu-latest steps: - - name: Install gtest manually - run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp *.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - - uses: actions/checkout@v1 - - name: configure - run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" .. - - name: make - run: cd build && make - - name: Run Test - run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + - name: Download, configure and install gtest + run: | + wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz + tar xf release-1.11.0.tar.gz + cd googletest-release-1.11.0 + cmake -DBUILD_SHARED_LIBS=OFF . + sudo make install + - name: Checkout the project + uses: actions/checkout@v1 + - name: Do some tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" .. + make + /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 378b704..725bddc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,15 +9,22 @@ on: branches: [ master ] jobs: - build: + build-linux: runs-on: ubuntu-latest steps: - - name: Install gtest manually - run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp *.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - - uses: actions/checkout@v1 - - name: configure - run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. - - name: make - run: cd build && make - - name: Run Test - run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + - name: Download, configure and install gtest + run: | + wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz + tar xf release-1.11.0.tar.gz + cd googletest-release-1.11.0 + cmake -DBUILD_SHARED_LIBS=OFF . + sudo make install + - name: Checkout the project + uses: actions/checkout@v1 + - name: Do some tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. + make + /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test From 9657f34b74fed70ec39df56479f8241a657cc963 Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 14:14:46 +0100 Subject: [PATCH 3/4] Update README --- README.md | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index df48fee..683b0b1 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ![github_actions_gtest_example-Release](https://github.com/bastianhjaeger/github_actions_gtest_example/workflows/github_actions_gtest_example-Release/badge.svg?branch=master) ![github_actions_gtest_example-Debug](https://github.com/bastianhjaeger/github_actions_gtest_example/workflows/github_actions_gtest_example-Debug/badge.svg?branch=master) -Example on how to integrate gtest test into [github actions](https://github.com/features/actions). +Example on how to integrate gtest test into [github actions](https://github.com/features/actions). While there exist other links in the www on how to use it (which did not work for my setup), this repo quickly shows how to add a workflow / action to github that executes your gtest tests and responses with a simple ok / not-ok to highlight on github. -It is plain and simple, but maybe it helps you. +It is plain and simple, but maybe it helps you. # Setup Actions @@ -27,18 +27,25 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Install gtest manually - run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp *.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - - uses: actions/checkout@v1 - - name: configure - run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. - - name: make - run: cd build && make - - name: Run Test - run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test -``` - -The important part is the *"Install gtest manually"* section. This is the plain and simple way to add it. + - name: Download, configure and install gtest + run: | + wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz + tar xf release-1.10.0.tar.gz + cd googletest-release-1.10.0 + cmake -DBUILD_SHARED_LIBS=OFF . + sudo make install + - name: Checkout the project + uses: actions/checkout@v1 + - name: Do some tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. + make + /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + ``` + +The important part is the *"Download, configure and install gtest"* section. This is the plain and simple way to add it. # Result @@ -59,3 +66,9 @@ mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. make -j8 ``` + +# If you only want to use Makefile + +You can use : +- `pkg-config --cflags gtest gmock` for your CXXFLAGS. +- `pkg-config --libs gtest gmock` for your LDFLAGS. From b326e1271a864af43453054aec672bd5f6fb8430 Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 14:04:51 +0100 Subject: [PATCH 4/4] Add build for MacOS X --- .github/workflows/debug.yml | 20 ++++++++++++++++++++ .github/workflows/release.yml | 20 ++++++++++++++++++++ test/CMakeLists.txt | 10 +++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index c24c2e7..a8e6267 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -28,3 +28,23 @@ jobs: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" .. make /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + + build-macos: + runs-on: macos-latest + steps: + - name: Download, configure and install gtest + run: | + wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz + tar xf release-1.11.0.tar.gz + cd googletest-release-1.11.0 + cmake -DBUILD_SHARED_LIBS=OFF . + sudo make install + - name: Checkout the project + uses: actions/checkout@v1 + - name: Do some tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" .. + make + /Users/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 725bddc..ed6b23c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,3 +28,23 @@ jobs: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. make /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + + build-macos: + runs-on: macos-latest + steps: + - name: Download, configure and install gtest + run: | + wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz + tar xf release-1.11.0.tar.gz + cd googletest-release-1.11.0 + cmake -DBUILD_SHARED_LIBS=OFF . + sudo make install + - name: Checkout the project + uses: actions/checkout@v1 + - name: Do some tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. + make + /Users/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e1edae5..b83e8db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,10 +1,14 @@ +link_directories("/usr/local/lib") add_executable(${PROJECT_NAME}.test AllTests.cpp ${PROJECT_NAME}Test.cpp) target_link_libraries(${PROJECT_NAME}.test - ${PROJECT_NAME} gtest pthread) -target_compile_definitions(${PROJECT_NAME}.test + ${PROJECT_NAME} gtest gmock pthread) +target_compile_definitions(${PROJECT_NAME}.test PRIVATE TEST_DIR="${CMAKE_CURRENT_LIST_DIR}/test") - install(TARGETS ${PROJECT_NAME}.test DESTINATION "${tool_dest}") + +# Mac OS X does not look at these paths +target_include_directories(${PROJECT_NAME}.test PRIVATE "/usr/local/include/") +set(CMAKE_LIBRARY_PATH "/usr/local/lib/")