Skip to content

Commit

Permalink
Only execute build once during CI and then run distinct jobs to run t…
Browse files Browse the repository at this point in the history
…ests for each Java version.
  • Loading branch information
norrisjeremy committed Jul 11, 2024
1 parent a7ef4a0 commit 1459a94
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
48 changes: 34 additions & 14 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,61 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '11', '17', '21']
steps:
- uses: actions/checkout@v4
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
path: |
~/.m2/repository
~/.m2/wrapper
key: ${{ runner.os }}-build-maven-${{ hashFiles('**/pom.xml', '**/maven-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-${{ matrix.java }}-maven-
- name: Set up build JDK
${{ runner.os }}-build-maven-
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'
check-latest: true
- name: Build with Maven
run: ./mvnw -B -V -e -DskipTests=true package
run: ./mvnw -B -V -e verify -DskipTests=true -DskipITs=true
- name: Archive target directory
run: tar -cf target.tar target
- uses: actions/upload-artifact@v4
with:
name: java-${{ matrix.java }}-jars
name: build_target
path: target.tar
test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '11', '17', '21']
steps:
- uses: actions/checkout@v4
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: |
**/target/*.jar
**/target/bom.*
if: always()
- name: Set up test JDK ${{ matrix.java }}
~/.m2/repository
~/.m2/wrapper
key: ${{ runner.os }}-test-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml', '**/maven-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-test-${{ matrix.java }}-maven-
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
check-latest: true
- uses: actions/download-artifact@v4
with:
name: build_target
- name: Extract target directory
run: tar -xf target.tar
- name: Test with Maven
run: ./mvnw -B -V -e -P coverage verify -Denforcer.skip=true -Dmaven.resources.skip=true -Dflatten.skip=true -Dmaven.main.skip=true -Dbnd.skip=true -Dassembly.skipAssembly=true -Dmaven.javadoc.skip=true -Dcyclonedx.skip=true -DskipITs=false
run: ./mvnw -B -V -e -Pcoverage verify -Denforcer.skip=true -Dmaven.resources.skip=true -Dflatten.skip=true -Dmaven.main.skip=true -Dbnd.skip=true -Dassembly.skipAssembly=true -Dmaven.javadoc.skip=true -Dcyclonedx.skip=true -Dformatter.skip=true -Dforbiddenapis.skip=true -DskipTests=false -DskipITs=false
- uses: actions/upload-artifact@v4
with:
name: java-${{ matrix.java }}-testresults
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.geany
nb-configuration.xml
.flattened-pom.xml
target.tar

# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,netbeans,eclipse,visualstudiocode,vim,emacs,macos,windows,linux,java,maven
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,netbeans,eclipse,visualstudiocode,vim,emacs,macos,windows,linux,java,maven
Expand Down

0 comments on commit 1459a94

Please sign in to comment.