Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate sonar-project.properties so forks can use SonarCloud #393

Open
IrateRedKite opened this issue Feb 10, 2024 · 2 comments
Open

Generate sonar-project.properties so forks can use SonarCloud #393

IrateRedKite opened this issue Feb 10, 2024 · 2 comments
Labels
ci/cd Issues that related to CI/CD proposal Proposal for a new feature or API change
Milestone

Comments

@IrateRedKite
Copy link
Contributor

I was looking at getting SonarCloud set up for our fork of FlHook and found that it's reliant on sonar-project.properties.

Obviously I'd rather not have to worry about accidentally pushing my version of this to the main branch, so would like to propose a workflow that generates the file using github actions and environment variables instead. Something a bit like:

name: SonarProjectProperties

on:
  push:
    branches: [ master ]
    
jobs:
  deploy:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          submodules: true
      - name: Generate sonar-project.properties
        run: |
          touch sonar-project.properties
          echo "sonar.projectKey=$SONAR_PROJECTKEY" >> sonar-project.properties
          echo "sonar.organization=$SONAR_PROJECTORG" >> sonar-project.properties
          echo >> sonar-project.properties
          echo "# This is the name and version displayed in the SonarCloud UI." >> sonar-project.properties
          echo "sonar.projectName=$SONAR_PROJECTNAME" >> sonar-project.properties
          echo "sonar.projectVersion=$SONAR_PROJECTVERSION" >> sonar-project.properties
          echo >> sonar-project.properties
          echo "# Path is relative to the sonar-project.properties file. Replace '\' by '/' on Windows." >> sonar-project.properties
          echo "sonar.sources=." >> sonar-project.properties
          echo "sonar.exclusions = $SONAR_EXCLUSIONS" >> sonar-project.properties
          echo >> sonar-project.properties
          echo "# Encoding of the source code. Default is default system encoding" >> sonar-project.properties
          echo "sonar.sourceEncoding=UTF-8" >> sonar-project.properties
          cp "sonar-project.properties" staging
      - name: Commit to branch
        run: |
          cd staging
          echo $env:TAG > .github/workflows/flhooktag
          git config user.name github-actions
          git config user.email [email protected]
          git add sonar-project.properties
          git add .github/workflows/flhooktag
          git commit -m "Generate sonar-project.properties for build"
          git push

My knowledge of CI/CD is quite limited, so I'd appreciate it if someone like @Lazrius could take a look and let me know how viable this implementation is.

@IrateRedKite IrateRedKite added the proposal Proposal for a new feature or API change label Feb 10, 2024
@IrateRedKite IrateRedKite changed the title Gewnerate sonar-project.properties so forks can use SonarCloud Generate sonar-project.properties so forks can use SonarCloud Feb 10, 2024
@oliverpechey
Copy link
Member

I know it was my idea, but now I'm not convinced we would need to generate a dynamic properties file to remain compatible with Forks.

You seem to be able to pass sonar properties to the scanner directly. Presumably it looks up missing ones in the properties file.

So perhaps we could add the repo specific ones here with variables, and just keep the generic ones in the properties file?

@IrateRedKite IrateRedKite modified the milestones: Backlog, 4.1 Feb 12, 2024
@IrateRedKite IrateRedKite added stretch ci/cd Issues that related to CI/CD and removed stretch labels Feb 12, 2024
@Lazrius
Copy link
Member

Lazrius commented May 20, 2024

In the newest version, manual sonar scanning will no longer be nessasary and our reliance on github actions will be removed. Will leave issue open until 5.0 is merged, but it is currently possible for you to have forks be scanned through the sonar portal (our config may be out of date, not tried)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/cd Issues that related to CI/CD proposal Proposal for a new feature or API change
Projects
Status: Ready
Development

No branches or pull requests

3 participants