From 561191ef148c1b826cbc300e3e42b381c73f064f Mon Sep 17 00:00:00 2001 From: Tristan Carel Date: Wed, 27 Sep 2023 15:34:59 +0200 Subject: [PATCH] CI: add SonarSource GitHub workflow --- .github/workflows/sonarsource.yml | 105 ++++++++++++++++++++++++++++++ sonar-project.properties | 13 ++++ 2 files changed, 118 insertions(+) create mode 100644 .github/workflows/sonarsource.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/sonarsource.yml b/.github/workflows/sonarsource.yml new file mode 100644 index 0000000000..c76e3d125b --- /dev/null +++ b/.github/workflows/sonarsource.yml @@ -0,0 +1,105 @@ +name: SonarCloud +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + steps: + - name: Install apt packages + run: | + sudo apt-get install xfonts-100dpi build-essential doxygen lcov libboost-all-dev libopenmpi-dev libmpich-dev libx11-dev libxcomposite-dev mpich openmpi-bin gpg ninja-build flex bison libfl-dev + shell: bash + + - name: Setup Xvfb + run: | + sudo apt-get install xvfb + sudo /usr/bin/Xvfb $DISPLAY -screen 0 1600x1200x24 -noreset -nolock -shmem & # run in bg + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Clone nmodl + working-directory: ${{runner.workspace}}/nrn + run: | + git submodule update --init --recursive --force --depth 1 -- external/nmodl + + - name: Set up Python@${{ env.PY_MIN_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PY_MIN_VERSION }} + + - name: Install Python@${{ env.PY_MIN_VERSION }} dependencies + working-directory: ${{runner.workspace}}/nrn + run: | + python -m pip install --upgrade pip -r nrn_requirements.txt + python -m pip install --upgrade -r external/nmodl/requirements.txt + + - name: Set up Python@${{ env.PY_MID_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PY_MID_VERSION }} + + - name: Set up Python@${{ env.PY_MAX_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PY_MAX_VERSION }} + + - name: Install Python@${{ env.PY_MAX_VERSION }} dependencies + working-directory: ${{runner.workspace}}/nrn + run: | + python -m pip install --upgrade pip -r nrn_requirements.txt + python -m pip install --upgrade -r external/nmodl/requirements.txt + + - name: Build & Test + id: build-test + shell: bash + working-directory: ${{runner.workspace}}/nrn + run: | + export SHELL="/bin/bash" + + # Compiler setup + export CC=gcc + export CXX=g++ + + # Python setup + export PYTHON_MIN=$(which $PYTHON_MIN_NAME); + export PYTHON_MID=$(which $PYTHON_MID_NAME); + export PYTHON_MAX=$(which $PYTHON_MAX_NAME); + + mkdir build + + # CMake options & flags + cmake_args=(-G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER="$CC" \ + -DCMAKE_CXX_COMPILER="$CXX" \ + -DNRN_ENABLE_BACKTRACE=ON \ + -DNRN_ENABLE_CORENEURON=ON \ + -DNRN_ENABLE_INTERVIEWS=ON \ + -DNRN_ENABLE_MPI=ON \ + -DNRN_ENABLE_PERFORMANCE_TESTS=OFF \ + -DNRN_ENABLE_PROFILING=ON \ + -DNRN_ENABLE_PYTHON=ON \ + -DNRN_ENABLE_PYTHON_DYNAMIC=ON \ + -DNRN_PYTHON_DYNAMIC="${PYTHON_MIN};${PYTHON_MAX}" \ + -DNRN_PYTHON_EXTRA_FOR_TESTS=${PYTHON_MID} \ + -DNRN_ENABLE_TESTS=ON) + cmake -S . -B build "${cmake_args[@]}" + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v2 + - name: Run build-wrapper + working-directory: ${{runner.workspace}}/nrn + run: | + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000000..a9ea1c3a96 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,13 @@ +sonar.projectKey=neuronsimulator_nrn +sonar.organization=bluebrain + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=nrn +#sonar.projectVersion=1.0 + + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8