Skip to content

Commit

Permalink
Adds GitHub workflow for building and testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
joesiltberg committed Sep 3, 2024
1 parent 5890c0e commit 79390e9
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 4 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
cmake_preset: windows
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
cmake_preset: unix

steps:
- uses: actions/checkout@v4

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: "Set environmental variables"
shell: bash
run: |
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
- name: Install dependencies on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y libldap2-dev

- name: Configure CMake
run: cmake -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} --preset=${{ matrix.cmake_preset }}

- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Tests on Windows
if: matrix.os == 'windows-latest'
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: .\${{ matrix.build_type }}\tests.exe

- name: Tests on Unix
if: matrix.os == 'ubuntu-latest'
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ./tests

- name: Upload Windows artifacts
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: EgilSCIMClient-${{ matrix.os }}
path: build/${{ matrix.build_type }}

- name: Upload Ubuntu artifacts
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: EgilSCIMClient-${{ matrix.os }}
path: build/EgilSCIMClient
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ else()
include_directories(${CURL_INCLUDE_DIRS})
endif ()

find_package(Boost REQUIRED COMPONENTS program_options)
find_package(Boost REQUIRED COMPONENTS program_options uuid)
if (NOT Boost_FOUND)
message(FATAL_ERROR "please install boost")
else ()
include_directories(${Boost_INCLUDE_DIRS})
endif ()

if (WIN32)
set(LDFLAGS wldap32.lib ${CURL_LIBRARIES})
set(LDFLAGS wldap32.lib Bcrypt.lib ${CURL_LIBRARIES})
else()
set(LDFLAGS -lldap -llber -lcurl -lstdc++fs -ldl)
set(LDFLAGS -lldap -llber -lstdc++fs -ldl ${CURL_LIBRARIES})
endif()

link_libraries(${LDFLAGS})
Expand All @@ -60,7 +60,7 @@ add_library (Egil ${SOURCES})
add_executable(EgilSCIMClient ${srcroot}/main.cpp)
add_executable(tests ${TEST_SOURCES})

target_link_libraries(EgilSCIMClient LINK_PUBLIC Egil Boost::program_options)
target_link_libraries(EgilSCIMClient LINK_PUBLIC Egil Boost::program_options Boost::uuid CURL::libcurl)
target_link_libraries(tests LINK_PUBLIC Egil)

install (TARGETS EgilSCIMClient DESTINATION bin)
Expand Down
31 changes: 31 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": 2,
"configurePresets": [
{
"name": "windows",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "unix",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "unix_debug",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "Debug"
}
}
]
}
3 changes: 3 additions & 0 deletions src/tests/transformer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ TEST_CASE("regex_transformer") {
std::vector<std::string> student3_otherGroup({"fritis-bandy"});
REQUIRE(student3.get_values("class") == student3_className);
REQUIRE(student3.get_values("studyGroup") == student3_studyGroup);
#ifndef _WIN32
// $0 doesn't seem to work on MSVC...
REQUIRE(student3.get_values("otherGroup") == student3_otherGroup);
#endif
}

TEST_CASE("urldecode_transformer") {
Expand Down
14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "6f1ddd6b6878e7e66fcc35c65ba1d8feec2e01f8",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
8 changes: 8 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": [
"boost-program-options",
"boost-property-tree",
"boost-uuid",
"curl"
]
}

0 comments on commit 79390e9

Please sign in to comment.