-
Notifications
You must be signed in to change notification settings - Fork 11
142 lines (117 loc) · 4.42 KB
/
ctest_pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: ctest_pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
unit_tests:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-22.04
strategy:
matrix:
compiler: [clang, gcc]
dependency_loader: [fetch_content, vcpkg]
build_type: [debug, release]
steps:
- name: install deps
run: |
sudo apt-get update -y
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get install -y gcc-11 g++-11 clang-14 libclang-cpp14-dev libclang-14-dev ninja-build
sudo apt-get install -y curl zip unzip tar pkg-config python3.10-venv flex bison
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Restore artifacts, or setup vcpkg (do not install any package)
uses: lukka/run-vcpkg@v10
with:
vcpkgDirectory: '${{ github.workspace }}/vendor/vcpkg'
- name: Run CMake consuming CMakePreset.json and vcpkg.json by mean of vcpkg.
uses: lukka/run-cmake@v10
with:
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
configurePreset: '${{ matrix.compiler }}-${{ matrix.dependency_loader }}-${{ matrix.build_type }}'
buildPreset: '${{ matrix.compiler }}-${{ matrix.dependency_loader }}-${{ matrix.build_type }}'
testPreset: '${{ matrix.compiler }}-${{ matrix.dependency_loader }}-${{ matrix.build_type }}'
formatting:
runs-on: ubuntu-22.04
steps:
- name: install deps
run: |
sudo apt-get update -y
sudo apt-get install -y clang-format-15
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Run clang-format
run: |
./scripts/format.sh --check
fetch_content_integration:
runs-on: ubuntu-22.04
steps:
- name: install deps
run: |
sudo apt-get update -y
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get install -y gcc-11 g++-11 clang-14 libclang-cpp14-dev libclang-14-dev ninja-build
sudo apt-get install -y curl zip unzip tar pkg-config python3.10-venv flex bison git
- name: Set SHA to fetch
run: echo "SHA=${{github.event.pull_request.head.sha}}" >> $GITHUB_ENV
if: ${{ github.event_name == 'pull_request'}}
- name: Set SHA to fetch
run: echo "SHA=${{github.sha}}" >> $GITHUB_ENV
if: ${{ github.event_name == 'push'}}
- name: Create CMakeLists.txt
run: |
cat <<EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(tsmp_application)
include(FetchContent)
FetchContent_Declare(
tsmp
GIT_REPOSITORY https://github.com/${{ github.repository }}.git
GIT_TAG ${SHA}
)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(catch2 tsmp)
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
include(CTest NO_POLICY_SCOPE)
include(Catch)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE Catch2::Catch2WithMain tsmp::json)
enable_reflection(main)
catch_discover_tests(main)
EOF
- name: Cat CMakeLists.txt
run: cat CMakeLists.txt
- name: Create Test
run: |
cat <<EOF > main.cpp
#include <catch2/catch_all.hpp>
#include <tsmp/json.hpp>
struct foo_t {
std::string hello = "world";
};
TEST_CASE("FetchContent integration test", "[unit]") {
foo_t hello_world;
REQUIRE(tsmp::to_json(hello_world) == R"({"hello":"world"})");
}
EOF
- name: Configure
run: cmake -B binary_dir -DCMAKE_CXX_COMPILER=g++-11
- name: Build
run: cmake --build binary_dir
- name: Run Test
run: cmake --build binary_dir --target test