|
1 | | -# This workflow will build a Java project with Gradle |
2 | | -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle |
3 | | - |
4 | | -name: Java PR builder with Gradle |
| 1 | +name: Java PR Builder with Gradle and SonarCloud |
5 | 2 |
|
6 | 3 | on: |
7 | 4 | pull_request_target: |
|
10 | 7 |
|
11 | 8 | jobs: |
12 | 9 | build-and-analyze: |
13 | | - |
14 | | - runs-on: ubuntu-20.04 |
| 10 | + name: Build and SonarCloud Analysis |
| 11 | + runs-on: ubuntu-latest |
15 | 12 |
|
16 | 13 | steps: |
17 | | - - name: Checkout Code |
18 | | - uses: actions/checkout@v3 |
| 14 | + - name: Checkout PR source code |
| 15 | + uses: actions/checkout@v4 |
19 | 16 | with: |
20 | 17 | ref: ${{ github.event.pull_request.head.sha }} |
21 | 18 |
|
| 19 | + - name: Validate Gradle wrapper |
| 20 | + uses: gradle/wrapper-validation-action@v1 |
| 21 | + |
22 | 22 | - name: Set up JDK 21 |
23 | | - uses: actions/setup-java@v3 |
| 23 | + uses: actions/setup-java@v4 |
24 | 24 | with: |
25 | | - java-version: '21' |
26 | 25 | distribution: 'temurin' |
27 | | - |
28 | | - - name: Grant execute permission for gradlew |
29 | | - run: chmod +x gradlew |
30 | | - |
31 | | - - name: Build and analyze with Gradle |
32 | | - run: ./gradlew build sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_30-seconds-of-java -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
| 26 | + java-version: '21' |
| 27 | + cache: 'gradle' |
| 28 | + |
| 29 | + - name: Make Gradle executable |
| 30 | + run: chmod +x ./gradlew |
| 31 | + |
| 32 | + - name: Build and analyze with Gradle and SonarCloud |
| 33 | + run: | |
| 34 | + ./gradlew build sonarqube --no-daemon \ |
| 35 | + -Dsonar.host.url=https://sonarcloud.io \ |
| 36 | + -Dsonar.organization=iluwatar \ |
| 37 | + -Dsonar.projectKey=iluwatar_30-seconds-of-java \ |
| 38 | + -Dsonar.pullrequest.branch=${{ github.head_ref }} \ |
| 39 | + -Dsonar.pullrequest.base=${{ github.base_ref }} \ |
| 40 | + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
33 | 41 | env: |
34 | 42 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
35 | 43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments