Skip to content

Commit 4581508

Browse files
committed
Refactor: github workflows, project files
1 parent 8637bbe commit 4581508

File tree

9 files changed

+137
-62
lines changed

9 files changed

+137
-62
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ on:
1010
- 'CMakeLists.txt'
1111
- 'CMakePresets.json'
1212
- '.github/workflows/ci.yml'
13+
14+
pull_request:
15+
branches: [ master ]
16+
paths:
17+
- '**/*.cpp'
18+
- '**/*.hpp'
19+
- 'cmake/**'
20+
- 'CMakeLists.txt'
21+
- 'CMakePresets.json'
22+
- '.github/workflows/ci.yml'
23+
1324
workflow_dispatch:
1425

1526
jobs:
@@ -21,52 +32,56 @@ jobs:
2132
os: [ubuntu-latest]
2233
compiler: [gcc, clang]
2334
build_type: [Sanitize, Release]
35+
env:
36+
CMAKE_C_COMPILER_LAUNCHER: ccache
37+
CMAKE_CXX_COMPILER_LAUNCHER: ccache
38+
CCACHE_DIR: ${{ github.workspace }}/.ccache
2439

2540
steps:
2641
- name: Checkout repository
2742
uses: actions/checkout@v4
2843
with: { fetch-depth: 0 }
2944

30-
- name: Install CMake
45+
- name: Cache APT packages
46+
uses: actions/cache@v3
47+
with:
48+
path: /var/cache/apt
49+
key: ${{ runner.os }}-apt-ci-${{ hashFiles('.github/workflows/ci.yml') }}
50+
restore-keys: |
51+
${{ runner.os }}-apt-ci-
52+
53+
- name: Install CMake and Ninja
3154
uses: lukka/get-cmake@latest
55+
with:
56+
cmakeVersion: ^3.28.0
57+
ninjaVersion: ^1.11.0
3258

33-
- name: Install build tools
34-
run: sudo apt update && sudo apt install -y clang lld gcc g++ ccache ninja-build
59+
- name: Install dependencies
60+
run: |
61+
sudo apt-get -qq update
62+
sudo apt-get -qq install -y clang lld gcc g++ ccache --no-install-recommends
3563
36-
- name: Restore ccache
64+
- name: Cache ccache
3765
uses: actions/cache@v3
3866
with:
3967
path: ${{ github.workspace }}/.ccache
40-
key: ${{ runner.os }}-ccache-${{ matrix.compiler }}-${{ matrix.build_type }}
68+
key: ${{ runner.os }}-ccache-${{ matrix.compiler }}-${{ matrix.build_type }}-${{ hashFiles('CMakeLists.txt') }}
69+
restore-keys: |
70+
${{ runner.os }}-ccache-
4171
42-
- name: Restore build directory
72+
- name: Cache build directory
4373
uses: actions/cache@v3
4474
with:
45-
path: build/${{ matrix.compiler }}-${{ matrix.build_type }}
46-
key: ${{ runner.os }}-ccache-${{ matrix.compiler }}-${{ matrix.build_type }}
75+
path: build/
76+
key: ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.build_type }}-${{ github.sha }}
77+
restore-keys: |
78+
${{ runner.os }}-build-
4779
4880
- name: Configure with CMake Preset
49-
env:
50-
CCACHE_DIR: ${{ github.workspace }}/.ccache
51-
CMAKE_C_COMPILER_LAUNCHER: ccache
52-
CMAKE_CXX_COMPILER_LAUNCHER: ccache
5381
run: cmake --preset ${{ matrix.compiler }}-${{ matrix.build_type }}
5482

5583
- name: Build (Ninja)
5684
run: cmake --build --preset ${{ matrix.compiler }}-${{ matrix.build_type }}
5785

5886
- name: Run tests (ctest)
5987
run: ctest --preset ${{ matrix.compiler }}-${{ matrix.build_type }}
60-
61-
# not sure if next steps are required
62-
- name: Save ccache
63-
uses: actions/cache@v3
64-
with:
65-
path: ${{ github.workspace }}/.ccache
66-
key: ${{ runner.os }}-ccache-${{ matrix.compiler }}-${{ matrix.build_type }}
67-
68-
- name: Save build directory
69-
uses: actions/cache@v3
70-
with:
71-
path: build/${{ matrix.compiler }}-${{ matrix.build_type }}
72-
key: ${{ runner.os }}-ccache-${{ matrix.compiler }}-${{ matrix.build_type }}

.github/workflows/clang-format.yml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,67 @@ name: clang-format
22

33
on:
44
push:
5-
branches:
6-
- master
5+
branches: [ master ]
76
paths:
87
- '**/*.cpp'
98
- '**/*.hpp'
109
- '.clang-format'
10+
- 'cmake/Tooling.cmake'
1111
- '.github/workflows/clang-format.yml'
12+
1213
pull_request:
14+
branches: [ master ]
1315
paths:
1416
- '**/*.cpp'
1517
- '**/*.hpp'
1618
- '.clang-format'
19+
- 'cmake/Tooling.cmake'
1720
- '.github/workflows/clang-format.yml'
1821

22+
workflow_dispatch:
23+
1924
jobs:
2025
format-check:
2126
name: Check clang-format
2227
runs-on: ubuntu-latest
28+
env:
29+
CMAKE_PRESET_NAME: gcc-Release
2330

2431
steps:
25-
- name: Checkout code
32+
- name: Checkout repository
2633
uses: actions/checkout@v4
34+
with: { fetch-depth: 0 }
35+
36+
- name: Cache APT packages
37+
uses: actions/cache@v3
38+
with:
39+
path: /var/cache/apt
40+
key: ${{ runner.os }}-apt-clang-format-${{ hashFiles('.github/workflows/clang-format.yml') }}
41+
restore-keys: |
42+
${{ runner.os }}-apt-clang-format-
43+
44+
- name: Install CMake and Ninja
45+
uses: lukka/get-cmake@latest
46+
with:
47+
cmakeVersion: ^3.28.0
48+
ninjaVersion: ^1.11.0
49+
50+
- name: Install dependencies
51+
run: |
52+
sudo apt-get -qq update
53+
sudo apt-get -qq install -y g++ gcc clang-format --no-install-recommends
2754
28-
- name: Install clang-format
29-
run: sudo apt update && sudo apt install -y clang-format cmake ninja-build g++ gcc
55+
- name: Cache build artifacts
56+
id: cache-build
57+
uses: actions/cache@v3
58+
with:
59+
path: build/
60+
key: ${{ runner.os }}-build-${{ github.sha }}
61+
restore-keys: |
62+
${{ runner.os }}-build-
3063
31-
- name: Configure project
32-
run: cmake --preset gcc-RelWithDebInfo
64+
- name: Configure with CMake Preset
65+
run: cmake --preset $CMAKE_PRESET_NAME -DENABLE_CLANG_FORMAT=ON
3366

3467
- name: Run clang-format
35-
run: cmake --build --preset gcc-RelWithDebInfo --target format-check
68+
run: cmake --build --preset $CMAKE_PRESET_NAME --target format-check

.github/workflows/clang-tidy.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,65 @@ name: clang-tidy
22

33
on:
44
push:
5-
branches:
6-
- master
5+
branches: [ master ]
76
paths:
87
- '**/*.cpp'
98
- '**/*.hpp'
109
- '.clang-tidy'
11-
- 'CMakePresets.json'
12-
- 'CMakeLists.txt'
10+
- 'cmake/Tooling.cmake'
1311
- '.github/workflows/clang-tidy.yml'
12+
1413
pull_request:
14+
branches: [ master ]
1515
paths:
1616
- '**/*.cpp'
1717
- '**/*.hpp'
1818
- '.clang-tidy'
19-
- 'CMakePresets.json'
20-
- 'CMakeLists.txt'
19+
- 'cmake/Tooling.cmake'
2120
- '.github/workflows/clang-tidy.yml'
2221

2322
jobs:
2423
lint:
25-
name: Clang-Tidy Analysis
24+
name: Check clang-tidy
2625
runs-on: ubuntu-latest
26+
env:
27+
CMAKE_PRESET_NAME: gcc-Release
2728

2829
steps:
29-
- name: Checkout code
30+
- name: Checkout repository
3031
uses: actions/checkout@v4
32+
with: { fetch-depth: 0 }
33+
34+
- name: Cache APT packages
35+
uses: actions/cache@v3
36+
with:
37+
path: /var/cache/apt
38+
key: ${{ runner.os }}-apt-clang-tidy-${{ hashFiles('.github/workflows/clang-tidy.yml') }}
39+
restore-keys: |
40+
${{ runner.os }}-apt-clang-tidy-
41+
42+
- name: Install CMake and Ninja
43+
uses: lukka/get-cmake@latest
44+
with:
45+
cmakeVersion: ^3.28.0
46+
ninjaVersion: ^1.11.0
3147

3248
- name: Install dependencies
33-
run: sudo apt update && sudo apt install -y clang-tidy cmake ninja-build g++ gcc
49+
run: |
50+
sudo apt-get -qq update
51+
sudo apt-get -qq install -y g++ gcc clang-tidy --no-install-recommends
52+
53+
- name: Cache build artifacts
54+
id: cache-build
55+
uses: actions/cache@v3
56+
with:
57+
path: build/
58+
key: ${{ runner.os }}-build-${{ github.sha }}
59+
restore-keys: |
60+
${{ runner.os }}-build-
3461
3562
- name: Configure project
36-
run: cmake --preset gcc-RelWithDebInfo
63+
run: cmake --preset $CMAKE_PRESET_NAME -DENABLE_CLANG_TIDY=ON
3764

3865
- name: Run clang-tidy
39-
run: cmake --build --preset gcc-RelWithDebInfo --target clang-tidy
66+
run: cmake --build --preset $CMAKE_PRESET_NAME --target clang-tidy

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111
# === Options ===
1212
include(Options)
1313

14-
# === Flags ===
14+
# === Compiler Flags ===
1515
include(CompilerFlags)
1616

1717
# === Helpers ===
1818
include(Helpers)
1919

20-
# === Core Library ===
20+
# === Coverage ===
21+
include(Coverage)
22+
23+
# === Library ===
2124
add_subdirectory(src)
2225

2326
# === App ===
@@ -39,9 +42,6 @@ endif()
3942
# === Developer Tooling (formatters, linters, etc.) ===
4043
include(Tooling)
4144

42-
# === Coverage ===
43-
include(Coverage)
44-
4545
# === Installation & Export ===
4646
include(install/InstallConfig)
4747

app/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include "modern_cpp/library.hpp"
44

55
int main() {
6-
const int LEFT = 10;
7-
const int RIGHT = 4;
6+
const int left = 10;
7+
const int right = 4;
88

9-
std::cout << "Add: " << modern_cpp::add(LEFT, RIGHT) << '\n';
10-
std::cout << "Subtract: " << modern_cpp::subtract(LEFT, RIGHT) << '\n';
9+
std::cout << "Add: " << modern_cpp::add(left, right) << '\n';
10+
std::cout << "Subtract: " << modern_cpp::subtract(left, right) << '\n';
1111

1212
return 0;
1313
}

benchmarks/benchmarks.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
#include "modern_cpp/library.hpp"
44

5-
static void bmAdd(benchmark::State &state) {
5+
static void benchAdd(benchmark::State &state) {
66
for (auto _ : state) { // NOLINT
7-
benchmark::DoNotOptimize(modern_cpp::add(1, 2)); // NOLINT (readability-magic-numbers)
7+
benchmark::DoNotOptimize(modern_cpp::add(1, 2)); // NOLINT(*-magic-numbers)
88
}
99
}
1010

11-
static void bmSubtract(benchmark::State &state) {
11+
static void benchSubtract(benchmark::State &state) {
1212
for (auto _ : state) { // NOLINT
13-
benchmark::DoNotOptimize(modern_cpp::subtract(5, 3)); // NOLINT (readability-magic-numbers)
13+
benchmark::DoNotOptimize(modern_cpp::subtract(5, 3)); // NOLINT(*-magic-numbers)
1414
}
1515
}
1616

17-
BENCHMARK(bmAdd); // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
18-
BENCHMARK(bmSubtract); // NOLINT (cppcoreguidelines-avoid-non-const-global-variables)
17+
BENCHMARK(benchAdd);
18+
BENCHMARK(benchSubtract);

cmake/Tooling.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# === Search All Source Files ===
1+
# === Search all source files ===
22
file(GLOB_RECURSE CORE_SOURCES
33
CONFIGURE_DEPENDS
44
${CMAKE_SOURCE_DIR}/src/*.cpp

include/modern_cpp/library.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/**
55
* @file library.hpp
6-
* @brief Arithmetic operations library (add, subtract, multiply).
6+
* @brief Arithmetic operations library (add, subtract, multiply, divide).
77
*/
88

99
namespace modern_cpp {

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ add_library(${PROJECT_NAME}_library STATIC
44

55
add_library(${PROJECT_NAME}::library ALIAS ${PROJECT_NAME}_library)
66

7-
target_compile_features(${PROJECT_NAME}_library PUBLIC cxx_std_20)
7+
target_compile_features(${PROJECT_NAME}_library PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
88

99
target_include_directories(${PROJECT_NAME}_library
1010
PUBLIC

0 commit comments

Comments
 (0)