Skip to content

Commit 349ed1d

Browse files
authored
Merge pull request #515 from NLeSC/460_sonarcloud
460-Add sonarcloud question
2 parents 6295366 + 0c135f8 commit 349ed1d

10 files changed

Lines changed: 46 additions & 11 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
* Make SonarCloud optional [#515](https://github.com/NLeSC/python-template/pull/515)
78
* Make citation optional [#471](https://github.com/NLeSC/python-template/pull/471)
89
* Make online documentation optional [#476](https://github.com/NLeSC/python-template/pull/476)
910
* Added Python 3.12 support [#356](https://github.com/NLeSC/python-template/issues/356)

copier.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ AddPreCommit:
107107
default: "{{ template_profile != 'minimum' }}"
108108
help: Add pre-commit hook to check code style and format on every commit?
109109

110+
AddSonarCloud:
111+
when: "{{ template_profile == 'ask' }}"
112+
type: bool
113+
default: "{{ template_profile != 'minimum' }}"
114+
help: Add SonarCloud (code analysis service) integration?
115+
110116
# internal fields
111117
_subdirectory: template
112118

profiles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- project_setup.md
2323

2424
- code quality:
25-
- sonarcloud
25+
- sonarcloud #515
2626
- ruff and lint workflow
2727
- github action to build (exist) #451
2828
- pre-commit

template/.github/workflows/next_steps.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4
11-
- name: Create Sonarcloud integration issue
12-
uses: JasonEtco/create-an-issue@v2
13-
env:
14-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15-
with:
16-
filename: .github/next_steps/01_sonarcloud_integration.md
17-
id: sonarcloud
1811
- name: Create Zenodo integration issue
1912
uses: JasonEtco/create-an-issue@v2
2013
env:
@@ -32,7 +25,6 @@ jobs:
3225
- name: List created issues
3326
run: |
3427
echo 'Created issues that must be completed to have fully working Python package:
35-
* Sonarcloud integration ${{ steps.sonarcloud.outputs.url }}
3628
* Zenodo integration ${{ steps.zenodo.outputs.url }}
3729
* Linting fixes ${{ steps.linting.outputs.url }}'
3830
- name: Cleanup files needed to create next steps issues
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on: [push]
2+
permissions:
3+
contents: write
4+
issues: write
5+
name: Create an issue for Sonarcloud
6+
jobs:
7+
next_steps:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Create Sonarcloud issue
12+
uses: JasonEtco/create-an-issue@v2
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
with:
16+
filename: .github/workflows/next_steps_sonarcloud_issue.md
17+
id: sonarcloud
18+
- name: List created issues
19+
run: |
20+
echo 'Created issues that must be completed to have fully working Python package:
21+
* Sonarcloud integration ${{ steps.sonarcloud.outputs.url }}'
22+
- name: Cleanup files needed to create next steps issues
23+
run: |
24+
git config --global user.name 'NLeSC Python template'
25+
git config --global user.email 'nlesc-python-template@users.noreply.github.com'
26+
git pull # other next step workflows may push changes before
27+
git rm .github/workflows/next_steps_sonarcloud.yml
28+
git rm .github/workflows/next_steps_sonarcloud_issue.md
29+
git commit -am "Cleanup automated next steps issue generator for sonarcloud"
30+
git push

template/.github/next_steps/01_sonarcloud_integration.md.jinja renamed to template/.github/workflows/{% if AddSonarCloud %}next_steps_sonarcloud_issue.md{% endif %}.jinja

File renamed without changes.

template/.github/workflows/sonarcloud.yml renamed to template/.github/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %}

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ jobs:
3636
- name: SonarCloud Scan
3737
uses: SonarSource/sonarcloud-github-action@master
3838
env:
39-
GITHUB_TOKEN: ${{ '{{' -}} secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
40-
SONAR_TOKEN: ${{ '{{' -}} secrets.SONAR_TOKEN }}
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
40+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

template/README.md.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
| (5/5) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>/badge)](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>) |
1212
| howfairis | [![fair-software badge](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu) |
1313
| **Other best practices** | &nbsp; |
14+
{% if AddSonarCloud -%}
1415
| Static analysis | [![workflow scq badge](https://sonarcloud.io/api/project_badges/measure?project={{github_organization}}_{{package_name}}&metric=alert_status)](https://sonarcloud.io/dashboard?id={{github_organization}}_{{package_name}}) |
1516
| Coverage | [![workflow scc badge](https://sonarcloud.io/api/project_badges/measure?project={{github_organization}}_{{package_name}}&metric=coverage)](https://sonarcloud.io/dashboard?id={{github_organization}}_{{package_name}}) |
17+
{%- endif -%}
1618
{% if AddOnlineDocumentation -%}
1719
| Documentation | [![Documentation Status](https://readthedocs.org/projects/{{package_name}}/badge/?version=latest)](https://{{package_name}}.readthedocs.io/en/latest/?badge=latest) |
1820
{%- endif -%}
@@ -21,7 +23,9 @@
2123
{% if AddCitation -%}
2224
| Citation data consistency | [![cffconvert]({{repository_url}}/actions/workflows/cffconvert.yml/badge.svg)]({{repository_url}}/actions/workflows/cffconvert.yml) |
2325
{%- endif -%}
26+
{% if AddSonarCloud -%}
2427
| SonarCloud | [![sonarcloud]({{repository_url}}/actions/workflows/sonarcloud.yml/badge.svg)]({{repository_url}}/actions/workflows/sonarcloud.yml) |
28+
{%- endif -%}
2529
| MarkDown link checker | [![markdown-link-check]({{repository_url}}/actions/workflows/markdown-link-check.yml/badge.svg)]({{repository_url}}/actions/workflows/markdown-link-check.yml) |
2630

2731
## How to use {{ package_name }}

template/project_setup.md.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ help you decide which tool to use for packaging.
6666

6767
- [Relevant section in the NLeSC guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=coding-style-conventions) and [README.dev.md](README.dev.md).
6868

69+
{% if AddSonarCloud -%}
6970
## Continuous code quality
7071

7172
[Sonarcloud](https://sonarcloud.io/) is used to perform quality analysis and code coverage report
7273

7374
- `sonar-project.properties` is the SonarCloud [configuration](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) file
7475
- `.github/workflows/sonarcloud.yml` is the GitHub action workflow which performs the SonarCloud analysis
76+
{%- endif -%}
7577

7678
## Package version number
7779

template/sonar-project.properties.jinja renamed to template/{% if AddSonarCloud %}sonar-project.properties{% endif %}.jinja

File renamed without changes.

0 commit comments

Comments
 (0)