🐛 fix(ci): handle missing sonar project key gracefully
Some checks failed
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Failing after 6s
build-and-push / docker (push) Has been skipped

- set default empty value for PROJECT_KEY variable
- add fallback to read sonar-project.properties if secret is not provided
- exit with error if PROJECT_KEY is still unset after checks
This commit is contained in:
nocci 2025-12-30 13:05:40 +00:00
parent 608b6b87cd
commit 02972a04d4

View file

@ -35,7 +35,14 @@ jobs:
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
run: | run: |
HOST_URL=${SONAR_HOST_URL:?SONAR_HOST_URL secret not set} HOST_URL=${SONAR_HOST_URL:?SONAR_HOST_URL secret not set}
PROJECT_KEY=${SONAR_PROJECT_KEY:?SONAR_PROJECT_KEY secret not set} PROJECT_KEY=${SONAR_PROJECT_KEY:-}
if [ -z "$PROJECT_KEY" ] && [ -f sonar-project.properties ]; then
PROJECT_KEY=$(grep -E '^sonar.projectKey=' sonar-project.properties | cut -d= -f2 | tr -d '\r')
fi
if [ -z "$PROJECT_KEY" ]; then
echo "SONAR_PROJECT_KEY secret not set and no sonar-project.properties entry found" >&2
exit 1
fi
docker run --rm \ docker run --rm \
-e SONAR_HOST_URL="$HOST_URL" \ -e SONAR_HOST_URL="$HOST_URL" \
-e SONAR_TOKEN="$SONAR_TOKEN" \ -e SONAR_TOKEN="$SONAR_TOKEN" \
@ -44,7 +51,6 @@ jobs:
sonarsource/sonar-scanner-cli \ sonarsource/sonar-scanner-cli \
sonar-scanner \ sonar-scanner \
-Dsonar.host.url="$HOST_URL" \ -Dsonar.host.url="$HOST_URL" \
-Dsonar.token="$SONAR_TOKEN" \
-Dsonar.projectKey="$PROJECT_KEY" \ -Dsonar.projectKey="$PROJECT_KEY" \
-Dsonar.sources=. \ -Dsonar.sources=. \
-Dsonar.scm.provider=none \ -Dsonar.scm.provider=none \