Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate SonarScanner in Github Actions workflow #240

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-and-test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ jobs:
..
popd
- name: Load Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ccache
key: ccache-osx-${{ github.ref }}-${{ github.sha }}
key: ccache-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-osx-${{ github.ref }}-
ccache-osx-
ccache-${{ matrix.os }}-${{ github.ref }}-
ccache-${{ matrix.os }}-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/build-and-test-ubuntu-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
libboost-context-dev \
libboost-regex-dev \
libboost-coroutine-dev
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Configure
Expand All @@ -49,14 +49,13 @@ jobs:
..
popd
- name: Load Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ccache
key: ccache-debug-${{ github.ref }}-${{ github.sha }}
key: ccache-debug-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-debug-${{ github.ref }}-
ccache-debug-
ccache-
ccache-debug-${{ matrix.os }}-${{ github.ref }}-
ccache-debug-${{ matrix.os }}-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/build-and-test-ubuntu-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
libboost-context-dev \
libboost-regex-dev \
libboost-coroutine-dev
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Configure
Expand All @@ -52,11 +52,10 @@ jobs:
uses: actions/cache@v1
with:
path: ccache
key: ccache-release-${{ github.ref }}-${{ github.sha }}
key: ccache-release-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-release-${{ github.ref }}-
ccache-release-
ccache-
ccache-release-${{ matrix.os }}-${{ github.ref }}-
ccache-release-${{ matrix.os }}-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Scan with SonarScanner
on: [ push, pull_request ]
env:
CCACHE_COMPRESS: exists means true
CCACHE_SLOPPINESS: include_file_ctime,include_file_mtime,time_macros
jobs:
sonar-scan:
name: Scan with SonarScanner
strategy:
matrix:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Download and install latest SonarScanner CLI tool
run: |
SONAR_SCANNER_VERSION=`curl https://github.com/SonarSource/sonar-scanner-cli/releases/latest \
2>/dev/null | cut -f2 -d'"' | cut -f8 -d'/'`
SONAR_DOWNLOAD_PATH=https://binaries.sonarsource.com/Distribution/sonar-scanner-cli
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip \
$SONAR_DOWNLOAD_PATH/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \
https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
echo "SONAR_SCANNER_VERSION=$SONAR_SCANNER_VERSION" >> $GITHUB_ENV
echo "SONAR_SCANNER_HOME=$SONAR_SCANNER_HOME" >> $GITHUB_ENV
echo "SONAR_SCANNER_OPTS=-server" >> $GITHUB_ENV
echo "$SONAR_SCANNER_HOME/bin" >> $GITHUB_PATH
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
- name: Install dependencies
run: |
sudo apt-get update
openssl_ver=`sudo apt-cache madison openssl | grep xenial-updates | awk '{print $3}'`
libssl_ver=`sudo apt-cache madison libssl-dev | grep xenial-updates | awk '{print $3}'`
[ -n "${openssl_ver}" ] && [ -n "${libssl_ver}" ] && \
sudo apt-get install -y --allow-downgrades openssl=${openssl_ver} libssl-dev=${libssl_ver}
sudo apt-get install -y \
ccache \
parallel \
libboost-thread-dev \
libboost-iostreams-dev \
libboost-date-time-dev \
libboost-system-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-chrono-dev \
libboost-test-dev \
libboost-context-dev \
libboost-regex-dev \
libboost-coroutine-dev
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive
- name: Configure
run: |
mkdir -p _build
pushd _build
export -n BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR
cmake -D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON \
-D CMAKE_C_COMPILER=gcc \
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER=g++ \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D CMAKE_C_FLAGS=--coverage \
-D CMAKE_CXX_FLAGS=--coverage \
-D Boost_USE_STATIC_LIBS=OFF \
..
popd
- name: Load Cache
uses: actions/cache@v2
with:
path: |
ccache
sonar_cache
key: sonar-${{ github.ref }}-${{ github.sha }}
restore-keys: |
sonar-${{ github.ref }}-
sonar-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
mkdir -p "$CCACHE_DIR"
build-wrapper-linux-x86-64 --out-dir bw-output make -j 2 -C _build
- name: Test
run: |
parallel echo Running {}\; sh -c "./{}" <<_EOT_
tests/run-parallel-tests.sh _build/tests/all_tests -l test_suite
_build/tests/bloom_test -- README.md
_build/tests/ecc_test README.md
_build/tests/hmac_test
_build/tests/task_cancel_test
_EOT_
- name: Prepare for scanning with SonarScanner
run: |
mkdir -p sonar_cache
find _build/CMakeFiles/fc.dir -type d -print \
| while read d; do gcov -o "$d" "${d/_build*.dir/.}"/*.cpp; done >/dev/null
if [ -z "$GITHUB_HEAD_REF" ]; then \
echo "sonar.branch.target=master" >> sonar-project.properties; \
if [ "${GITHUB_REF#refs/heads/}" != "$GITHUB_REF" ]; then \
echo "sonar.branch.name=${GITHUB_REF#refs/heads/}" >> sonar-project.properties; \
elif [ "${GITHUB_REF#refs/tags/}" != "$GITHUB_REF" ]; then \
echo "sonar.branch.name=${GITHUB_REF#refs/}" >> sonar-project.properties; \
else \
echo "sonar.branch.name=${GITHUB_REF}" >> sonar-project.properties; \
fi \
fi
- name: Scan with SonarScanner
env:
# to get access to secrets.SONAR_TOKEN, provide GITHUB_TOKEN
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sonar-scanner \
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
11 changes: 9 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
sonar.projectKey=BitShares-FC
sonar.organization=bitshares-on-github

sonar.projectKey=bitshares_bitshares-fc
sonar.projectName=BitShares-FC
sonar.projectDescription=Fast-compiling C++ library

sonar.host.url=https://sonarcloud.io

sonar.links.homepage=https://bitshares.org
sonar.links.ci=https://travis-ci.org/bitshares/bitshares-fc/
sonar.links.ci=https://github.com/bitshares/bitshares-fc/actions
sonar.links.issue=https://github.com/bitshares/bitshares-core/issues
sonar.links.scm=https://github.com/bitshares/bitshares-fc/tree/master

Expand All @@ -12,3 +17,5 @@ sonar.sources=src,include
sonar.cfamily.build-wrapper-output=bw-output
sonar.cfamily.gcov.reportsPath=.
sonar.cfamily.threads=2
sonar.cfamily.cache.enabled=true
sonar.cfamily.cache.path=sonar_cache