Running sonarqube checks for PRs

Hi devs,

I’m proposing to automatically execute sonarqube (with our sonarcloud setup) on the 3 repos of the XWiki GH organization (commons, rendering and platform) so that we can detect sonarqub issues in PRs before they’re merged.

As a proof of concept I’ve now set it up for commons, rendering and platform. See for ex xwiki-commons/.github/workflows/sonar-pr.yml at master · xwiki/xwiki-commons · GitHub

I’ll remove them if we don’t want it (but not sure why we wouldn’t).

WDYT?

Thanks

Actually, in order to not duplicate the workflow, I’m proposing to also create a .github repo in the XWiki GH organization that will serve to host GH actions to be used across repos. This will be very useful if we want to extend this to contrib project and to avoid duplicate other actions.

We’ll still need a few lines of code in each repo but it’s a lot less:

# .github/workflows/sonar-pr.yml                                                                                                                                                                                                                                                                                          
  name: SonarCloud PR analysis                                                                                                                                                                                                                                                                                              
  on:                                                                                                                                                                                                                                                                                                                       
    pull_request:                                                                                                                                                                                                                                                                                                           
      types: [opened, synchronize, reopened]                                                                                                                                                                                                                                                                                
  jobs:                                                                                                                                                                                                                                                                                                                     
    analysis:                                                                                                                                                                                                                                                                                                               
      uses: xwiki/.github/.github/workflows/sonar-pr.yml@master                                                                                                                                                                                                                                                             
      with:                                                                                                                                                                                                                                                                                                                 
        java-version: '21'   # per-repo/per-branch, the one thing that legitimately varies                                                                                                                                                                                                                                  
      secrets: inherit   

Incidentally, this same move would fix an existing drift: backport.yml is duplicated in all three repos and xwiki-platform’s copy has already diverged from the identical commons/rendering pair…

WDYT?

Thx

+1

@tmortagne +1 also for the .github repo in the XWiki GH org? Thx

Sure, I don’t see anything wrong with making it a bit more reusable.

This is quite misleading since 99% of the time you should not set it (the action seems to deduce it from the pom, as expected).

+1 in general, but shouldn’t we add the same thing for checkstyle too?

+1, thanks

I’ve now added checkstyle check for PRs too :slight_smile: Thx for suggesting it. It’s a little less needed since you’re supposed to build and a checkstyle error would fail the build but it’s good nevertheless to have it (and doesn’t cost too much).

Note that we don’t report when a change causes a checkstyle issue elsewhere. This is rare but can happen. It’s caught by your jenkins jobs, as usual.

The .github repo proposed in post 2 now exists: GitHub - xwiki/.github: GitHub configuration shared by the XWiki repositories: default community health files, reusable workflows and the Renovate preset · GitHub

I’ve written up what’s in it and what changes for everyone in a separate thread, to keep this one about the checks themselves: New .github repo in the XWiki GH organization for shared GitHub configuration

Short version: quality-pr.yml and backport.yml are now single reusable workflows called by a small stub in each repo, the PR template / SECURITY.md / FUNDING.yml are served org-wide, and there’s a shared Renovate preset. Two things to be aware of here: the PR check is now named Quality / Analyze instead of Analyze, and the workflow is edited in xwiki/.github from now on, not in the three repos.

@tmortagne, you were right about java-version — there’s no such input, it’s read from the pom as you expected.