Skip to content

Commit

Permalink
Added SonarCloud integration
Browse files Browse the repository at this point in the history
Refs #88
Refs #89
  • Loading branch information
sverhoeven committed Apr 16, 2021
1 parent 214c989 commit 3a19919
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
30 changes: 30 additions & 0 deletions {{cookiecutter.project_slug}}/.github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: quality
on:
push:
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: python -m pip install .[dev]
- name: Check style against standards using prospector
run: prospector --zero-exit -o grouped -o pylint:pylint-report.txt
- name: Run unit tests with coverage
run: pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml tests/
- name: Correct coverage paths
run: sed -i "s+$PWD/++g" coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
12 changes: 12 additions & 0 deletions {{cookiecutter.project_slug}}/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
- |Python Build| |PyPI Publish|
* - Metadata consistency
- |metadata consistency|
* - Code quality
- |sonarcloud quality badge|
* - Code coverage of unit tests
- |sonarcloud coverage badge|

(Customize these badges with your own links, and check https://shields.io/ or https://badgen.net/ to see which other badges are available.)

Expand Down Expand Up @@ -65,6 +69,14 @@
:target: https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}/actions?query=workflow%3A%22cffconvert%22
:alt: metadata consistency badge

.. |sonarcloud quality badge| image:: https://sonarcloud.io/api/project_badges/measure?project=fair-software_howfairis&metric=alert_status
:target: https://sonarcloud.io/dashboard?id={{ cookiecutter.github_organization }}_{{ cookiecutter.project_slug }}
:alt: Quality Gate Status

.. |sonarcloud coverage badge| image:: https://sonarcloud.io/api/project_badges/measure?project=fair-software_howfairis&metric=coverage
:target: https://sonarcloud.io/dashboard?id={{ cookiecutter.github_organization }}_{{ cookiecutter.project_slug }}
:alt: Coverage

################################################################################
{{ cookiecutter.project_name }}
################################################################################
Expand Down
10 changes: 10 additions & 0 deletions {{cookiecutter.project_slug}}/project_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ help you decide which tool to use for packaging.
- [Relevant section in the
guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=coding-style-conventions)

## Continuous code quality

- [Sonarcloud](https://sonarcloud.io/) is used to perform quality analysis and code coverage report on each push
- The GitHub organization and repository must be added Sonarcloud for analysis to work by going to
[Sonarcloud](https://sonarcloud.io/projects/create), login with your GitHub account,
add organization or reuse existing and setup repository
- Analysis is run in [GH action workflow](.github/workflows/quality.yml)
- To run analysis a token must be created at [Sonarcloud account](https://sonarcloud.io/account/security/)
and token must be added as `SONAR_TOKEN` to [secrets on GitHub](https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}/settings/secrets/actions)

## Package version number

- We recommend using [semantic
Expand Down
12 changes: 12 additions & 0 deletions {{cookiecutter.project_slug}}/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sonar.organization={{ cookiecutter.github_organization }}
sonar.projectKey={{ cookiecutter.github_organization }}_{{ cookiecutter.project_slug }}
sonar.host.url=https://sonarcloud.io
sonar.sources={{ cookiecutter.project_slug.lower().replace(" ", "_").replace("-", "_")}}/
sonar.tests=tests/
sonar.links.homepage=https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}
sonar.links.scm=https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}
sonar.links.issue=https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}/issues
sonar.links.ci=https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}/actions
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.xunit.reportPath=xunit-result.xml
sonar.python.pylint.reportPaths=pylint-report.txt

0 comments on commit 3a19919

Please sign in to comment.