├── .gitignore ├── doc ├── actions_build_example_01.png ├── actions_build_example_02_detail.png └── actions_build_example_03_overview.png ├── src ├── info.cpp ├── github_actions_gtest_example.cpp └── CMakeLists.txt ├── include └── github_actions_gtest_example │ └── github_actions_gtest_example.h ├── CMakeLists.txt ├── test ├── AllTests.cpp ├── CMakeLists.txt └── github_actions_gtest_exampleTest.cpp ├── .github └── workflows │ ├── debug.yml │ └── release.yml ├── license └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .cproject 3 | build/ 4 | -------------------------------------------------------------------------------- /doc/actions_build_example_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bastianhjaeger/github_actions_gtest_example/HEAD/doc/actions_build_example_01.png -------------------------------------------------------------------------------- /doc/actions_build_example_02_detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bastianhjaeger/github_actions_gtest_example/HEAD/doc/actions_build_example_02_detail.png -------------------------------------------------------------------------------- /doc/actions_build_example_03_overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bastianhjaeger/github_actions_gtest_example/HEAD/doc/actions_build_example_03_overview.png -------------------------------------------------------------------------------- /src/info.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | int main(int argc, char** argv) { 6 | 7 | std::cout << githubActionsGtestExample::sayHello() << std::endl; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /include/github_actions_gtest_example/github_actions_gtest_example.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace githubActionsGtestExample { 7 | 8 | std::string sayHello(); 9 | int add(int _first, int _second); 10 | 11 | } // namespace githubActionsGtestExample 12 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10.2) 2 | project (github_actions_gtest_example) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -g") 6 | 7 | 8 | set(tool_dest "bin") 9 | set(lib_dest "lib") 10 | set(include_dest "include/${PROJECT_NAME}") 11 | 12 | add_subdirectory(src) 13 | add_subdirectory(test) 14 | -------------------------------------------------------------------------------- /test/AllTests.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) { 4 | ::testing::InitGoogleTest(&argc, argv); 5 | 6 | std::cout << "TEST_DIR '" << TEST_DIR << "'" << std::endl; 7 | for (int i = 1; i < argc; ++i) { 8 | std::cout << "Input[" << i << "]: "<< argv[i] << std::endl; 9 | } 10 | 11 | return RUN_ALL_TESTS(); 12 | } 13 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(${PROJECT_NAME}.test 2 | AllTests.cpp 3 | ${PROJECT_NAME}Test.cpp) 4 | target_link_libraries(${PROJECT_NAME}.test 5 | ${PROJECT_NAME} gtest pthread) 6 | target_compile_definitions(${PROJECT_NAME}.test 7 | PRIVATE TEST_DIR="${CMAKE_CURRENT_LIST_DIR}/test") 8 | 9 | install(TARGETS ${PROJECT_NAME}.test 10 | DESTINATION "${tool_dest}") 11 | -------------------------------------------------------------------------------- /src/github_actions_gtest_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace githubActionsGtestExample { 4 | 5 | std::string sayHello() { 6 | return "Hello world from 'github-actions-gtest-example' project"; 7 | } 8 | 9 | 10 | int add(int _first, int _second) { 11 | return _first + _second; 12 | } 13 | 14 | } // namespace githubActionsGtestExample 15 | -------------------------------------------------------------------------------- /test/github_actions_gtest_exampleTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST(githubActionsGtestExampleTest, firstTest) { 6 | EXPECT_TRUE( 1 == 1 ); 7 | } 8 | 9 | TEST(githubActionsGtestExampleTest, addTest) { 10 | const int a = 1; 11 | const int b = 3; 12 | const int result = githubActionsGtestExample::add(a, b); 13 | 14 | EXPECT_EQ( result, a + b ); 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/debug.yml: -------------------------------------------------------------------------------- 1 | name: github_actions_gtest_example-Debug 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Install gtest manually 14 | 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 15 | - uses: actions/checkout@v1 16 | - name: configure 17 | run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror" .. 18 | - name: make 19 | run: cd build && make 20 | - name: Run Test 21 | run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test 22 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: github_actions_gtest_example-Release 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Install gtest manually 14 | 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 15 | - uses: actions/checkout@v1 16 | - name: configure 17 | run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. 18 | - name: make 19 | run: cd build && make 20 | - name: Run Test 21 | run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test 22 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(header_path "${${PROJECT_NAME}_SOURCE_DIR}/include/${PROJECT_NAME}") 2 | set(header ${header_path}/${PROJECT_NAME}.h) 3 | set(src ${PROJECT_NAME}.cpp) 4 | 5 | 6 | add_library(${PROJECT_NAME} SHARED 7 | ${header} 8 | ${src}) 9 | target_include_directories(${PROJECT_NAME} 10 | PUBLIC ${CMAKE_CURRENT_BINARY_DIR} 11 | ${${PROJECT_NAME}_SOURCE_DIR}/include) 12 | target_link_libraries(${PROJECT_NAME} 13 | pthread) 14 | 15 | 16 | add_executable(${PROJECT_NAME}.info info.cpp) 17 | target_include_directories(${PROJECT_NAME}.info 18 | PUBLIC ${CMAKE_CURRENT_BINARY_DIR} 19 | ${${PROJECT_NAME}_SOURCE_DIR}/include) 20 | target_link_libraries(${PROJECT_NAME}.info 21 | ${PROJECT_NAME}) 22 | 23 | 24 | install(TARGETS ${PROJECT_NAME} 25 | LIBRARY DESTINATION "${lib_dest}" 26 | ARCHIVE DESTINATION "${lib_dest}" 27 | COMPONENT library) 28 | install(TARGETS ${PROJECT_NAME}.info 29 | RUNTIME DESTINATION "${tool_dest}" 30 | COMPONENT library) 31 | install(FILES ${header} DESTINATION "${include_dest}") 32 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Bastian Jäger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # General 2 | ![github_actions_gtest_example-Release](https://github.com/bastianhjaeger/github_actions_gtest_example/workflows/github_actions_gtest_example-Release/badge.svg?branch=master) 3 | ![github_actions_gtest_example-Debug](https://github.com/bastianhjaeger/github_actions_gtest_example/workflows/github_actions_gtest_example-Debug/badge.svg?branch=master) 4 | 5 | Example on how to integrate gtest test into [github actions](https://github.com/features/actions). 6 | 7 | 8 | 9 | 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. 10 | 11 | It is plain and simple, but maybe it helps you. 12 | 13 | # Setup Actions 14 | 15 | the workflow file you need (e.g. in you repo under `.github/workflows/release.yml`) could look like this 16 | 17 | ```yaml 18 | name: my-workflow-name 19 | 20 | on: 21 | push: 22 | branches: [ master ] 23 | pull_request: 24 | branches: [ master ] 25 | 26 | jobs: 27 | build: 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: Install gtest manually 31 | run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.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 32 | - uses: actions/checkout@v1 33 | - name: configure 34 | run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" .. 35 | - name: make 36 | run: cd build && make 37 | - name: Run Test 38 | run: /home/runner/work/github_actions_gtest_example/github_actions_gtest_example/build/test/github_actions_gtest_example.test 39 | ``` 40 | 41 | The important part is the *"Install gtest manually"* section. This is the plain and simple way to add it. 42 | 43 | # Result 44 | 45 | After some time (depending on you project and test complexity) you see the results like this: 46 | 47 | actions_build_example_01 48 | 49 | actions_build_example_02_detail 50 | 51 | actions_build_example_03_overview 52 | 53 | 54 | # Build local 55 | ```bash 56 | git clone git@github.com:bastianhjaeger/github_actions_gtest_example.git 57 | cd github_actions_gtest_example 58 | mkdir build && cd build 59 | cmake -DCMAKE_BUILD_TYPE=Release .. 60 | make -j8 61 | ``` 62 | --------------------------------------------------------------------------------