Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GitHub Actions workflow to verify builds and pull requests #166

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# yaml-language-server:$schema=https://json.schemastore.org/github-workflow.json
name: Java CI with Maven

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
contents: read

jobs:
legacy-java:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 6, 8 ]
name: Java ${{ matrix.java }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
# JDK 11 is required for Maven itself as runtime
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: |
${{ matrix.java }}
11
- name: Cache Maven artifacts
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.m2/wrapper
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup Maven
run: |
mkdir -p .mvn
echo "-B" > .mvn/maven.config
- name: Compile with Java ${{ matrix.java }}
run: mvn clean compile -P=legacy-java -Djava.version="1.${{ matrix.java }}"
- name: Run Tests with Java ${{ matrix.java }}
run: mvn test -P=legacy-java -Djava.version="1.${{ matrix.java }}"
- name: Build Test Report for Java ${{ matrix.java }}
if: ${{ always() }}
run: |
mvn surefire-report:report-only
mvn site -DgenerateReports=false
- name: Upload Test Results for Java ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Test Results for Java ${{ matrix.java }}
path: target/surefire-reports/
- name: Upload Test Report ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Test Report for Java ${{ matrix.java }}
path: target/site/

build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 17, 21 ]
name: Java ${{ matrix.java }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: ${{ matrix.java }}
- name: Cache Maven artifacts
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.m2/wrapper
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup Maven
run: |
mkdir -p .mvn
echo "-B" > .mvn/maven.config
- name: Compile with Java ${{ matrix.java }}
run: mvn clean compile -Djava.version="${{ matrix.java }}"
- name: Run Tests with Java ${{ matrix.java }}
run: mvn test -Djava.version="${{ matrix.java }}"
- name: Build Test Report for Java ${{ matrix.java }}
if: ${{ always() }}
run: |
mvn surefire-report:report-only
mvn site -DgenerateReports=false
- name: Upload Test Results for Java ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Test Results for Java ${{ matrix.java }}
path: target/surefire-reports/
- name: Upload Test Report ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: Test Report for Java ${{ matrix.java }}
path: target/site/
71 changes: 70 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
<url>https://github.com/skyscreamer/JSONassert</url>

<properties>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
<maven.compiler.encoding>${project.build.sourceEncoding}</maven.compiler.encoding>

<java.version>1.8</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
<toolchain.jdk.version>[${java.version},${parsedVersion.nextMajorVersion})</toolchain.jdk.version>
<!-- For some reason IfMatch does not work as expected together with Java 8 and below -->
<toolchain.jdk.mode>IfSame</toolchain.jdk.mode>
</properties>

<licenses>
Expand Down Expand Up @@ -62,10 +70,58 @@

<build>
<plugins>
<!--
Plugin declaration order is the deciding factor when the same phase is targeted
builder-helper-maven-plugin has to execute before maven-toolchains-plugin or else
the expected property will not be available because the selected goals run in the
same phase by default (`validate`).
See:
- https://maven.apache.org/ref/3.9.8/maven-core/lifecycles.html
- https://www.mojohaus.org/build-helper-maven-plugin/parse-version-mojo.html
- https://maven.apache.org/plugins/maven-toolchains-plugin/select-jdk-toolchain-mojo.html
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<versionString>${java.version}</versionString>
</configuration>
</execution>
</executions>
</plugin>
<!--
Maven Toolchains has to be declared before the compiler plugin
or else the wrong JDK/JVM will be used for compilation.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>select-jdk-toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<!--
Ensure that the correct compiler is used independently of the Maven runtime selection.
This is also important in case the JDK/JVM runtime args need to be modified for compilation e.g. for Google Error-Prone integration.
-->
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
Expand Down Expand Up @@ -100,6 +156,19 @@
</distributionManagement>

<profiles>
<profile>
<id>legacy-java</id>
<!-- Automatically activate if the runtime JDK is Java 8 or below -->
<activation>
<jdk>(,1.8]</jdk>
</activation>
<properties>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<!-- Unset the release flag that isn't supported by Java 8 and below -->
<maven.compiler.release></maven.compiler.release>
</properties>
</profile>
<profile>
<id>deploy</id>
<build>
Expand Down