I was able to simplify the logic by doing just setting sonar.branch.name
explicitly when not on a PR:
sonar-project.properties
:
sonar.branch.name = ${env.SONAR_BRANCH}
Then in a shell step of the workflow yaml:
if [[ ! $GITHUB_BASE_REF ]]; then
# GITHUB_BASE_REF is only set for PRs, we are on a branch.
echo "SONAR_BRANCH=${GITHUB_REF_NAME}" >> $GITHUB_ENV
fi
This way the sonar.branch.name
is the only parameter to set and only set if we are not on a pull request analysis. Now everything is working well.