Skip to content

Commit

Permalink
Merge pull request #12 from ucsd-cse125-sp24/chore/ci
Browse files Browse the repository at this point in the history
build client in GH actions
  • Loading branch information
atar13 authored Apr 15, 2024
2 parents c8ed84d + 9ded619 commit a798df8
Show file tree
Hide file tree
Showing 33 changed files with 460 additions and 30 deletions.
16 changes: 16 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
Checks: >
*,
-altera-struct-pack-align,
-fuchsia-*,
-google-*,
-zircon-*,
-abseil-*,
-modernize-use-trailing-return-type,
-llvm-*,
-llvmlibc-*,
-cppcoreguidelines-virtual-class-destructor,
CheckOptions: [{ key: misc-non-private-member-variables-in-classes, value: IgnoreClassesWithAllMemberVariablesBeingPublic }]
WarningsAsErrors: '*'
HeaderFilterRegex: ''
FormatStyle: none
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build

on:
push:
branches:
- dev
pull_request:

jobs:
client-windows:
name: Client on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake -G "Unix Makefiles" ..
- name: Build
run: cd build && make client
client-linux:
name: Client on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake ..
- name: Build
run: cd build && make client
server-windows:
name: Server on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake -G "Unix Makefiles" ..
- name: Build
run: cd build && make server
server-linux:
name: Server on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake ..
- name: Build
run: cd build && make server
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

on:
push:
branches:
- dev
pull_request:

jobs:
clang-tidy:
name: clang-tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake ..
- name: clang-tidy version
run: clang-tidy --version
- name: Lint
run: cd build && make lint
75 changes: 75 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Test

on:
push:
branches:
- dev
pull_request:

jobs:
client-windows:
name: Client on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake -G "Unix Makefiles" ..
- name: Test
run: cd build && make run_client_tests
client-linux:
name: Client on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake ..
- name: Test
run: cd build && make run_client_tests
server-windows:
name: Server on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake -G "Unix Makefiles" ..
- name: Test
run: cd build && make run_server_tests
server-linux:
name: Server on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake ..
- name: Test
run: cd build && make run_server_tests
shared-windows:
name: Shared on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake -G "Unix Makefiles" ..
- name: Test
run: cd build && make run_shared_tests
shared-linux:
name: Shared on Linux (Ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create build dir
run: mkdir -p build
- name: Run CMake
run: cd build && cmake ..
- name: Test
run: cd build && make run_shared_tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build/
assets/*
.vscode/
.vs/
.cache/

docs/*
!docs/.gitkeep
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin)

# Generate a "compile_commands.json" file for clang-tidy and VScode to use
set(CMAKE_EXPORT_COMPILE_COMMANDS True)

# Add google test to CMake
add_subdirectory(dependencies/google-test)

# If we need any compiler / linker flags, add them here
SET(GCC_COMPILE_FLAGS "")
SET(GCC_LINK_FLAGS "")
Expand All @@ -28,4 +34,13 @@ SET(INCLUDE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)

add_subdirectory(src/shared) # define game_shared_lib
add_subdirectory(src/client) # create client executable
add_subdirectory(src/server) # create server executable
add_subdirectory(src/server) # create server executable

# this might not be compatible on Windows due to how find is used
file(GLOB_RECURSE LINT_FILES "src/*.cpp" "include/*.hpp")
find_program(CLANG_TIDY "clang-tidy")
add_custom_target(lint
COMMAND ${CLANG_TIDY}
-p=.
${LINT_FILES}
)
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TODO: Game description here, with screenshots.
- in the popup window put in this URL: `https://github.com/ucsd-cse125-sp24/group3.git`
- Alternatively, you can use the command line and then open Visual Studio in the directory where you cloned it:
- `git clone https://github.com/ucsd-cse125-sp24/group3.git`
3. Everything should just work. To run the program, you can click on the green arrow at the top bar that says "Select Startup Item." There is a dropdown arrow on the right side which will let you select between running the client and the server.
3. Everything should just work. To run the program, you can click on the green arrow at the top bar that says "Select Startup Item." There is a dropdown arrow on the right side which will let you select between running the client and the server.

### Linux / Mac

Expand Down Expand Up @@ -137,3 +137,51 @@ View deployed documentation [here](https://cse125.ucsd.edu/2024/cse125g3/site/do
2. Run `doxygen` from the root of the directory
3. Open the `html` files in the `docs` directory of the repo


## Testing

We are using [GoogleTest](https://google.github.io/googletest/) for unit testing. They run automatically in GitHub actions or can also be done manually.

There are three categories of unit tests:

1. Client tests for client specific code
2. Server tests for server specific code
2. Shared tests for code shared between the client and server

### Running Tests Locally

From the build directory run the following commands for each testing category:

```sh
make run_client_tests
make run_server_tests
make run_shared_tests
```

### Adding New Tests

1. Add a new `.cpp` file to the testing directory you want (either `src/client/tests`, `src/server/tests` or `src/shared/tests`).

2. Add a testing function with the GoogleTest `TEST` macro. See [this](https://google.github.io/googletest/reference/assertions.html) page to see all the available assertions.
```cpp
// Tests factorial of positive numbers.
TEST(FactorialTest, HandlesPositiveInput) {
EXPECT_EQ(Factorial(1), 1);
EXPECT_EQ(Factorial(2), 2);
EXPECT_EQ(Factorial(3), 6);
EXPECT_EQ(Factorial(8), 40320);
}
```
3. Run the tests locally with the steps above or with GitHub actions
## Linting
We are using [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) for linting and code style. They run automatically with GitHub actions.
### Linting locally
#### Linux/macOS
Install clang-tidy on your system. [Here are instructions for Debian/Ubuntu Linux distros](https://apt.llvm.org/). [Here is a Stack Overflow of people attempting to install it on macOS](https://stackoverflow.com/questions/53111082/how-to-install-clang-tidy-on-macos).
#### Windows
Visual Studio supports [clang-tidy natively](https://learn.microsoft.com/en-us/cpp/code-quality/clang-tidy?view=msvc-170)
3 changes: 3 additions & 0 deletions dependencies/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disable all checks in this folder.
Checks: '-*'

69 changes: 69 additions & 0 deletions dependencies/google-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Download and unpack googletest at configure time
# See: http://crascit.com/2015/07/25/cmake-gtest/
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
# Call CMake to download and Google Test
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
# Build the downloaded google test
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Prevent installation of GTest with your project
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build)

# This is a bit of a hack that can be used to get gtest libraries to build in C++11 if you aren't using CMAKE_CXX_STANDARD
#
#set(CXX11_FEATURES
# cxx_nullptr
# cxx_auto_type
# cxx_delegating_constructors
#)
#target_compile_features(gtest
# PRIVATE
# ${CXX11_FEATURES}
#)
#
#target_compile_features(gmock_main
# PRIVATE
# ${CXX11_FEATURES}
#)
#
#target_compile_features(gmock
# PRIVATE
# ${CXX11_FEATURES}
#)
#
#target_compile_features(gmock_main
# PRIVATE
# ${CXX11_FEATURES}
#)

# Add aliases for GTest and GMock libraries
if(NOT TARGET GTest::GTest)
add_library(GTest::GTest ALIAS gtest)
add_library(GTest::Main ALIAS gtest_main)
endif()

if(NOT TARGET GTest::GMock)
add_library(GMock::GMock ALIAS gmock)
add_library(GMock::Main ALIAS gmock_main)
endif()


21 changes: 21 additions & 0 deletions dependencies/google-test/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.0)

project(googletest-download NONE)

include(ExternalProject)

# Version bfc0ffc8a698072c794ae7299db9cb6866f4c0bc happens to be master when I set this up.
# To prevent an issue with accidentally installing GTest / GMock with your project you should use a
# commit after 9469fb687d040b60c8749b7617fee4e77c7f6409
# Note: This is after the release of v1.8
ExternalProject_Add(googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
DOWNLOAD_EXTRACT_TIMESTAMP true
)

2 changes: 1 addition & 1 deletion include/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Client {
public:
Client();
Client() = default;
private:

};
Expand Down
2 changes: 1 addition & 1 deletion include/server/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Server {
public:
Server();
Server() = default;
private:

};
Loading

0 comments on commit a798df8

Please sign in to comment.