Skip to content

Commit 7a0bd91

Browse files
committed
Add CI scripts (#1)
1 parent 5d39f83 commit 7a0bd91

File tree

11 files changed

+261
-52
lines changed

11 files changed

+261
-52
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: CMake on multiple platforms
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
types: [ "opened", "reopened", "synchronize", "ready_for_review" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
fail-fast: false # ensure we don't stop after 1 failure to always have a complete picture of what is failing
15+
16+
# Set up a matrix to run the following configurations:
17+
# - ubuntu Debug/Release clang/gcc
18+
# - windows Debug/Release cl
19+
# - macos Debug/Release clang
20+
matrix:
21+
os: [ubuntu-latest, macos-latest] # , windows-latest
22+
build_type: [Release, Debug]
23+
c_compiler: [gcc, clang, cl]
24+
include:
25+
# - os: windows-latest
26+
# c_compiler: cl
27+
# cpp_compiler: cl
28+
- os: ubuntu-latest
29+
c_compiler: gcc
30+
cpp_compiler: g++
31+
- os: ubuntu-latest
32+
c_compiler: clang
33+
cpp_compiler: clang++
34+
- os: macos-latest
35+
c_compiler: clang
36+
cpp_compiler: clang++
37+
exclude:
38+
- os: windows-latest
39+
c_compiler: gcc
40+
- os: windows-latest
41+
c_compiler: clang
42+
- os: ubuntu-latest
43+
c_compiler: cl
44+
- os: macos-latest
45+
c_compiler: cl
46+
- os: macos-latest
47+
c_compiler: gcc
48+
49+
steps:
50+
- uses: actions/checkout@v3
51+
52+
- name: Set reusable strings
53+
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
54+
id: strings
55+
shell: bash
56+
run: |
57+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
58+
59+
- name: Cache VCPKG (Windows)
60+
if: runner.os == 'Windows'
61+
uses: actions/cache@v3
62+
with:
63+
path: ${{ env.VCPKG_ROOT }}
64+
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ hashFiles('vcpkg.json') }}
65+
66+
- name: Install OpenSSL (Windows)
67+
if: runner.os == 'Windows'
68+
shell: powershell
69+
run: |
70+
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
71+
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
72+
vcpkg install
73+
74+
- name: Configure CMake
75+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
76+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
77+
run: >
78+
cmake -B ${{ steps.strings.outputs.build-output-dir }}
79+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
80+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
81+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
82+
-DCPPSOCKETS_TESTS=TRUE
83+
-S ${{ github.workspace }}
84+
85+
- name: Build
86+
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
87+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
88+
89+
- name: Test
90+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
91+
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
92+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
93+
run: ctest --build-config ${{ matrix.build_type }} --test-dir tests
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: "Code Scanning"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ "master" ]
9+
schedule:
10+
- cron: '20 3 * * 0'
11+
12+
jobs:
13+
codeql:
14+
name: CodeQL
15+
# Runner size impacts CodeQL analysis time. To learn more, please see:
16+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
17+
# - https://gh.io/supported-runners-and-hardware-resources
18+
# - https://gh.io/using-larger-runners
19+
# Consider using larger runners for possible analysis time improvements.
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 360
22+
permissions:
23+
actions: read
24+
contents: read
25+
security-events: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v3
30+
31+
# Initializes the CodeQL tools for scanning.
32+
- name: Initialize CodeQL
33+
uses: github/codeql-action/init@v2
34+
with:
35+
languages: 'c-cpp'
36+
# If you wish to specify custom queries, you can do so here or in a config file.
37+
# By default, queries listed here will override any specified in a config file.
38+
# Prefix the list here with "+" to use these queries and those in the config file.
39+
40+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
41+
# queries: security-extended,security-and-quality
42+
43+
44+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
45+
# If this step fails, then you should remove it and run the build manually (see below)
46+
- name: Autobuild
47+
uses: github/codeql-action/autobuild@v2
48+
49+
# ℹ️ Command-line programs to run using the OS shell.
50+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
51+
52+
# If the Autobuild fails above, remove it and uncomment the following three lines.
53+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
54+
55+
# - run: |
56+
# echo "Run, Build Application using script"
57+
# ./location_of_script_within_repo/buildscript.sh
58+
59+
- name: Perform CodeQL Analysis
60+
uses: github/codeql-action/analyze@v2
61+
with:
62+
category: "/language:c-cpp"
63+
64+
flawfinder:
65+
name: Flawfinder
66+
runs-on: ubuntu-latest
67+
permissions:
68+
actions: read
69+
contents: read
70+
security-events: write
71+
steps:
72+
- name: Checkout code
73+
uses: actions/checkout@v3
74+
75+
- name: flawfinder_scan
76+
uses: david-a-wheeler/flawfinder@8e4a779ad59dbfaee5da586aa9210853b701959c
77+
with:
78+
arguments: '--sarif ./'
79+
output: 'flawfinder_results.sarif'
80+
81+
- name: Upload analysis results to GitHub Security tab
82+
uses: github/codeql-action/upload-sarif@v2
83+
with:
84+
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
85+
86+
# microsoft-analyze:
87+
# permissions:
88+
# contents: read # for actions/checkout to fetch code
89+
# security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
90+
# actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
91+
# name: Microsoft Analyze
92+
# runs-on: windows-latest
93+
94+
# steps:
95+
# - name: Checkout repository
96+
# uses: actions/checkout@v3
97+
98+
# - name: Configure CMake
99+
# run: cmake -B ./build
100+
101+
# # Build is not required unless generated source files are used
102+
# # - name: Build CMake
103+
# # run: cmake --build ./build
104+
105+
# - name: Initialize MSVC Code Analysis
106+
# uses: microsoft/msvc-code-analysis-action@04825f6d9e00f87422d6bf04e1a38b1f3ed60d99
107+
# # Provide a unique ID to access the sarif output path
108+
# id: run-analysis
109+
# with:
110+
# cmakeBuildDirectory: ${{ env.build }}
111+
# # Ruleset file that will determine what checks will be run
112+
# ruleset: NativeRecommendedRules.ruleset
113+
114+
# # Upload SARIF file to GitHub Code Scanning Alerts
115+
# - name: Upload SARIF to GitHub
116+
# uses: github/codeql-action/upload-sarif@v2
117+
# with:
118+
# sarif_file: ${{ steps.run-analysis.outputs.sarif }}
119+
120+
# # Upload SARIF file as an Artifact to download and view
121+
# # - name: Upload SARIF as an Artifact
122+
# # uses: actions/upload-artifact@v3
123+
# # with:
124+
# # name: sarif-file
125+
# # path: ${{ steps.run-analysis.outputs.sarif }}

CMakeLists.txt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Author Francois Michaut
55
##
66
## Started on Sun Aug 28 19:26:51 2022 Francois Michaut
7-
## Last update Sat Dec 2 10:33:43 2023 Francois Michaut
7+
## Last update Sat Dec 2 17:45:28 2023 Francois Michaut
88
##
99
## CMakeLists.txt : CMake to build the CppSockets library
1010
##
@@ -26,20 +26,11 @@ add_library(cppsockets
2626
source/TlsSocket.cpp
2727
)
2828
target_include_directories(cppsockets PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
29-
# target_include_directories(cppsockets INTERFACE $<INSTALL_INTERFACE:include>)
3029

3130
find_package(OpenSSL 3.0 COMPONENTS SSL)
3231
target_link_libraries(cppsockets OpenSSL::SSL)
3332

34-
add_custom_target(test
35-
COMMAND ${CMAKE_COMMAND} --log-level=WARNING
36-
-B "${CMAKE_CURRENT_BINARY_DIR}/tests"
37-
-S "${CMAKE_CURRENT_SOURCE_DIR}/tests"
38-
-G ${CMAKE_GENERATOR}
39-
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color
40-
--switch=$(COLOR) --cyan "Building tests..."
41-
COMMAND ${CMAKE_COMMAND}
42-
--build "${CMAKE_CURRENT_BINARY_DIR}/tests" -- --quiet
43-
COMMAND ${CMAKE_MAKE_PROGRAM}
44-
-C "${CMAKE_CURRENT_BINARY_DIR}/tests" test ARGS=--output-on-failure
45-
)
33+
option(CPPSOCKETS_TESTS "TRUE to build the libcppsockets tests" FALSE)
34+
if(CPPSOCKETS_TESTS)
35+
add_subdirectory(tests)
36+
endif()

include/CppSockets/Address.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sun Feb 13 17:09:05 2022 Francois Michaut
7-
** Last update Sat Nov 11 16:57:43 2023 Francois Michaut
7+
** Last update Sat Dec 9 08:52:22 2023 Francois Michaut
88
**
99
** Address.hpp : Interface to represent network addresses
1010
*/
@@ -44,6 +44,7 @@ namespace CppSockets {
4444
Endpoint(T addr, std::uint16_t port) :
4545
addr(std::move(addr)), port(port), str(makeString())
4646
{};
47+
virtual ~Endpoint() = default;
4748

4849
[[nodiscard]] std::uint16_t getPort() const override {
4950
return port;
@@ -57,8 +58,8 @@ namespace CppSockets {
5758
return str;
5859
}
5960
private:
60-
std::uint16_t port;
6161
T addr;
62+
std::uint16_t port;
6263
std::string str;
6364
};
6465
}

include/CppSockets/Socket.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sat Jan 15 01:17:42 2022 Francois Michaut
7-
** Last update Tue Nov 14 19:37:59 2023 Francois Michaut
7+
** Last update Sat Dec 9 08:55:07 2023 Francois Michaut
88
**
99
** Socket.hpp : Portable C++ socket class
1010
*/
@@ -29,8 +29,8 @@
2929
#include "CppSockets/Address.hpp"
3030

3131
namespace CppSockets {
32-
static void init(bool init_ssl = true, bool init_wsa = true);
33-
static void deinit(bool deinit_ssl = true, bool deinit_wsa = true);
32+
void init(bool init_ssl = true, bool init_wsa = true);
33+
void deinit(bool deinit_ssl = true, bool deinit_wsa = true);
3434

3535
class Socket {
3636
public:

source/IPv4.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sun Feb 13 18:52:28 2022 Francois Michaut
7-
** Last update Thu Jul 20 23:08:49 2023 Francois Michaut
7+
** Last update Sat Dec 2 16:17:43 2023 Francois Michaut
88
**
99
** IPv4.cpp : Implementation of IPv4 class
1010
*/
@@ -14,13 +14,17 @@
1414

1515
#include <stdexcept>
1616

17-
#include <arpa/inet.h>
17+
#ifdef OS_WINDOWS
18+
#include <ws2tcpip.h>
19+
#else
20+
#include <arpa/inet.h>
21+
#endif
1822

1923
namespace CppSockets {
2024
IPv4::IPv4(std::uint32_t addr) :
2125
addr(htonl(addr))
2226
{
23-
struct in_addr tmp {this->addr};
27+
struct in_addr tmp {.s_addr = this->addr};
2428

2529
str = inet_ntoa(tmp);
2630
}
@@ -30,7 +34,7 @@ namespace CppSockets {
3034
{
3135
struct in_addr in;
3236

33-
if (inet_aton(addr, &in) == 0)
37+
if (inet_pton(AF_INET, addr, &in) != 1)
3438
throw std::runtime_error("Invalid IPv4 address");
3539
this->addr = in.s_addr;
3640
}

0 commit comments

Comments
 (0)