diff --git a/CHANGELOG.md b/CHANGELOG.md index da19350b..cc68ae25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added +* Make SonarCloud optional [#515](https://github.com/NLeSC/python-template/pull/515) * Make citation optional [#471](https://github.com/NLeSC/python-template/pull/471) * Make online documentation optional [#476](https://github.com/NLeSC/python-template/pull/476) * Added Python 3.12 support [#356](https://github.com/NLeSC/python-template/issues/356) diff --git a/copier.yml b/copier.yml index 04222e9b..5b1d9e72 100644 --- a/copier.yml +++ b/copier.yml @@ -107,6 +107,12 @@ AddPreCommit: default: "{{ template_profile != 'minimum' }}" help: Add pre-commit hook to check code style and format on every commit? +AddSonarCloud: + when: "{{ template_profile == 'ask' }}" + type: bool + default: "{{ template_profile != 'minimum' }}" + help: Add SonarCloud (code analysis service) integration? + # internal fields _subdirectory: template diff --git a/profiles.md b/profiles.md index 1544f7d3..44be9878 100644 --- a/profiles.md +++ b/profiles.md @@ -22,7 +22,7 @@ - project_setup.md - code quality: - - sonarcloud + - sonarcloud #515 - ruff and lint workflow - github action to build (exist) #451 - pre-commit diff --git a/template/.github/workflows/next_steps.yml b/template/.github/workflows/next_steps.yml index dc8ba159..4b0c1d22 100644 --- a/template/.github/workflows/next_steps.yml +++ b/template/.github/workflows/next_steps.yml @@ -8,13 +8,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Create Sonarcloud integration issue - uses: JasonEtco/create-an-issue@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - filename: .github/next_steps/01_sonarcloud_integration.md - id: sonarcloud - name: Create Zenodo integration issue uses: JasonEtco/create-an-issue@v2 env: @@ -32,7 +25,6 @@ jobs: - name: List created issues run: | echo 'Created issues that must be completed to have fully working Python package: - * Sonarcloud integration ${{ steps.sonarcloud.outputs.url }} * Zenodo integration ${{ steps.zenodo.outputs.url }} * Linting fixes ${{ steps.linting.outputs.url }}' - name: Cleanup files needed to create next steps issues diff --git a/template/.github/workflows/{% if AddSonarCloud %}next_steps_sonarcloud.yml{% endif %} b/template/.github/workflows/{% if AddSonarCloud %}next_steps_sonarcloud.yml{% endif %} new file mode 100644 index 00000000..576a7642 --- /dev/null +++ b/template/.github/workflows/{% if AddSonarCloud %}next_steps_sonarcloud.yml{% endif %} @@ -0,0 +1,30 @@ +on: [push] +permissions: + contents: write + issues: write +name: Create an issue for Sonarcloud +jobs: + next_steps: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create Sonarcloud issue + uses: JasonEtco/create-an-issue@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + filename: .github/workflows/next_steps_sonarcloud_issue.md + id: sonarcloud + - name: List created issues + run: | + echo 'Created issues that must be completed to have fully working Python package: + * Sonarcloud integration ${{ steps.sonarcloud.outputs.url }}' + - name: Cleanup files needed to create next steps issues + run: | + git config --global user.name 'NLeSC Python template' + git config --global user.email 'nlesc-python-template@users.noreply.github.com' + git pull # other next step workflows may push changes before + git rm .github/workflows/next_steps_sonarcloud.yml + git rm .github/workflows/next_steps_sonarcloud_issue.md + git commit -am "Cleanup automated next steps issue generator for sonarcloud" + git push diff --git a/template/.github/next_steps/01_sonarcloud_integration.md.jinja b/template/.github/workflows/{% if AddSonarCloud %}next_steps_sonarcloud_issue.md{% endif %}.jinja similarity index 100% rename from template/.github/next_steps/01_sonarcloud_integration.md.jinja rename to template/.github/workflows/{% if AddSonarCloud %}next_steps_sonarcloud_issue.md{% endif %}.jinja diff --git a/template/.github/workflows/sonarcloud.yml b/template/.github/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} similarity index 86% rename from template/.github/workflows/sonarcloud.yml rename to template/.github/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} index 1c7ec8b3..e8ca8152 100644 --- a/template/.github/workflows/sonarcloud.yml +++ b/template/.github/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} @@ -36,5 +36,5 @@ jobs: - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: - GITHUB_TOKEN: ${{ '{{' -}} secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ '{{' -}} secrets.SONAR_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/template/README.md.jinja b/template/README.md.jinja index d8792190..6a791fa0 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -11,8 +11,10 @@ | (5/5) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects//badge)](https://bestpractices.coreinfrastructure.org/projects/) | | 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) | | **Other best practices** |   | +{% if AddSonarCloud -%} | 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}}) | | 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}}) | +{%- endif -%} {% if AddOnlineDocumentation -%} | Documentation | [![Documentation Status](https://readthedocs.org/projects/{{package_name}}/badge/?version=latest)](https://{{package_name}}.readthedocs.io/en/latest/?badge=latest) | {%- endif -%} @@ -21,7 +23,9 @@ {% if AddCitation -%} | Citation data consistency | [![cffconvert]({{repository_url}}/actions/workflows/cffconvert.yml/badge.svg)]({{repository_url}}/actions/workflows/cffconvert.yml) | {%- endif -%} +{% if AddSonarCloud -%} | SonarCloud | [![sonarcloud]({{repository_url}}/actions/workflows/sonarcloud.yml/badge.svg)]({{repository_url}}/actions/workflows/sonarcloud.yml) | +{%- endif -%} | MarkDown link checker | [![markdown-link-check]({{repository_url}}/actions/workflows/markdown-link-check.yml/badge.svg)]({{repository_url}}/actions/workflows/markdown-link-check.yml) | ## How to use {{ package_name }} diff --git a/template/project_setup.md.jinja b/template/project_setup.md.jinja index ba015fc9..72e4be95 100644 --- a/template/project_setup.md.jinja +++ b/template/project_setup.md.jinja @@ -66,12 +66,14 @@ help you decide which tool to use for packaging. - [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). +{% if AddSonarCloud -%} ## Continuous code quality [Sonarcloud](https://sonarcloud.io/) is used to perform quality analysis and code coverage report - `sonar-project.properties` is the SonarCloud [configuration](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) file - `.github/workflows/sonarcloud.yml` is the GitHub action workflow which performs the SonarCloud analysis +{%- endif -%} ## Package version number diff --git a/template/sonar-project.properties.jinja b/template/{% if AddSonarCloud %}sonar-project.properties{% endif %}.jinja similarity index 100% rename from template/sonar-project.properties.jinja rename to template/{% if AddSonarCloud %}sonar-project.properties{% endif %}.jinja