|
| 1 | +# Description |
| 2 | +# =========== |
| 3 | +# This workflow is triggered each time |
| 4 | +# commits are pushed to GitHub or a pull request is opened. |
| 5 | +# It launches three jobs in parallel : a build with java 8, |
| 6 | +# a build with java 11 and a SonarCloud analysis. |
| 7 | +--- |
| 8 | +name: Java CI |
| 9 | + |
| 10 | +on: [push, pull_request] |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + name: Java 11 CI |
| 17 | + steps: |
| 18 | + - name: Check out repository code |
| 19 | + uses: actions/checkout@v2 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + - name: Setup java |
| 23 | + uses: actions/setup-java@v2 |
| 24 | + with: |
| 25 | + distribution: 'adopt' |
| 26 | + java-version: 11 |
| 27 | + - name: Cache Maven packages |
| 28 | + uses: actions/cache@v2 |
| 29 | + with: |
| 30 | + path: ~/.m2 |
| 31 | + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 32 | + restore-keys: ${{ runner.os }}-m2 |
| 33 | + - name: Build with Maven |
| 34 | + run: mvn -B clean test package |
| 35 | + |
| 36 | + code-analysis: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + name: SonarCloud Code Analysis |
| 39 | + # It's not possible to launch an analysis on external pull requests |
| 40 | + if: ${{ github.repository_owner == 'cnescatlab' }} |
| 41 | + steps: |
| 42 | + - name: Check out repository code |
| 43 | + uses: actions/checkout@v2 |
| 44 | + with: |
| 45 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
| 46 | + - name: Setup java |
| 47 | + uses: actions/setup-java@v2 |
| 48 | + with: |
| 49 | + distribution: 'adopt' |
| 50 | + java-version: '11' |
| 51 | + - name: Cache Maven packages |
| 52 | + uses: actions/cache@v2 |
| 53 | + with: |
| 54 | + path: ~/.m2 |
| 55 | + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 56 | + restore-keys: ${{ runner.os }}-m2 |
| 57 | + - name: Cache SonarCloud packages |
| 58 | + uses: actions/cache@v2 |
| 59 | + with: |
| 60 | + path: ~/.sonar/cache |
| 61 | + key: ${{ runner.os }}-sonar |
| 62 | + restore-keys: ${{ runner.os }}-sonar |
| 63 | + - name: Build and analyze |
| 64 | + env: |
| 65 | + # Needed to get some information about the pull request, if any |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ |
| 68 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 69 | + run: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.organization=lequal -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN |
0 commit comments