Add sonar analysis to CI #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java CI with Maven | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: maven | |
- name: Set up MySQL | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y mysql-server | |
sudo service mysql start | |
- name: Create MySQL database | |
run: | | |
sudo apt-get install mysql-client | |
mysql -u root -proot -e "CREATE DATABASE IF NOT EXISTS autocrud;" | |
# Run tests | |
- name: Run tests with Maven | |
run: mvn -B test --file pom.xml | |
build: | |
runs-on: ubuntu-latest | |
needs: test # This ensures the build job only runs if tests pass | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: maven | |
# Build the project | |
- name: Build with Maven | |
run: mvn -B package -DskipTests=true --file pom.xml | |
# Save build artifacts | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: target/*.jar | |
# SonarCloud Analysis | |
- name: SonarCloud Scan | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
mvn sonar:sonar -Dsonar.projectKey=geo-tp_AutoCrud \ | |
-Dsonar.organization=geo-tp \ | |
-Dsonar.login=${{ secrets.SONAR_TOKEN }} |