Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71a4d33

Browse files
authored
Merge pull request #711 from utPLSQL/build/sonarpr
Added ability to generate a sonar branches pull request analysis
2 parents c5f640b + a8fa36c commit 71a4d33

4 files changed

Lines changed: 63 additions & 5 deletions

File tree

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ addons:
1212
organization: utplsql
1313
token:
1414
secure: ${SONAR_TOKEN}
15-
branches:
16-
- develop
17-
- master
1815

1916
services:
2017
- docker
@@ -66,6 +63,8 @@ cache:
6663
before_install:
6764
#The update_project_version.sh is done before deployment to validate that the change of project files does not break installation
6865
- bash .travis/update_project_version.sh
66+
#Allow for sonar to blame issues
67+
- git fetch --unshallow
6968
# download latest utPLSQL release
7069
#- curl -LOk $(curl --silent https://api.github.com/repos/utPLSQL/utPLSQL/releases/latest | awk '/browser_download_url/ { print $2 }' | grep ".zip" | sed 's/"//g')
7170
- git clone --depth=1 --branch=${SELFTESTING_BRANCH:-master} https://github.com/utPLSQL/utPLSQL.git $UTPLSQL_DIR
@@ -94,7 +93,7 @@ before_script:
9493
script:
9594
- if [[ ! $TRAVIS_TAG ]]; then bash test/install_and_run_tests.sh; fi
9695
- if [[ ! $TRAVIS_TAG ]]; then bash .travis/validate_report_files.sh; fi
97-
- if [[ ! $TRAVIS_TAG ]] && [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sonar-scanner; fi
96+
- if [[ ! $TRAVIS_TAG ]] && [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ]; then bash .travis/run_sonar_scanner.sh; fi
9897
- if [[ ! $TRAVIS_TAG ]]; then bash .travis/coveralls_uploader.sh; fi
9998

10099
notifications:

.travis/run_sonar_scanner.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
#Run Sonar based on conditions
4+
5+
MAIN_DEV_BRANCH="develop"
6+
7+
BRANCH_SONAR_PROPERTY="sonar.branch.name"
8+
BRANCH_SONAR_TARGET_PROPERTY="sonar.branch.target"
9+
10+
PR_SONAR_BRANCH_PROPERTY="sonar.pullrequest.branch"
11+
PR_KEY_PROPERTY="sonar.pullrequest.key"
12+
PR_SONAR_BASE_PROPERTY="sonar.pullrequest.base"
13+
PR_SONAR_TOKEN_PROPERTY="sonar.pullrequest.github.token.secured"
14+
15+
#Add property to file
16+
function add_sonar_property {
17+
echo "$1=$2" >> sonar-project.properties
18+
}
19+
20+
21+
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
22+
BRANCH=$TRAVIS_BRANCH;
23+
PR_BRANCH=""
24+
echo "BRANCH=$BRANCH"
25+
else
26+
BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
27+
PR_BRANCH=$TRAVIS_BRANCH
28+
echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$TRAVIS_PULL_REQUEST, BRANCH=$BRANCH"
29+
30+
fi
31+
32+
33+
#Are we running on develop branch ?
34+
echo "Check if we running from develop or on branch"
35+
if [ "${TRAVIS_REPO_SLUG}" = "${UTPLSQL_REPO}" ] && [[ ! "${BRANCH}" =~ ^(release/v[0-9]+\.[0-9]+\.[0-9]+.*|"${MAIN_DEV_BRANCH}")$ ]]; then
36+
37+
echo "" >> sonar-project.properties
38+
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
39+
echo "Updating sonar properties to include branch ${BRANCH}"
40+
add_sonar_property "${BRANCH_SONAR_PROPERTY}" "${BRANCH}"
41+
add_sonar_property "${BRANCH_SONAR_TARGET_PROPERTY}" "${MAIN_DEV_BRANCH}"
42+
else
43+
echo "Updating sonar properties to include pull request ${BRANCH}"
44+
add_sonar_property "${PR_SONAR_TOKEN_PROPERTY}" "${GITHUB_TRAVISCI_TOKEN}"
45+
add_sonar_property "${PR_SONAR_BRANCH_PROPERTY}" "${BRANCH}"
46+
add_sonar_property "${PR_KEY_PROPERTY}" "${PR}"
47+
add_sonar_property "${PR_SONAR_BASE_PROPERTY}" "${PR_BRANCH}"
48+
fi
49+
else
50+
echo "No need to update sonar we building on release or develop"
51+
fi
52+
53+
#Execute Sonar scanner
54+
sonar-scanner

sonar-project.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ sonar.projectDescription=PL/SQL Unit Testing Framework
1919
sonar.plsql.file.suffixes=sql,tab,pkb,tpb
2020
sonar.language=plsql
2121

22+
sonar.pullrequest.provider=github
23+
sonar.pullrequest.github.endpoint=https://api.github.com/
24+
sonar.pullrequest.github.repository=utPLSQL/utPLSQL
25+
2226
# Encoding of the source code. Default is default system encoding
2327
#sonar.sourceEncoding=UTF-8

source/api/ut.pkb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ create or replace package body ut is
103103
raise e_package_invalidated;
104104
end if;
105105
end;
106-
106+
107+
107108
procedure run_autonomous(
108109
a_paths ut_varchar2_list,
109110
a_reporter ut_reporter_base,

0 commit comments

Comments
 (0)