From e9e177a04291b68d3aa2e3d68e3c41791248f6bc Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 13:11:17 +0100 Subject: [PATCH 1/8] 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 400d79c8102ed4ff90d6cbff412c5931497999c1 Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 13:23:02 +0100 Subject: [PATCH 2/8] Fix build for Linux --- .github/workflows/debug.yml | 27 ++++++++++++++--------- .github/workflows/release.yml | 27 ++++++++++++++--------- src/github_actions_gtest_example.cpp | 2 +- src/info.cpp | 2 +- test/AllTests.cpp | 1 + test/github_actions_gtest_exampleTest.cpp | 6 ++--- 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 4414940..1c50858 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.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=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..fffca33 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.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 diff --git a/src/github_actions_gtest_example.cpp b/src/github_actions_gtest_example.cpp index 6f8fa72..4ed4e4c 100644 --- a/src/github_actions_gtest_example.cpp +++ b/src/github_actions_gtest_example.cpp @@ -1,4 +1,4 @@ -#include +#include "github_actions_gtest_example/github_actions_gtest_example.h" namespace githubActionsGtestExample { diff --git a/src/info.cpp b/src/info.cpp index 24a0465..e34cc77 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1,4 +1,4 @@ -#include +#include "github_actions_gtest_example/github_actions_gtest_example.h" #include diff --git a/test/AllTests.cpp b/test/AllTests.cpp index 0f72bc3..1fbd44c 100644 --- a/test/AllTests.cpp +++ b/test/AllTests.cpp @@ -1,3 +1,4 @@ +#include #include int main(int argc, char **argv) { diff --git a/test/github_actions_gtest_exampleTest.cpp b/test/github_actions_gtest_exampleTest.cpp index f99e5a9..28b5559 100644 --- a/test/github_actions_gtest_exampleTest.cpp +++ b/test/github_actions_gtest_exampleTest.cpp @@ -1,5 +1,5 @@ -#include - +#include "github_actions_gtest_example/github_actions_gtest_example.h" +#include #include TEST(githubActionsGtestExampleTest, firstTest) { @@ -10,6 +10,6 @@ TEST(githubActionsGtestExampleTest, addTest) { const int a = 1; const int b = 3; const int result = githubActionsGtestExample::add(a, b); - + EXPECT_EQ( result, a + b ); } From 29d12ec899afb7e25ce574bbbc37aab430d36bcd Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 14:14:46 +0100 Subject: [PATCH 3/8] Update README --- README.md | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index df48fee..064f581 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,7 @@ mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. make -j8 ``` + +# If you only want to use Makefile + +You can `pkg-config --libs gtest gmock` and `pkg-config --cflags gtest gmock`. From b580c960ec99fef3e8039fc6583f16542244e17e Mon Sep 17 00:00:00 2001 From: LeCrapouille Date: Tue, 1 Mar 2022 14:04:51 +0100 Subject: [PATCH 4/8] Add build for MacOS X --- .github/workflows/debug.yml | 20 ++++++++++++++++++++ .github/workflows/release.yml | 26 +++++++++++++++++++++++--- test/CMakeLists.txt | 7 +++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 1c50858..3710918 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.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=Debug -DCMAKE_CXX_FLAGS="-Werror" .. + VERBOSE=1 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 fffca33..70b70b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,9 +14,9 @@ jobs: steps: - 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 + 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 @@ -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" .. + VERBOSE=1 make + /home/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..c824dda 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,9 +2,12 @@ add_executable(${PROJECT_NAME}.test AllTests.cpp ${PROJECT_NAME}Test.cpp) target_link_libraries(${PROJECT_NAME}.test - ${PROJECT_NAME} gtest pthread) + ${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/") From b9022e27b6ca33bfde17fd4f0409fcf391908963 Mon Sep 17 00:00:00 2001 From: Basti Date: Tue, 1 Mar 2022 22:25:38 +0100 Subject: [PATCH 5/8] add path to installed libraries --- src/CMakeLists.txt | 1 - test/CMakeLists.txt | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 216e5e6..cce8b53 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,6 @@ set(header_path "${${PROJECT_NAME}_SOURCE_DIR}/include/${PROJECT_NAME}") set(header ${header_path}/${PROJECT_NAME}.h) set(src ${PROJECT_NAME}.cpp) - add_library(${PROJECT_NAME} SHARED ${header} ${src}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c824dda..7332b7d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,5 @@ +link_directories("/usr/local/lib") + add_executable(${PROJECT_NAME}.test AllTests.cpp ${PROJECT_NAME}Test.cpp) From 9497e4e470af0b0008aeb10b28368473d7af7519 Mon Sep 17 00:00:00 2001 From: Basti Date: Tue, 1 Mar 2022 22:29:36 +0100 Subject: [PATCH 6/8] Adapt path to build directory for MacOS --- .github/workflows/debug.yml | 3 ++- .github/workflows/release.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 3710918..f2ce119 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -47,4 +47,5 @@ jobs: cd build cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" .. VERBOSE=1 make - /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + pwd + /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 70b70b6..fc0ca1f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,4 +47,5 @@ jobs: cd build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. VERBOSE=1 make - /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test + pwd + /Users/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test From aa4eaca8eb8432e91baaf74d855c0b4c1dcc991f Mon Sep 17 00:00:00 2001 From: Basti Date: Tue, 1 Mar 2022 22:42:39 +0100 Subject: [PATCH 7/8] Revert inclusion method --- src/github_actions_gtest_example.cpp | 2 +- src/info.cpp | 2 +- test/github_actions_gtest_exampleTest.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/github_actions_gtest_example.cpp b/src/github_actions_gtest_example.cpp index 4ed4e4c..6f8fa72 100644 --- a/src/github_actions_gtest_example.cpp +++ b/src/github_actions_gtest_example.cpp @@ -1,4 +1,4 @@ -#include "github_actions_gtest_example/github_actions_gtest_example.h" +#include namespace githubActionsGtestExample { diff --git a/src/info.cpp b/src/info.cpp index e34cc77..24a0465 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1,4 +1,4 @@ -#include "github_actions_gtest_example/github_actions_gtest_example.h" +#include #include diff --git a/test/github_actions_gtest_exampleTest.cpp b/test/github_actions_gtest_exampleTest.cpp index 28b5559..dd0ce43 100644 --- a/test/github_actions_gtest_exampleTest.cpp +++ b/test/github_actions_gtest_exampleTest.cpp @@ -1,4 +1,4 @@ -#include "github_actions_gtest_example/github_actions_gtest_example.h" +#include #include #include From 897ca084895a386f1d09899d5ced267c3021e1ef Mon Sep 17 00:00:00 2001 From: Basti Date: Tue, 1 Mar 2022 22:48:01 +0100 Subject: [PATCH 8/8] Test removal of gmock --- test/AllTests.cpp | 1 - test/CMakeLists.txt | 2 +- test/github_actions_gtest_exampleTest.cpp | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/AllTests.cpp b/test/AllTests.cpp index 1fbd44c..0f72bc3 100644 --- a/test/AllTests.cpp +++ b/test/AllTests.cpp @@ -1,4 +1,3 @@ -#include #include int main(int argc, char **argv) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7332b7d..a075f6c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,7 +4,7 @@ add_executable(${PROJECT_NAME}.test AllTests.cpp ${PROJECT_NAME}Test.cpp) target_link_libraries(${PROJECT_NAME}.test - ${PROJECT_NAME} gtest gmock pthread) + ${PROJECT_NAME} gtest pthread) target_compile_definitions(${PROJECT_NAME}.test PRIVATE TEST_DIR="${CMAKE_CURRENT_LIST_DIR}/test") install(TARGETS ${PROJECT_NAME}.test diff --git a/test/github_actions_gtest_exampleTest.cpp b/test/github_actions_gtest_exampleTest.cpp index dd0ce43..2fda908 100644 --- a/test/github_actions_gtest_exampleTest.cpp +++ b/test/github_actions_gtest_exampleTest.cpp @@ -1,5 +1,4 @@ #include -#include #include TEST(githubActionsGtestExampleTest, firstTest) {