From 92f46ccc2fbdc3408569a21566f83e843e563ff4 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 22 Oct 2026 13:36:16 +0200 Subject: [PATCH] Add CI tests --- .appveyor.yml | 39 +++++++++ .github/workflows/unit-tests.yml | 115 +++++++++++++++++++++++++++ libs/common/include/s25util/span.hpp | 12 +-- tools/ci/build.sh | 42 ++++++++++ tools/ci/checkUTF8.sh | 11 +++ tools/ci/setupCompiler.sh | 23 ++++++ tools/ci/staticValidation.sh | 25 ++++++ 7 files changed, 261 insertions(+), 6 deletions(-) create mode 100644 .appveyor.yml create mode 100644 .github/workflows/unit-tests.yml create mode 100755 tools/ci/build.sh create mode 100755 tools/ci/checkUTF8.sh create mode 100755 tools/ci/setupCompiler.sh create mode 100755 tools/ci/staticValidation.sh diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..b8c371b --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,39 @@ +# Copyright (C) 2005 - 2026 Settlers Freaks +# +# SPDX-License-Identifier: GPL-2.0-or-later + +version: 1.0.{build} + +shallow_clone: true + +branches: + only: [master] + +image: Visual Studio 2019 + +configuration: + - Debug + - Release + +platform: x64 + +environment: + global: + BOOST_DIR: 'C:\Libraries\boost_1_85_0' + RTTR_DISABLE_ASSERT_BREAKPOINT: 1 + +install: + - git clone https://github.com/Return-To-The-Roots/libutil.git libutil + - git clone https://github.com/Return-To-The-Roots/libendian.git libendian + - set CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH%;%cd%\libutil;%cd%\libendian + +before_build: + - mkdir build + - cd build + - dir /a:d %BOOST_DIR% + - cmake -G "Visual Studio 16 2019" -A %platform% -DRTTR_ENABLE_WERROR=ON -DBOOST_ROOT="%BOOST_DIR%\lib64-msvc-14.2\cmake" -DBoost_VERBOSE=ON .. + +build_script: cmake --build . --config %configuration% --parallel 4 + +test_script: ctest --output-on-failure -C %configuration% --parallel 4 + diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..96f15cc --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,115 @@ +# Copyright (C) 2005 - 2026 Settlers Freaks +# +# SPDX-License-Identifier: GPL-2.0-or-later + +name: Unit tests + +on: + push: + pull_request: + +concurrency: + group: ${{format('tests-{0}:{1}', github.repository, github.ref)}} + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + StyleAndFormatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - run: git submodule update --init + - name: Validation + run: tools/ci/staticValidation.sh "$GITHUB_WORKSPACE" + - name: Formatting + uses: DoozyX/clang-format-lint-action@bcb4eb2cb0d707ee4f3e5cc3b456eb075f12cf73 # v0.20 + with: + source: "examples include src tests" + clangFormatVersion: 10 + - name: Lint markdown files + uses: avto-dev/markdown-lint@04d43ee9191307b50935a753da3b775ab695eceb # v1.5.0 + with: + args: . + - name: Check licensing + run: + pip install --user reuse + reuse lint + UnitTests: + strategy: + matrix: + include: + - { compiler: gcc-9, os: ubuntu-22.04, buildType: Debug, boostVersion: 1.73.0 } + - { compiler: clang, os: macos-26, buildType: Debug, boostVersion: 1.81.0 } # New libc++ only supported since 1.81 + # Latest GCC + - { compiler: gcc-14, os: ubuntu-24.04, buildType: Debug, boostVersion: 1.87.0 } + # Latest Clang + - { compiler: clang-19, os: ubuntu-24.04, buildType: Debug, boostVersion: 1.81.0 } + # Windows + - { compiler: msvc, os: windows-2022, buildType: Debug, boostVersion: 1.87.0, generator: 'Visual Studio 17 2022' } + + runs-on: ${{matrix.os}} + env: + GENERATOR: ${{matrix.generator}} + + steps: + - run: | + echo "DEPS_DIR=${{runner.temp}}/.cache" >> $GITHUB_ENV + echo "BOOST_VERSION=${{matrix.boostVersion}}" >> $GITHUB_ENV + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Cache dependencies + if: "!startsWith(runner.os, 'Windows')" + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{env.DEPS_DIR}} + key: ${{matrix.os}}-${{matrix.compiler}}-${{env.BOOST_VERSION}} + + - name: Install Compiler + if: "startsWith(runner.os, 'Linux')" + run: | + pkgs=${{matrix.compiler}} + pkgs=${pkgs/gcc-/g++-} + sudo apt install $pkgs + - name: Setup compiler + if: "!startsWith(runner.os, 'Windows')" + run: tools/ci/setupCompiler.sh + env: + COMPILER: ${{matrix.compiler}} + + - name: Install system packages (Linux) + if: "startsWith(runner.os, 'Linux')" + run: sudo apt install ccache libminiupnpc-dev + - name: Install system packages (OSX) + if: startsWith(runner.os, 'macOS') + run: brew install ccache cmake miniupnpc + + - name: Setup cmake + if: "!startsWith(runner.os, 'Windows')" + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2.2.0 + with: + cmake-version: '3.20.x' + + - name: Setup CCache + if: "!startsWith(runner.os, 'Windows')" + uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 + with: + key: ${{matrix.os}}-${{matrix.compiler}}-${{matrix.buildType}}-${{matrix.boostVersion}} + max-size: 200M + + - name: Install Boost + shell: bash + run: | + BOOST_ROOT="${DEPS_DIR}/boost${BOOST_VERSION}" + echo "BOOST_ROOT=${BOOST_ROOT}" >> $GITHUB_ENV + echo "ADDITIONAL_CMAKE_FLAGS=${ADDITIONAL_CMAKE_FLAGS} -DBoost_NO_SYSTEM_PATHS=ON -DBoost_NO_BOOST_CMAKE=ON" >> $GITHUB_ENV + SHARED="" + if [[ "${{runner.os}}" == macOS ]]; then SHARED="shared"; fi # Seems to be required + tools/ci/installBoost.sh "${BOOST_VERSION}" "${BOOST_ROOT}" "filesystem,test" $SHARED + + - name: Build + run: tools/ci/build.sh "${{matrix.buildType}}" "${ADDITIONAL_CMAKE_FLAGS}" + env: + GENERATOR: ${{matrix.generator}} diff --git a/libs/common/include/s25util/span.hpp b/libs/common/include/s25util/span.hpp index be99ed2..891191c 100644 --- a/libs/common/include/s25util/span.hpp +++ b/libs/common/include/s25util/span.hpp @@ -214,19 +214,19 @@ class span constexpr span() noexcept : s_(0, 0) {} - template, int> = 0> + template && E == dynamic_extent, int> = 0> constexpr span(I* f, size_type c) : s_(f, c) {} - template, int> = 0> + template && E != dynamic_extent, int> = 0> explicit constexpr span(I* f, size_type c) : s_(f, c) {} - template, int> = 0> + template && E == dynamic_extent, int> = 0> constexpr span(I* f, L* l) : s_(f, l - f) {} - template, int> = 0> + template && E != dynamic_extent, int> = 0> explicit constexpr span(I* f, L* l) : s_(f, l - f) {} @@ -242,11 +242,11 @@ class span constexpr span(const std::array& a) noexcept : s_(a.data(), N) {} - template, int> = 0> + template && E == dynamic_extent, int> = 0> constexpr span(R&& r) noexcept(noexcept(std::data(r)) && noexcept(r.size())) : s_(std::data(r), r.size()) {} - template, int> = 0> + template && E != dynamic_extent, int> = 0> explicit constexpr span(R&& r) noexcept(noexcept(std::data(r)) && noexcept(r.size())) : s_(std::data(r), r.size()) {} diff --git a/tools/ci/build.sh b/tools/ci/build.sh new file mode 100755 index 0000000..5d53252 --- /dev/null +++ b/tools/ci/build.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright (C) 2005 - 2025 Settlers Freaks +# +# SPDX-License-Identifier: GPL-2.0-or-later + +set -euo pipefail + +# Required by the tests +export USER="${USER:-TestUser}'" + +BUILD_TYPE="${1}" +CMAKE_FLAGS="${2}" + +mkdir build && cd build + +if [[ "${TRAVIS_OS_NAME:-}" == "windows" ]] || [[ "${RUNNER_OS:-}" == "Windows" ]]; then + GENERATOR=${GENERATOR:-Visual Studio 17 2022} + BUILD_FLAGS="" +else + GENERATOR="Unix Makefiles" + BUILD_FLAGS="-j3" +fi + +cmake --version + +# shellcheck disable=SC2086 +cmake \ + -G "$GENERATOR" \ + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ + -DRTTR_ENABLE_WERROR=ON \ + -DCMAKE_INSTALL_PREFIX="$PWD/installed" \ + ${CMAKE_FLAGS} \ + .. + +cmake --build . --target install --config "${BUILD_TYPE}" -- $BUILD_FLAGS + +# Execute tests +export RTTR_DISABLE_ASSERT_BREAKPOINT=1 +export BOOST_TEST_LOG_LEVEL=message +export BOOST_TEST_REPORT_LEVEL=detailed +ctest --build-config "${BUILD_TYPE}" --output-on-failure -j2 diff --git a/tools/ci/checkUTF8.sh b/tools/ci/checkUTF8.sh new file mode 100755 index 0000000..666ce89 --- /dev/null +++ b/tools/ci/checkUTF8.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Copyright (C) 2005 - 2021 Settlers Freaks +# +# SPDX-License-Identifier: GPL-2.0-or-later + +set -euo pipefail + +# Try to convert all source files to UTF-8 to detect encoding errors +# Execute in the project folder (s25client) +find . -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.tpp' -o -name '*.h' \) -exec iconv -f UTF-8 > /dev/null {} \; diff --git a/tools/ci/setupCompiler.sh b/tools/ci/setupCompiler.sh new file mode 100755 index 0000000..d964dfb --- /dev/null +++ b/tools/ci/setupCompiler.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Copyright (C) 2005 - 2021 Settlers Freaks +# +# SPDX-License-Identifier: GPL-2.0-or-later + +set -euo pipefail + +CC="$COMPILER" + +if [[ "$CC" =~ clang ]]; then + CXX=${CC/clang/clang++} +elif [[ "$CC" =~ gcc ]]; then + CXX=${CC/gcc/g++} +fi +ver=7 # default +if [[ "$CC" =~ gcc- ]]; then + ver="${CC##*gcc-}" +fi +GCOV=gcov-${ver} +echo "CC=$CC" >> $GITHUB_ENV +echo "CXX=$CXX" >> $GITHUB_ENV +echo "GCOV=$GCOV" >> $GITHUB_ENV diff --git a/tools/ci/staticValidation.sh b/tools/ci/staticValidation.sh new file mode 100755 index 0000000..6ee2a7d --- /dev/null +++ b/tools/ci/staticValidation.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Copyright (C) 2005 - 2021 Settlers Freaks +# +# SPDX-License-Identifier: GPL-2.0-or-later + +set -euo pipefail + +SRC_DIR="${1:?SRC_DIR missing}" +scriptPath=$(dirname "$(readlink -f "$0")") + +cd "${SRC_DIR}" + +nonUTF8Files="$("$scriptPath/checkUTF8.sh")" +if [[ "${nonUTF8Files}" != "" ]]; then + echo "Files not in UTF8 encoding: ${nonUTF8Files}" + exit 1 +fi + +canonicalBugs="$(grep -r -l --include \*.h --include \*.cpp --include \*.hpp --include \*.tpp "::canonical(" || true)" +if [[ "${canonicalBugs}" != "" ]]; then + echo "Following files use buggy boost::filesystem::canonical: ${canonicalBugs}" + echo "If this is only used on non-windows use canonical unqualified: using bfs::canonical; canonical(...)" + exit 1 +fi