Skip to content

Commit 112667c

Browse files
committed
Add SonarQube for Apache Cloudberry
This PR introduces the SonarQube for Apache Cloudberry as a code quality and security tool, which is similar to the Coverity. We also use the Cloudberry docker image as the running base env.
1 parent 96a9b92 commit 112667c

File tree

4 files changed

+140
-5
lines changed

4 files changed

+140
-5
lines changed

.github/workflows/coverity.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ name: Apache Cloudberry Coverity Scan
4040

4141
on:
4242
schedule:
43-
- cron: "0 0 * * *"
43+
- cron: "0 0 * * 1"
4444
workflow_dispatch:
4545

4646
permissions:
@@ -62,7 +62,8 @@ jobs:
6262
uses: actions/checkout@v4
6363
with:
6464
fetch-depth: 1
65-
65+
submodules: true
66+
6667
- name: Environment Initialization
6768
run: |
6869
if ! su - gpadmin -c "/tmp/init_system.sh"; then
@@ -72,15 +73,16 @@ jobs:
7273
7374
- name: Download Coverity build tool
7475
run: |
76+
set -euox pipefail
7577
wget -c -N https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=apache%2Fcloudberry" -O coverity_tool.tar.gz
7678
mkdir -p coverity_tool
7779
tar xzf coverity_tool.tar.gz --strip 1 -C coverity_tool
7880
chown -R gpadmin:gpadmin coverity_tool
7981
8082
- name: Build with Coverity build tool
8183
run: |
84+
set -euox pipefail
8285
WORKSPACE="${GITHUB_WORKSPACE}"
83-
sudo rm -rf /usr/local/cloudberry-db
8486
sudo chmod a+w /usr/local
8587
mkdir -p /usr/local/cloudberry-db/lib
8688
sudo cp /usr/local/xerces-c/lib/libxerces-c.so \
@@ -90,7 +92,6 @@ jobs:
9092
su - gpadmin -c "cd $WORKSPACE"
9193
export LD_LIBRARY_PATH=/usr/local/cloudberry-db/lib:LD_LIBRARY_PATH
9294
export PATH=$WORKSPACE/coverity_tool/bin:$PATH
93-
git submodule update --init
9495
./configure --prefix=/usr/local/cloudberry-db \
9596
--disable-external-fts \
9697
--enable-gpcloud \

.github/workflows/sonarqube.yml

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# --------------------------------------------------------------------
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed
5+
# with this work for additional information regarding copyright
6+
# ownership. The ASF licenses this file to You under the Apache
7+
# License, Version 2.0 (the "License"); you may not use this file
8+
# except in compliance with the License. You may obtain a copy of the
9+
# License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
# implied. See the License for the specific language governing
17+
# permissions and limitations under the License.
18+
#
19+
# --------------------------------------------------------------------
20+
# GitHub Actions Workflow: Apache Cloudberry SonarQube Pipeline
21+
# --------------------------------------------------------------------
22+
# Description:
23+
#
24+
# This workflow performs scheduled SonarQube analysis for Cloudberry.
25+
#
26+
# Workflow Overview:
27+
# 1. **Check Skip**:
28+
# - workflow run currently is limited to "apache" GitHub organization
29+
#
30+
# 2. **scan Job**:
31+
# - performs scan and upload result to https://sonarcloud.io/project/overview?id=apache_cloudberry
32+
# Triggers:
33+
# - Weekly schedule
34+
# - optional manual dispatch.
35+
#
36+
# Notes:
37+
# - SONARCLOUD_TOKEN secret is provided by the ASF Infra team
38+
# --------------------------------------------------------------------
39+
name: Apache Cloudberry SonarQube Cloud Analysis
40+
41+
on:
42+
schedule:
43+
- cron: "0 0 * * 1"
44+
workflow_dispatch:
45+
46+
permissions:
47+
contents: read
48+
49+
jobs:
50+
sonarqube-analysis:
51+
runs-on: ubuntu-22.04
52+
if: ${{ github.repository_owner == 'apache' }}
53+
54+
container:
55+
image: apache/incubator-cloudberry:cbdb-build-rocky9-latest
56+
options: >-
57+
--user root
58+
-h cdw
59+
env:
60+
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
61+
62+
steps:
63+
- name: Checkout Apache Cloudberry
64+
uses: actions/checkout@v4
65+
with:
66+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
67+
submodules: true
68+
69+
- name: Environment Initialization
70+
run: |
71+
if ! su - gpadmin -c "/tmp/init_system.sh"; then
72+
echo "::error::Container initialization failed"
73+
exit 1
74+
fi
75+
76+
- name: Install Build Wrapper
77+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5
78+
79+
- name: Run Build Wrapper
80+
run: |
81+
set -euox pipefail
82+
sudo chmod a+w /usr/local
83+
mkdir -p /usr/local/cloudberry-db/lib
84+
sudo cp /usr/local/xerces-c/lib/libxerces-c.so \
85+
/usr/local/xerces-c/lib/libxerces-c-3.3.so \
86+
/usr/local/cloudberry-db/lib
87+
sudo chown -R gpadmin:gpadmin /usr/local/cloudberry-db
88+
export LD_LIBRARY_PATH=/usr/local/cloudberry-db/lib:LD_LIBRARY_PATH
89+
./configure --prefix=/usr/local/cloudberry-db \
90+
--disable-external-fts \
91+
--enable-gpcloud \
92+
--enable-ic-proxy \
93+
--enable-orafce \
94+
--enable-orca \
95+
--enable-pax \
96+
--enable-pxf \
97+
--enable-tap-tests \
98+
--with-gssapi \
99+
--with-ldap \
100+
--with-libxml \
101+
--with-lz4 \
102+
--with-openssl \
103+
--with-pam \
104+
--with-perl \
105+
--with-pgport=5432 \
106+
--with-python \
107+
--with-pythonsrc-ext \
108+
--with-ssl=openssl \
109+
--with-uuid=e2fs \
110+
--with-includes=/usr/local/xerces-c/include \
111+
--with-libraries=/usr/local/cloudberry-db/lib
112+
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -j$(nproc)
113+
114+
- name: SonarQube Scan
115+
uses: SonarSource/sonarqube-scan-action@v5
116+
env:
117+
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
118+
with:
119+
args: >
120+
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
<img alt="Coverity Scan Build Status"
2424
src="https://scan.coverity.com/projects/31473/badge.svg"/>
2525
</a>
26-
26+
<a href="https://sonarcloud.io/summary/new_code?id=apache_cloudberry">
27+
<img alt="SonarQube Cloud" src="https://sonarcloud.io/images/project_badges/sonarcloud-highlight.svg" width="100px">
28+
</a>
2729
---------
2830

2931
## Introduction

sonar-project.properties

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sonar.projectKey=apache_cloudberry
2+
sonar.organization=apache
3+
4+
# This is the name and version displayed in the SonarCloud UI.
5+
sonar.projectName=Apache Cloudberry
6+
sonar.projectVersion=Main
7+
8+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
9+
sonar.sources=.
10+
11+
# Encoding of the source code. Default is default system encoding
12+
#sonar.sourceEncoding=UTF-8

0 commit comments

Comments
 (0)