Skip to content

Add GitHub Actions workflows for CI and PR validation #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Linux

on: [push, pull_request]

jobs:
gcc7:
strategy:
fail-fast: false
matrix:
config: [Debug, Release]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build

- name: Build GTest
run: |
cmake -E make_directory gtest
cd gtest
cmake -DCMAKE_BUILD_TYPE=${{ matrix.config }} -G Ninja /usr/src/gtest
cmake --build . -j -v
sudo cmake --install .

- name: Create Build Environment
run: cmake -E make_directory build

- name: Configure CMake
shell: pwsh
working-directory: build/
run: |
$cmakeBuildType = '${{ matrix.config }}'

cmake "-DCMAKE_BUILD_TYPE=$cmakeBuildType" -G Ninja ${{ github.workspace }}

- name: Build
working-directory: build/
run: cmake --build . -j -v

- name: Test
working-directory: build/
run: ctest --output-on-failure
54 changes: 54 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: macOS

on: [push, pull_request]

jobs:
xcode:
strategy:
fail-fast: false
matrix:
config: [Debug, Release]

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Cache vcpkg
uses: actions/cache@v2
id: cache-vcpkg
with:
path: vcpkg/
key: vcpkg-x64-osx

- name: Install Dependencies
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
shell: pwsh
run: |
git clone https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.sh -allowAppleClang
./vcpkg integrate install
./vcpkg install boost-program-options rapidjson gtest

- name: Create Build Environment
run: cmake -E make_directory build

- name: Configure
shell: pwsh
working-directory: build/
run: |
$vcpkgToolchain = Join-Path '../vcpkg' './scripts/buildsystems/vcpkg.cmake' -Resolve
$cmakeBuildType = '${{ matrix.config }}'

cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DCMAKE_BUILD_TYPE=$cmakeBuildType" ${{ github.workspace }}

- name: Build
working-directory: build/
run: cmake --build . -j -v

- name: Test
working-directory: build/
run: ctest --output-on-failure
63 changes: 63 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Windows

on: [push, pull_request]

jobs:
vs2019:
strategy:
fail-fast: false
matrix:
arch: ['x86', 'x64']
libs: ['shared', 'static']
config: ['Debug', 'Release']

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Set target triplet
id: set-variables
shell: pwsh
run: echo "::set-output name=vcpkg_triplet::${{ matrix.arch }}-windows$(if ('${{ matrix.libs }}' -eq 'static') { '-static' })"

- name: Cache vcpkg
uses: actions/cache@v2
id: cache-vcpkg
with:
path: vcpkg/
key: vcpkg-${{ steps.set-variables.outputs.vcpkg_triplet }}

- name: Install Dependencies
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
shell: pwsh
run: |
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
.\vcpkg install boost-program-options rapidjson gtest --triplet ${{ steps.set-variables.outputs.vcpkg_triplet }}

- name: Create Build Environment
run: cmake -E make_directory build

- name: Configure
shell: pwsh
working-directory: build/
run: |
$vcpkgToolchain = Join-Path '..\vcpkg' '.\scripts\buildsystems\vcpkg.cmake' -Resolve
$vcpkgTriplet = '${{ steps.set-variables.outputs.vcpkg_triplet }}'
$cmakeSharedLibs = $(if ('${{ matrix.libs }}' -eq 'shared') { 'ON' } else { 'OFF' })
$msbuildArch = $(if ('${{ matrix.arch }}' -eq 'x64') { 'X64' } else { 'Win32' })

cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DVCPKG_TARGET_TRIPLET=$vcpkgTriplet" "-DBUILD_SHARED_LIBS=$cmakeSharedLibs" -G "Visual Studio 16 2019" -A "$msbuildArch" ${{ github.workspace }}

- name: Build
working-directory: build/
run: cmake --build . --config ${{ matrix.config }} -j -v

- name: Test
working-directory: build/
run: ctest -C ${{ matrix.config }} --output-on-failure
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

cmake_minimum_required(VERSION 3.8.2)

# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows.
cmake_policy(SET CMP0091 NEW)

# Default to the last updated version from version.txt.
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.txt" VERSION_FILE)
file(READ "${VERSION_FILE}" LATEST_VERSION)
Expand Down Expand Up @@ -36,6 +39,24 @@ set(GRAPHQL_INSTALL_CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES} CACHE STRING "Co

option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)

if(VCPKG_TARGET_TRIPLET)
message(STATUS "Using ${VCPKG_TARGET_TRIPLET} triplet with vcpkg")

if(MSVC)
# Match the MSVC runtime if we're using VCPKG with static libraries.
if(VCPKG_TARGET_TRIPLET MATCHES [[^.+-static$]])
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
message(STATUS "Using MSVC runtime static library")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
message(STATUS "Using MSVC runtime DLL")
endif()

add_custom_target(output_msvc_runtime ALL
${CMAKE_COMMAND} -E echo "Using ${CMAKE_MSVC_RUNTIME_LIBRARY} MSVC runtime to match ${VCPKG_TARGET_TRIPLET}")
endif()
endif()

function(add_bigobj_flag target)
if(MSVC)
# MSVC requires the /bigobj flag if the number of sections gets too big.
Expand Down
16 changes: 8 additions & 8 deletions include/graphqlservice/GraphQLSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Schema : public std::enable_shared_from_this<Schema>
GRAPHQLSERVICE_EXPORT void AddType(std::string_view name, std::shared_ptr<BaseType> type);
GRAPHQLSERVICE_EXPORT const std::shared_ptr<const BaseType>& LookupType(
std::string_view name) const;
GRAPHQLSERVICE_EXPORT const std::shared_ptr<const BaseType>& WrapType(
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType);
GRAPHQLSERVICE_EXPORT std::shared_ptr<const BaseType> WrapType(
introspection::TypeKind kind, std::shared_ptr<const BaseType> ofType);
GRAPHQLSERVICE_EXPORT void AddDirective(std::shared_ptr<Directive> directive);

// Accessors
Expand All @@ -67,12 +67,12 @@ class Schema : public std::enable_shared_from_this<Schema>
std::shared_ptr<const ObjectType> _query;
std::shared_ptr<const ObjectType> _mutation;
std::shared_ptr<const ObjectType> _subscription;
std::unordered_map<std::string_view, size_t> _typeMap;
internal::sorted_map<std::string_view, size_t> _typeMap;
std::vector<std::pair<std::string_view, std::shared_ptr<const BaseType>>> _types;
std::vector<std::shared_ptr<const Directive>> _directives;
std::unordered_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
internal::sorted_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
_nonNullWrappers;
std::unordered_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
internal::sorted_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
_listWrappers;
};

Expand Down Expand Up @@ -282,7 +282,7 @@ class WrapperType : public BaseType
explicit WrapperType(init&& params);

GRAPHQLSERVICE_EXPORT static std::shared_ptr<WrapperType> Make(
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType);
introspection::TypeKind kind, std::weak_ptr<const BaseType> ofType);

// Accessors
GRAPHQLSERVICE_EXPORT const std::weak_ptr<const BaseType>& ofType() const noexcept final;
Expand All @@ -303,7 +303,7 @@ class Field : public std::enable_shared_from_this<Field>

GRAPHQLSERVICE_EXPORT static std::shared_ptr<Field> Make(std::string_view name,
std::string_view description, std::optional<std::string_view> deprecationReason,
const std::shared_ptr<const BaseType>& type,
std::weak_ptr<const BaseType> type,
std::initializer_list<std::shared_ptr<InputValue>> args = {});

// Accessors
Expand Down Expand Up @@ -333,7 +333,7 @@ class InputValue : public std::enable_shared_from_this<InputValue>
explicit InputValue(init&& params);

GRAPHQLSERVICE_EXPORT static std::shared_ptr<InputValue> Make(std::string_view name,
std::string_view description, const std::shared_ptr<const BaseType>& type,
std::string_view description, std::weak_ptr<const BaseType> type,
std::string_view defaultValue);

// Accessors
Expand Down
13 changes: 10 additions & 3 deletions include/graphqlservice/GraphQLTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ class ast_node
[[nodiscard]] bool is_type() const noexcept
{
const auto u = type_name<U>();
const auto u_hash = type_hash<U>();

return _type_hash == u_hash
&& ((_type.data() == u.data() && _type.size() == u.size()) || _type == u);
// The pointer comparison doesn't work with shared libraries where the parse tree is
// constructed in one module and consumed in another. So to optimize this comparison, check
// the size first, then the hash (cached in a static local variable per specialization of
// type_hash<U>()), then the pointer comparison with a full string compare as fallback.
return _type.size() == u.size() && _type_hash == type_hash<U>()
&& (_type.data() == u.data() || _type == u);
}

template <typename... States>
Expand Down Expand Up @@ -115,6 +118,8 @@ class ast_node
template <typename U>
[[nodiscard]] static std::string_view type_name() noexcept
{
// This is cached in a static local variable per-specialization, but each module may have
// its own instance of the specialization and the local variable.
static const std::string_view name { tao::graphqlpeg::demangle<U>() };

return name;
Expand All @@ -123,6 +128,8 @@ class ast_node
template <typename U>
[[nodiscard]] static size_t type_hash() noexcept
{
// This is cached in a static local variable per-specialization, but each module may have
// its own instance of the specialization and the local variable.
static const size_t hash = std::hash<std::string_view>()(type_name<U>());

return hash;
Expand Down
3 changes: 3 additions & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ if(GRAPHQL_UPDATE_SAMPLES)
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/unified/TodaySchema.cpp
${CMAKE_CURRENT_BINARY_DIR}/unified/TodaySchema.h
${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection/TodaySchema.cpp
${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection/TodaySchema.h
${CMAKE_CURRENT_BINARY_DIR}/separate/today_schema_files
${CMAKE_CURRENT_BINARY_DIR}/separate_nointrospection/today_schema_files
${CMAKE_CURRENT_BINARY_DIR}/validation/ValidationSchema.cpp
${CMAKE_CURRENT_BINARY_DIR}/validation/ValidationSchema.h
COMMENT "Updating sample files")
Expand Down
Loading