Generate sonar-project.properties so forks can use SonarCloud
Opened this issue · 2 comments
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 github-actions@github.com
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.
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.
FLHook/.github/workflows/sonar-scan.yml
Line 76 in 4832a27
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?
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)