Skip to content

ci: add a GH action for SonarCloud #7

ci: add a GH action for SonarCloud

ci: add a GH action for SonarCloud #7

Workflow file for this run

name: SonarCloud
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
id: setup-java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ~/.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
curl -sSLo sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-linux.zip
unzip sonar-scanner.zip -d ~/.sonar/
mv ~/.sonar/sonar-scanner-4.6.2.2472-linux ~/.sonar/scanner
~/.sonar/scanner/bin/sonar-scanner --version
- name: Ensure Java 17 is used
run: |
echo "JAVA_HOME: ${{ steps.setup-java.outputs.java-home }}"
export JAVA_HOME=${{ steps.setup-java.outputs.java-home }}
export PATH=${JAVA_HOME}/bin:${PATH}
java -version
- name: SonarCloud Scan
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
export JAVA_HOME=${{ steps.setup-java.outputs.java-home }}
export PATH=${JAVA_HOME}/bin:${PATH}
~/.sonar/scanner/bin/sonar-scanner -X \
-Dsonar.projectKey=fireorm24 \
-Dsonar.organization=elersong \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=${{ secrets.SONAR_TOKEN }}