Skip to content

Commit

Permalink
Setup build for Java 11 and 16 (#546)
Browse files Browse the repository at this point in the history
Setup build for Java 11 and 16

* Project will compile on all versions
* Tests only will be run on 16
* Tests, Jacoco and Sonar will run on 11

Co-authored-by: Scott Leberknight <174812+sleberknight@users.noreply.github.com>
  • Loading branch information
chrisrohr and sleberknight authored Apr 14, 2021
1 parent 7629d58 commit 66e6aeb
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,64 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java_version: ['11', '16']
steps:
# Check out the project
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11

# Setup the version of Java
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v1
with:
java-version: 11
java-version: ${{ matrix.java_version }}

# Cache all the things
- name: Cache SonarCloud packages
uses: actions/cache@v1
uses: actions/cache@v2.1.4
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v1
uses: actions/cache@v2.1.4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Cache Embedded Mongo files
uses: actions/cache@v1
uses: actions/cache@v2.1.4
with:
path: ~/.embedmongo
key: ${{ runner.os }}-embedmongo
restore-keys: ${{ runner.os }}-embedmongo
- name: Build and analyze

# Compile the project
- name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: mvn -B -V compile

# Run tests when Java version > 11 (Sonar runs tests and analysis on JDK 11)
- name: Run tests
if: ${{ matrix.java_version != '11' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: mvn -B -V verify

# Run Sonar Analysis (on Java version 11 only)
- name: Analyze with SonarCloud
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml org.jacoco:jacoco-maven-plugin:prepare-agent package org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
run: mvn -B -V -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml org.jacoco:jacoco-maven-plugin:prepare-agent verify org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

0 comments on commit 66e6aeb

Please sign in to comment.