Skip to content

Commit

Permalink
[CodeQuality]: Enable sonarcloud on CI run (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius authored Oct 26, 2022
1 parent f7217bd commit d9c02ce
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 10 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/linux-ci-sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Linux CI SonarCloud

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Install system dependencies
run: |
# build-essential clang-14 libc++-dev libc++abi-dev ruby-full cmake
sudo apt-get update && sudo apt-get install ninja-build lcov llvm-14 clang-tidy-14 libboost-all-dev --fix-missing
- name: Cache internal dependencies
id: internal_cache
uses: actions/[email protected]
with:
path: build/local
key: ${{ runner.os }}-internal-${{ hashFiles('tools/install-dependencies') }}
- name: Install internal dependencies
run: |
tools/install-dependencies
env:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
if: steps.internal_cache.outputs.cache-hit != 'true'
- name: Code generation
run: |
tools/generate-files
env:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
- name: CMake (coverage/clang-tidy/clang-asan)
run: |
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug -DTW_CODE_COVERAGE=ON -DTW_ENABLE_CLANG_TIDY=ON -DTW_CLANG_ASAN=ON -GNinja
cat build/compile_commands.json
env:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
- name: SonarCloud Scan
run: |
./tools/sonarcloud-analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7 changes: 7 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sonar.organization=trustwallet
sonar.projectKey=TrustWallet_wallet-core
sonar.cfamily.compile-commands=build/compile_commands.json
sonar.cfamily.reportingCppStandardOverride=c++20
sonar.cfamily.cache.enabled=false
sonar.lang.patterns.cpp=**/*.cc,**/*.cpp,**/*.cxx,**/*.c++,**/*.hh,**/*.hpp,**/*.hxx,**/*.h++,**/*.ipp,**/*.h
sonar.lang.patterns.c=**/*.c
2 changes: 1 addition & 1 deletion src/HDWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ std::string serialize(const HDNode* node, uint32_t fingerprint, uint32_t version
bool deserialize(const std::string& extended, TWCurve curve, Hash::Hasher hasher, HDNode* node) {
TW::memzero(node);
const char* curveNameStr = curveName(curve);
if (curveNameStr == nullptr || ::strlen(curveNameStr) == 0) {
if (curveNameStr == nullptr || std::string(curveNameStr).empty()) {
return false;
}
node->curve = get_curve_by_name(curveNameStr);
Expand Down
2 changes: 1 addition & 1 deletion src/Mnemonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool Mnemonic::isValidWord(const std::string& word) {
// (i.e., no early exit on match)
auto found = false;
for (const char* const* w = mnemonicWordlist(); *w != nullptr; ++w) {
if (strlen(*w) == len && strncmp(*w, wordC, len) == 0) {
if (std::string(*w).size() == len && strncmp(*w, wordC, len) == 0) {
found = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ struct Result {
E error() const { return get<E>(); }

/// Returns a new success result with the given payloadd.
static Result<T, E> success(T&& val) { return Result(Types::Success<T>(std::forward<T>(val))); }
static Result<T, E> success(T&& val) { return Result(Types::Success<T>(std::move(val))); }

/// Returns a new failure result with the given error.
static Result<T, E> failure(E&& val) { return Result(Types::Failure<E>(std::forward<E>(val))); }
static Result<T, E> failure(E&& val) { return Result(Types::Failure<E>(std::move(val))); }

static Result<T, E> failure(E& val) { return Result(Types::Failure<E>(val)); }

Expand Down Expand Up @@ -171,7 +171,7 @@ struct Result<void, E> {

/// Returns a new failure result with the given error.
static Result<void, E> failure(E&& val) {
return Result(Types::Failure<E>(std::forward<E>(val)));
return Result(Types::Failure<E>(std::move(val)));
}

operator bool() const { return success_; }
Expand Down
12 changes: 7 additions & 5 deletions src/interface/TWTransactionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ TWData *_Nonnull TWTransactionCompilerBuildInput(enum TWCoinType coinType, TWStr
return TWDataCreateWithBytes(result.data(), result.size());
}

std::vector<Data> createFromTWDataVector(const struct TWDataVector* _Nonnull dataVector) {
static std::vector<Data> createFromTWDataVector(const struct TWDataVector* _Nonnull dataVector) {
std::vector<Data> ret;
const auto n = TWDataVectorSize(dataVector);
for (auto i = 0ul; i < n; ++i) {
auto elem = TWDataVectorGet(dataVector, i);
ret.push_back(*(static_cast<const Data*>(elem)));
TWDataDelete(elem);
for (auto i = 0uL; i < n; ++i) {
const auto* const elem = TWDataVectorGet(dataVector, i);
if (const auto* const data = reinterpret_cast<const Data *>(elem); data) {
ret.emplace_back(*data);
TWDataDelete(elem);
}
}
return ret;
}
Expand Down
9 changes: 9 additions & 0 deletions tools/sonar-scanner.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=https://sonarcloud.io/

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

9 changes: 9 additions & 0 deletions tools/sonarcloud-analysis
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

TARGET=sonar-scanner-cli-4.7.0.2747-linux.zip
TARGET_DIR=sonar-scanner-4.7.0.2747-linux
curl https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${TARGET} --output ${TARGET}
unzip ${TARGET}
cp tools/sonar-scanner.properties ${TARGET_DIR}/conf
chmod +x ${TARGET_DIR}/bin/sonar-scanner
./${TARGET_DIR}/bin/sonar-scanner

0 comments on commit d9c02ce

Please sign in to comment.