Skip to content

Commit

Permalink
Merge pull request #4 from dave-shawley/add-sonar
Browse files Browse the repository at this point in the history
Add sonarqube
  • Loading branch information
dave-shawley committed May 18, 2019
2 parents 0bceacf + bac88dd commit 2ad2cbd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 8 deletions.
44 changes: 36 additions & 8 deletions .circleci/config.yml
Expand Up @@ -7,12 +7,6 @@ defaults:
ignore: /.*/
tags:
only: /.*/
only-master-filter: &filter-only-master
filters:
branches:
only: /master/
tags:
ignore: /.*/

commands:

Expand Down Expand Up @@ -62,6 +56,8 @@ commands:
type: string
coverage-file:
type: string
execution-file:
type: string
steps:
- setup_remote_docker
- run:
Expand All @@ -75,12 +71,14 @@ commands:
--with-xunit --xunit-file build/reports/nosetests.xml
cp .coverage ~/workspace/<< parameters.coverage-file >>
cp build/reports/nosetests.xml build/circleci/nosetests/results.xml
cp build/reports/nosetests.xml ~/workspace/<< parameters.execution-file >>
- store_test_results:
path: build/circleci
- persist_to_workspace:
root: ~/workspace
paths:
- << parameters.coverage-file >>
- << parameters.execution-file >>
- store_artifacts:
path: build/reports
destination: build-reports
Expand All @@ -102,7 +100,7 @@ executors:

workflows:
version: "2"
build-workflow: # PRs and merges into master
build-workflow:
jobs:
- test-python-2
- test-python-3
Expand Down Expand Up @@ -130,6 +128,7 @@ jobs:
version: "2.7"
- run-tests:
coverage-file: coverage-py2
execution-file: nosetests-py2.xml
virtual-environment-name: py2

test-python-3:
Expand All @@ -143,6 +142,7 @@ jobs:
version: "3.7"
- run-tests:
coverage-file: coverage-py3
execution-file: nosetests-py3.xml
virtual-environment-name: py3

combine-coverage:
Expand All @@ -162,11 +162,39 @@ jobs:
coverage report --show-missing >build-reports/coverage.txt
coverage xml -o build-reports/coverage.xml
- run:
name: Upload coverage
name: Upload coverage to coveralls
command: |
. ~/workspace/py3/bin/activate
cp ~/workspace/.coverage .
coveralls
- run:
name: Copy reports for sonarqube
command: |
if test -n "$SONARQUBE_TOKEN"
then
mkdir -p build/reports
cp ~/workspace/build-reports/coverage.xml build/reports
cp ~/workspace/nosetests-py3.xml build/reports/nosetests.xml
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.2.0.1227-linux.zip
unzip sonar-scanner-cli-3.2.0.1227-linux.zip
export SONAR_SCANNER_OPTS="-Xmx2048m"
if test -z "$CI_PULL_REQUEST"
then
./sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner \
-Dsonar.login=$SONARQUBE_TOKEN
else
pr_key=`echo $CI_PULL_REQUEST | sed 's@^.*/\([^/]*\)$@\1@'`
./sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner \
-Dsonar.login=$SONARQUBE_TOKEN \
-Dsonar.pullrequest.base=master \
-Dsonar.pullrequest.branch=$CIRCLE_BRANCH \
-Dsonar.pullrequest.provider=GitHub \
-Dsonar.pullrequest.github.repository=dave-shawley/klempner \
-Dsonar.pullrequest.key=$pr_key
fi
else
echo 'SONARQUBE_TOKEN is not defined, skipping upload.'
fi
- persist_to_workspace:
root: ~/workspace
paths:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@
build/
dist/
env/
.scannerwork
16 changes: 16 additions & 0 deletions README.rst
Expand Up @@ -2,6 +2,8 @@ klempner
========
Constructs URLs that targeting other services.

|Version| |Python| |Source| |Coverage| |Quality| |Docs| |CI|

This library makes building URLs for inter-service communication safer
and easier to build.

Expand Down Expand Up @@ -151,3 +153,17 @@ in the dictionary, then ``http`` is used as a default.
url = klempner.url.build_url('account')
print(url) # https://10.2.12.23:443/
.. |CI| image:: https://img.shields.io/circleci/project/github/dave-shawley/klempner/master.svg
:target: https://circleci.com/gh/dave-shawley/klempner
.. |Coverage| image:: https://img.shields.io/coveralls/github/dave-shawley/klempner.svg
:target: https://coveralls.io/github/dave-shawley/klempner
.. |Docs| image:: https://img.shields.io/readthedocs/klempner.svg
:target: https://klempner.readthedocs.io/
.. |Python| image:: https://img.shields.io/pypi/pyversions/klempner.svg
:target: https://pypi.org/project/klempner
.. |Quality| image:: https://sonarcloud.io/api/project_badges/measure?project=dave-shawley_klempner&metric=alert_status
:target: https://sonarcloud.io/dashboard?id=dave-shawley_klempner
.. |Source| image:: https://img.shields.io/github/stars/dave-shawley/klempner.svg?logo=github
:target: https://github.com/dave-shawley/klempner
.. |Version| image:: https://img.shields.io/pypi/v/klempner.svg
:target: https://pypi.org/project/klempner
14 changes: 14 additions & 0 deletions sonar-project.properties
@@ -0,0 +1,14 @@
sonar.host.url=https://sonarcloud.io
sonar.organization=dave-shawley-github
sonar.projectDescription=Construct service request URLs in a variety of ways
sonar.projectKey=dave-shawley_klempner

sonar.sources=klempner
sonar.tests=tests

sonar.python.coverage.reportPaths=build/reports/coverage.xml
sonar.python.xunit.reportPath=build/reports/nosetests.xml

sonar.links.ci=https://circleci.com/gh/dave-shawley/klempner
sonar.links.homepage=https://klempner.readthedocs.io
sonar.links.scm=https://github.com/dave-shawley/klempner

0 comments on commit 2ad2cbd

Please sign in to comment.