Skip to content

Commit 60d2d18

Browse files
committed
Improve CLI + Added CI & Style
- Added clang-tidy - Added CI Script to build FileShare on different platforms - Building CLI or GUI is now optional - CLI now supports custom config file, as well as many commands in interactive mode (Config edit, peer management, send/list/receive file)
1 parent 67523b9 commit 60d2d18

File tree

11 files changed

+1261
-131
lines changed

11 files changed

+1261
-131
lines changed

.clang-tidy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Checks: '
2+
*,
3+
-llvmlibc-*,
4+
-android-*,
5+
-altera-*,
6+
-fuchsia*,
7+
-google-readability-todo,
8+
-cppcoreguidelines-init-variables,
9+
-cppcoreguidelines-pro-type-reinterpret-cast,
10+
-llvm-namespace-comment,
11+
-readability-implicit-bool-conversion,
12+
-google-explicit-constructor,
13+
-abseil-string-find-str-contains,
14+
-readability-avoid-return-with-void-value,
15+
-readability-convert-member-functions-to-static,
16+
17+
-google-readability-braces-around-statements,
18+
-google-readability-namespace-comments,
19+
-hicpp-special-member-functions,
20+
-hicpp-braces-around-statements,
21+
-hicpp-explicit-conversions
22+
'
23+
24+
WarningsAsErrors: 'bugprone-exception-escape'
25+
FormatStyle: 'none' # TODO: Replace with 'file' once we have a proper .clang-format file
26+
InheritParentConfig: true
27+
CheckOptions:
28+
misc-include-cleaner.MissingIncludes: 'false'
29+
misc-include-cleaner.IgnoreHeaders: 'CppSockets/OSDetection.*;.*Version.hpp'
30+
31+
bugprone-argument-comment.StrictMode: 1
32+
33+
# Readability
34+
readability-braces-around-statements.ShortStatementLines: 2
35+
36+
readability-identifier-naming.NamespaceCase: CamelCase
37+
38+
readability-identifier-length.IgnoredVariableNames: "^(fd|nb|n|ss|ec|is|os|_.*)$"
39+
readability-identifier-length.IgnoredParameterNames: "^(fd|n|is|os|_.*)$"
40+
41+
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: CMake on multiple platforms
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
types: [ "opened", "reopened", "synchronize", "ready_for_review" ]
9+
10+
jobs:
11+
build:
12+
runs-on: ${{ matrix.os }}
13+
14+
strategy:
15+
# ensure we don't stop after 1 failure to always have a complete picture of what is failing
16+
fail-fast: false
17+
18+
# Set up a matrix to run the following configurations:
19+
# - ubuntu Debug/Release clang/gcc
20+
# - windows Debug/Release cl
21+
# - macos Debug/Release clang
22+
matrix:
23+
os: [ubuntu-latest, macos-latest, windows-latest]
24+
build_type: [Release, Debug]
25+
c_compiler: [gcc, clang, cl]
26+
include:
27+
- os: windows-latest
28+
c_compiler: cl
29+
cpp_compiler: cl
30+
- os: ubuntu-latest
31+
c_compiler: gcc
32+
cpp_compiler: g++
33+
- os: ubuntu-latest
34+
c_compiler: clang
35+
cpp_compiler: clang++
36+
- os: macos-latest
37+
c_compiler: clang
38+
cpp_compiler: clang++
39+
exclude:
40+
- os: windows-latest
41+
c_compiler: gcc
42+
- os: windows-latest
43+
c_compiler: clang
44+
- os: ubuntu-latest
45+
c_compiler: cl
46+
- os: macos-latest
47+
c_compiler: cl
48+
- os: macos-latest
49+
c_compiler: gcc
50+
51+
steps:
52+
- uses: actions/checkout@v3
53+
54+
- name: Set Env
55+
shell: bash
56+
run: |
57+
echo "BUILD_OUTPUT_DIR=${{ github.workspace }}/build" >> "$GITHUB_ENV"
58+
59+
- name: VCPKG Install (Windows)
60+
if: runner.os == 'Windows'
61+
uses: ./.github/workflows/windows-vcpkg
62+
with:
63+
key: ${{ runner.os }}-${{ matrix.build_type }}
64+
65+
- name: Configure CMake
66+
# Configure CMake in a 'build' subdirectory.
67+
# `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
68+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
69+
run: >
70+
cmake -B ${{ env.BUILD_OUTPUT_DIR }}
71+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
72+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
73+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
74+
-DFILE_SHARE_BUILD_TESTS=TRUE
75+
-S ${{ github.workspace }}
76+
77+
- name: Build
78+
# Build your program with the given configuration. Note that --config is needed
79+
# because the default Windows generator is a multi-config generator (Visual Studio generator).
80+
run: cmake --build ${{ env.BUILD_OUTPUT_DIR }} --config ${{ matrix.build_type }}
81+
82+
- uses: actions/upload-artifact@v4
83+
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'Release' && matrix.c_compiler == 'clang'
84+
with:
85+
name: compile_commands.json
86+
path: ${{ env.BUILD_OUTPUT_DIR }}/compile_commands.json
87+
88+
- name: Test
89+
working-directory: ${{ env.BUILD_OUTPUT_DIR }}
90+
# Execute tests defined by the CMake configuration. Note that --build-config is needed
91+
# 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 --output-on-failure
94+
95+
clang-tidy:
96+
needs: 'build'
97+
runs-on: ubuntu-latest
98+
if: always() && github.event_name == 'pull_request'
99+
100+
steps:
101+
- name: Checkout Code
102+
uses: actions/checkout@v4
103+
104+
- uses: actions/download-artifact@v4
105+
with:
106+
name: compile_commands.json
107+
108+
- name: clang-tidy review
109+
uses: ZedThree/clang-tidy-review@v0.21.0
110+
111+
# If there are any comments, fail the check
112+
- if: steps.review.outputs.total_comments > 0
113+
run: exit 1
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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@v3
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@v3
48+
49+
- name: Perform CodeQL Analysis
50+
uses: github/codeql-action/analyze@v3
51+
with:
52+
category: "/language:c-cpp"
53+
54+
flawfinder:
55+
name: Flawfinder
56+
runs-on: ubuntu-latest
57+
permissions:
58+
actions: read
59+
contents: read
60+
security-events: write
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v3
64+
65+
- name: flawfinder_scan
66+
uses: david-a-wheeler/flawfinder@2.0.19
67+
with:
68+
arguments: '--sarif ./'
69+
output: 'flawfinder_results.sarif'
70+
71+
- name: Upload analysis results to GitHub Security tab
72+
uses: github/codeql-action/upload-sarif@v3
73+
with:
74+
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
75+
76+
microsoft-analyze:
77+
permissions:
78+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
79+
contents: read # for actions/checkout to fetch code
80+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
81+
name: Microsoft Analyze
82+
runs-on: windows-latest
83+
84+
env:
85+
# Path to the CMake build directory.
86+
build: '${{ github.workspace }}/build'
87+
config: 'Debug'
88+
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v3
92+
93+
- name: VCPKG Install (Windows)
94+
uses: ./.github/workflows/windows-vcpkg
95+
with:
96+
key: ${{ runner.os }}-${{ env.config }}
97+
98+
- name: Configure CMake
99+
run: cmake -B ${{ env.build }} -DCMAKE_BUILD_TYPE=${{ env.config }}
100+
101+
# Build is not required unless generated source files are used
102+
# - name: Build CMake
103+
# run: cmake --build ${{ env.build }} --config ${{ env.config }}
104+
105+
- name: Run MSVC Code Analysis
106+
uses: microsoft/msvc-code-analysis-action@v0.1.1
107+
# Provide a unique ID to access the sarif output path
108+
id: run-analysis
109+
with:
110+
cmakeBuildDirectory: ${{ env.build }}
111+
buildConfiguration: ${{ env.config }}
112+
# Ruleset file that will determine what checks will be run
113+
ruleset: NativeRecommendedRules.ruleset
114+
# Paths to ignore analysis of CMake targets and includes
115+
# ignoredPaths: ${{ github.workspace }}/dependencies;${{ github.workspace }}/test
116+
117+
# Upload SARIF file to GitHub Code Scanning Alerts
118+
- name: Upload SARIF to GitHub
119+
uses: github/codeql-action/upload-sarif@v3
120+
with:
121+
sarif_file: ${{ steps.run-analysis.outputs.sarif }}
122+
123+
# # Upload SARIF file as an Artifact to download and view
124+
# - name: Upload SARIF as an Artifact
125+
# uses: actions/upload-artifact@v4
126+
# with:
127+
# name: sarif-file
128+
# path: ${{ steps.run-analysis.outputs.sarif }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Windows VCPKG
2+
3+
inputs:
4+
key:
5+
required: true
6+
type: string
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Set Env
12+
shell: powershell
13+
run: |
14+
echo "VCPKG_ROOT=${env:VCPKG_INSTALLATION_ROOT}" | Out-File -FilePath $env:GITHUB_ENV -Append
15+
echo "VCPKG_CACHE=${env:LOCALAPPDATA}\vcpkg\archives" | Out-File -FilePath $env:GITHUB_ENV -Append
16+
17+
- name: Fetch VCPKG Cache (Windows)
18+
id: fetch-vcpkg-cache
19+
if: runner.os == 'Windows'
20+
uses: actions/cache/restore@v4
21+
with:
22+
key: ${{ inputs.key }}-vcpkg-${{ hashFiles('vcpkg.json') }}
23+
path: ${{ env.VCPKG_CACHE }}
24+
25+
- name: VCPKG Install (Windows)
26+
if: runner.os == 'Windows'
27+
shell: powershell
28+
run: |
29+
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
30+
vcpkg install
31+
32+
- name: Always Save VCPKG Cache (Windows)
33+
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
34+
uses: actions/cache/save@v4
35+
with:
36+
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
37+
path: ${{ env.VCPKG_CACHE }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ compile_commands.json
66

77
*.tmp
88
*.gch
9+
*.pch
910
vgcore.*
1011

11-
.vscode
12+
.vscode/
13+
.cache/

0 commit comments

Comments
 (0)