Skip to content

Commit 2c90748

Browse files
authored
feature: additional github workflows (#17)
* Initial Unit Tests Workflow * Include additional packages * Update warnings and pr template * Additional workflow * remove format workflow * fix depedency issues + formatting * fix public issue with package in cmake * windows installation fix * windows specific cmakes * Update windows private cmake * remove windows support
1 parent db69d9b commit 2c90748

File tree

11 files changed

+206
-54
lines changed

11 files changed

+206
-54
lines changed

.clang-format

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ IncludeCategories:
6262
# Standard library
6363
- Regex: '^<[a-z_]+>'
6464
Priority: 4
65-
# Windows headers
66-
- Regex: '^<windows\.h>'
67-
Priority: 5
6865
# ODBC headers
6966
- Regex: '^<sql'
70-
Priority: 6
67+
Priority: 5
7168
# Third-party libraries
7269
- Regex: '.*'
73-
Priority: 7
70+
Priority: 6
7471

7572
# Other formatting
7673
BinPackArguments: true

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ assignees: ''
1111
<!-- A clear and concise description of what the bug is -->
1212

1313
## Environment
14-
- **OS**: <!-- e.g., macOS 14.0, Ubuntu 22.04, Windows 11 -->
15-
- **Compiler**: <!-- e.g., GCC 11.2, Clang 14, MSVC 2022 -->
14+
- **OS**: <!-- e.g., macOS 14.0, Ubuntu 22.04 -->
15+
- **Compiler**: <!-- e.g., GCC 11.2, Clang 14 -->
1616
- **SDK Version**: <!-- e.g., 0.3.0 -->
1717
- **CMake Version**: <!-- e.g., 3.25.0 -->
1818
- **ODBC Driver**: <!-- e.g., Simba Spark ODBC Driver 2.6.26 -->

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Closes #
2020
- [ ] Added/updated tests
2121
- [ ] All tests pass (`make test`)
2222
- [ ] Tested manually
23+
- [ ] Build and test workflow is successful
2324

2425
## Checklist
2526
- [ ] Code follows style guidelines (`make format`)

.github/workflows/ci.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Build & Test
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
cross-platform-tests:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest]
14+
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Install dependencies (Ubuntu)
22+
if: runner.os == 'Linux'
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y \
26+
cmake \
27+
unixodbc-dev \
28+
libcurl4-openssl-dev \
29+
libspdlog-dev \
30+
libfmt-dev \
31+
nlohmann-json3-dev \
32+
lcov
33+
34+
- name: Install dependencies (macOS)
35+
if: runner.os == 'macOS'
36+
run: |
37+
brew install \
38+
cmake \
39+
unixodbc \
40+
curl \
41+
spdlog \
42+
fmt \
43+
nlohmann-json
44+
45+
- name: Configure CMake
46+
run: |
47+
mkdir -p build
48+
cd build
49+
if [ "$RUNNER_OS" == "macOS" ]; then
50+
cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/opt/homebrew ..
51+
else
52+
cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
53+
fi
54+
55+
- name: Build
56+
run: |
57+
cd build
58+
cmake --build . --parallel $(nproc 2>/dev/null || sysctl -n hw.ncpu)
59+
60+
- name: Run unit tests
61+
run: |
62+
cd build
63+
ctest --output-on-failure --verbose
64+
65+
code-coverage:
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Install dependencies
73+
run: |
74+
sudo apt-get update
75+
sudo apt-get install -y \
76+
cmake \
77+
unixodbc-dev \
78+
libcurl4-openssl-dev \
79+
libspdlog-dev \
80+
libfmt-dev \
81+
nlohmann-json3-dev \
82+
lcov
83+
84+
- name: Configure CMake with Coverage
85+
run: |
86+
mkdir -p build
87+
cd build
88+
cmake -DBUILD_TESTS=ON \
89+
-DCMAKE_BUILD_TYPE=Debug \
90+
-DCMAKE_CXX_FLAGS="--coverage -g -O0" \
91+
-DCMAKE_C_FLAGS="--coverage -g -O0" \
92+
..
93+
94+
- name: Build
95+
run: |
96+
cd build
97+
cmake --build . --parallel $(nproc)
98+
99+
- name: Run unit tests
100+
run: |
101+
cd build
102+
ctest --output-on-failure --verbose
103+
104+
- name: Generate coverage report
105+
run: |
106+
cd build
107+
lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch --ignore-errors gcov
108+
lcov --remove coverage.info '/usr/*' '*/tests/*' '*/googletest/*' --output-file coverage.info --ignore-errors unused
109+
lcov --list coverage.info
110+
111+
- name: Upload coverage to Codecov
112+
uses: codecov/codecov-action@v4
113+
with:
114+
files: ./build/coverage.info
115+
fail_ci_if_error: false
116+
verbose: true

.github/workflows/codeql.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CodeQL Security Scan
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
schedule:
9+
# Run every Monday at 00:00 UTC
10+
- cron: '0 0 * * 1'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze C++
15+
runs-on: ubuntu-latest
16+
permissions:
17+
security-events: write
18+
actions: read
19+
contents: read
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Install dependencies
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y \
29+
cmake \
30+
unixodbc-dev \
31+
libcurl4-openssl-dev \
32+
libspdlog-dev \
33+
libfmt-dev \
34+
nlohmann-json3-dev
35+
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@v3
38+
with:
39+
languages: cpp
40+
queries: security-extended
41+
42+
- name: Configure CMake
43+
run: |
44+
mkdir -p build
45+
cd build
46+
cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..
47+
48+
- name: Build
49+
run: |
50+
cd build
51+
cmake --build . --parallel $(nproc)
52+
53+
- name: Perform CodeQL Analysis
54+
uses: github/codeql-action/analyze@v3
55+
with:
56+
category: "/language:cpp"

CMakeLists.txt

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ option(BUILD_TESTS "Build tests" OFF)
4444
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
4545

4646
# Platform-specific configuration
47-
if(WIN32)
48-
# Windows uses odbc32
49-
set(ODBC_LIBRARIES odbc32)
50-
elseif(APPLE)
47+
if(APPLE)
5148
# macOS: Prefer Homebrew paths on Apple Silicon
5249
if(NOT CMAKE_PREFIX_PATH AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
5350
list(PREPEND CMAKE_PREFIX_PATH "/opt/homebrew")
@@ -170,11 +167,13 @@ target_include_directories(databricks_sdk
170167
)
171168

172169
# Link ODBC libraries
173-
target_link_libraries(databricks_sdk PRIVATE
174-
${ODBC_LIBRARIES}
175-
spdlog::spdlog
176-
CURL::libcurl
177-
nlohmann_json::nlohmann_json
170+
target_link_libraries(databricks_sdk
171+
PRIVATE
172+
${ODBC_LIBRARIES}
173+
spdlog::spdlog
174+
CURL::libcurl
175+
PUBLIC
176+
nlohmann_json::nlohmann_json
178177
)
179178

180179
# Set library properties
@@ -183,22 +182,15 @@ set_target_properties(databricks_sdk PROPERTIES
183182
SOVERSION ${PROJECT_VERSION_MAJOR}
184183
)
185184

186-
# Set RPATH for finding ODBC libraries at runtime (Unix/Linux/macOS only)
187-
if(NOT WIN32)
188-
# Use RPATH to find shared libraries relative to executable
189-
set_target_properties(databricks_sdk PROPERTIES
190-
BUILD_RPATH "${ODBC_LIBRARY_DIR};/usr/local/lib;/opt/homebrew/lib;/opt/local/lib"
191-
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;/usr/local/lib;/opt/homebrew/lib;/opt/local/lib"
192-
INSTALL_RPATH_USE_LINK_PATH TRUE
193-
)
194-
endif()
185+
# Set RPATH for finding ODBC libraries at runtime
186+
set_target_properties(databricks_sdk PROPERTIES
187+
BUILD_RPATH "${ODBC_LIBRARY_DIR};/usr/local/lib;/opt/homebrew/lib;/opt/local/lib"
188+
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;/usr/local/lib;/opt/homebrew/lib;/opt/local/lib"
189+
INSTALL_RPATH_USE_LINK_PATH TRUE
190+
)
195191

196192
# Compiler warnings
197-
if(MSVC)
198-
target_compile_options(databricks_sdk PRIVATE /W4)
199-
else()
200-
target_compile_options(databricks_sdk PRIVATE -Wall -Wextra -Wpedantic)
201-
endif()
193+
target_compile_options(databricks_sdk PRIVATE -Wall -Wextra -Wpedantic)
202194

203195
# Examples
204196
if(BUILD_EXAMPLES)

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Thank you for your interest in contributing to the Databricks C++ SDK! This docu
1414

1515
### Prerequisites
1616

17-
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
17+
- C++17 compatible compiler (GCC 7+, Clang 5+)
1818
- CMake 3.14 or higher
1919
- ODBC Driver Manager (unixODBC on Linux/macOS)
2020
- [Simba Spark ODBC Driver](https://www.databricks.com/spark/odbc-drivers-download)
@@ -248,7 +248,7 @@ TEST(ClientTest, QueryWithValidParameters) {
248248
4. **Style**: Does it follow project conventions?
249249
5. **Performance**: Any performance implications?
250250
6. **Security**: Any security concerns?
251-
7. **Compatibility**: Works on Linux/macOS/Windows?
251+
7. **Compatibility**: Works on Linux/macOS?
252252

253253
### Responding to Feedback
254254

include/databricks/internal/secure_string.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
#include <cstring>
77
#include <memory>
88
#include <string>
9-
10-
#ifdef _WIN32
11-
# include <windows.h>
12-
#else
13-
# include <sys/mman.h>
14-
#endif
9+
#include <sys/mman.h>
1510

1611
namespace databricks {
1712
namespace internal {
@@ -86,26 +81,16 @@ template <typename T> class SecureAllocator {
8681
* @brief Lock memory pages to prevent swapping to disk
8782
*/
8883
static void lock_memory(void* ptr, size_type size) noexcept {
89-
#ifdef _WIN32
90-
// Use VirtualLock on Windows
91-
// Ignore failures - locking is best-effort
92-
VirtualLock(ptr, size);
93-
#else
9484
// Use mlock on POSIX systems
9585
// Ignore failures - locking is best-effort
9686
mlock(ptr, size);
97-
#endif
9887
}
9988

10089
/**
10190
* @brief Unlock memory pages
10291
*/
10392
static void unlock_memory(void* ptr, size_type size) noexcept {
104-
#ifdef _WIN32
105-
VirtualUnlock(ptr, size);
106-
#else
10793
munlock(ptr, size);
108-
#endif
10994
}
11095

11196
/**

src/core/client.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include <stdexcept>
2020
#include <thread>
2121

22-
#ifdef _WIN32
23-
# include <windows.h>
24-
#endif
2522
#include <sql.h>
2623
#include <sqlext.h>
2724

tests/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ FetchContent_Declare(
88
GIT_TAG v1.14.0
99
)
1010

11-
# For Windows: Prevent overriding the parent project's compiler/linker settings
1211
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
1312

1413
FetchContent_MakeAvailable(googletest)
@@ -20,13 +19,21 @@ enable_testing()
2019
file(GLOB_RECURSE UNIT_TEST_SOURCES CONFIGURE_DEPENDS "unit/**/*.cpp")
2120
add_executable(unit_tests ${UNIT_TEST_SOURCES})
2221

22+
# Find fmt package (spdlog dependency)
23+
find_package(fmt QUIET)
24+
2325
target_link_libraries(unit_tests
2426
PRIVATE
2527
databricks_sdk
2628
GTest::gtest_main
2729
GTest::gmock_main
2830
)
2931

32+
# Link fmt if found (needed on some systems where spdlog uses external fmt)
33+
if(fmt_FOUND)
34+
target_link_libraries(unit_tests PRIVATE fmt::fmt)
35+
endif()
36+
3037
target_include_directories(unit_tests
3138
PRIVATE
3239
${CMAKE_CURRENT_SOURCE_DIR}/../include

0 commit comments

Comments
 (0)