| 1 |
name: Build and test (using maven) |
| 2 |
|
| 3 |
#on: [push, pull_request] |
| 4 |
#on: [pull_request] |
| 5 |
on: |
| 6 |
# Trigger the workflow on push to master (ignoring .md only changes) |
| 7 |
push: |
| 8 |
branches: |
| 9 |
- master |
| 10 |
paths-ignore: |
| 11 |
- '**.md' |
| 12 |
|
| 13 |
# Trigger the workflow on any pull_request (ignoring .md only changes) |
| 14 |
pull_request: |
| 15 |
paths-ignore: |
| 16 |
- '**.md' |
| 17 |
|
| 18 |
# Enable manual triggering (important for contributors to enable a check on their fork) |
| 19 |
workflow_dispatch: |
| 20 |
|
| 21 |
# If a build is running in the current branch, and the branch is updated, we cancel the previous build and start |
| 22 |
# a new one with the updated changes. |
| 23 |
concurrency: |
| 24 |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 25 |
cancel-in-progress: true |
| 26 |
|
| 27 |
jobs: |
| 28 |
maven_test: |
| 29 |
strategy: |
| 30 |
## Optionally cancel all other combinations if one fails |
| 31 |
fail-fast: false |
| 32 |
matrix: |
| 33 |
## Different OSs have different default line-endings -- test on all combinations. |
| 34 |
os: [ ubuntu-latest, macos-latest, windows-latest ] |
| 35 |
## Different JDK versions have different implementations etc. -- test on all combinations (ideally 8 to latest). |
| 36 |
### exclude pre-8 (min development version jdk8) |
| 37 |
jdk: [ 8,9,10,11,12,13,14,15,16,17,18 ] |
| 38 |
env: |
| 39 |
OS: ${{ matrix.os }} |
| 40 |
JDK: ${{ matrix.jdk }} |
| 41 |
|
| 42 |
runs-on: ${{ matrix.os }} |
| 43 |
|
| 44 |
steps: |
| 45 |
## Checkout the current version of the code from the repo. |
| 46 |
- name: Checkout latest code |
| 47 |
uses: actions/[email protected] |
| 48 |
with: |
| 49 |
fetch-depth: "0" |
| 50 |
|
| 51 |
## Setup the specified version of Java (includes maven/gradle). |
| 52 |
- name: Set up JDK ${{ matrix.jdk }} |
| 53 |
uses: actions/setup-java@v4 |
| 54 |
with: |
| 55 |
distribution: 'zulu' # v2 requires explicitly stating the distribution - `zulu` and `adopt` supported at time of writing |
| 56 |
java-version: ${{ matrix.jdk }} # Use matrix to select which JDK level to use |
| 57 |
java-package: jdk # optional (jdk or jre) - defaults to jdk |
| 58 |
|
| 59 |
## Given that the build matrix only specifies the major version (configurable), output the precise version used. |
| 60 |
- name: Echo exact java version being used |
| 61 |
run: java -version |
| 62 |
|
| 63 |
## Use a cache to reduce the build/test times (avoids having to download dependencies on EVERY run). |
| 64 |
### https://help.github.com/en/actions/language-and-framework-guides/building-and-testing-java-with-maven#caching-dependencies |
| 65 |
- name: Cache Maven packages |
| 66 |
uses: actions/cache@v4 |
| 67 |
with: |
| 68 |
path: ~/.m2 |
| 69 |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 70 |
restore-keys: ${{ runner.os }}-m2 |
| 71 |
|
| 72 |
|
| 73 |
## Actually perform the tests. Unsuccessful tests will indicate a failed build. |
| 74 |
### -e, --errors : show traces where any errors occur |
| 75 |
### -B,--batch-mode : Run in non-interactive (batch) mode (disables output color) |
| 76 |
### clean : run the maven lifecycle stage `clean` |
| 77 |
### test : run the maven lifecycle stage `test` |
| 78 |
### -P,--activate-profiles : Comma-delimited list of profiles to activate |
| 79 |
### AlsoSlowTests : by default, only quick tests are run - the profile `AlsoSlowTests` runs the full test suite |
| 80 |
- name: Test with Maven (incl. slow tests) |
| 81 |
shell: bash |
| 82 |
run: ./mvnw -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B --errors clean test --activate-profiles AlsoSlowTests |
| 83 |
|
| 84 |
|
| 85 |
- name: CodeCov - JavaParser Core |
| 86 |
uses: codecov/[email protected] |
| 87 |
timeout-minutes: 10 |
| 88 |
with: |
| 89 |
files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml |
| 90 |
fail_ci_if_error: false # optional (default = false) -- fail the build if upload to codecov.io fails |
| 91 |
verbose: false # optional (default = false): |
| 92 |
flags: javaparser-core,AlsoSlowTests,${{ matrix.os }},jdk-${{ matrix.jdk }} |
| 93 |
env_vars: OS,JDK |
| 94 |
|
| 95 |
- name: CodeCov - JavaParser Symbol Solver |
| 96 |
uses: codecov/[email protected] |
| 97 |
timeout-minutes: 10 |
| 98 |
with: |
| 99 |
file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml |
| 100 |
fail_ci_if_error: false # optional (default = false) -- fail the build if upload to codecov.io fails |
| 101 |
verbose: false # optional (default = false): |
| 102 |
flags: javaparser-symbol-solver,AlsoSlowTests,${{ matrix.os }},jdk-${{ matrix.jdk }} |
| 103 |
env_vars: OS,JDK |
| 104 |
|
| 105 |
# Run checkstyle validations for pipeline |
| 106 |
checkstyle_check: |
| 107 |
name: Validate checkstyle |
| 108 |
runs-on: ubuntu-latest |
| 109 |
steps: |
| 110 |
- name: Checkout latest code |
| 111 |
uses: actions/[email protected] |
| 112 |
with: |
| 113 |
fetch-depth: "0" |
| 114 |
- name: Set up JDK 11 |
| 115 |
uses: actions/setup-java@v4 |
| 116 |
with: |
| 117 |
java-version: '11' |
| 118 |
distribution: 'zulu' |
| 119 |
- name: Validate Project Checkstyle |
| 120 |
run: ./mvnw -B checkstyle:check |
| 121 |
|
| 122 |
spotless_check: |
| 123 |
name: Validate code generation and formatting |
| 124 |
runs-on: ubuntu-latest |
| 125 |
steps: |
| 126 |
- name: Checkout latest code |
| 127 |
uses: actions/[email protected] |
| 128 |
with: |
| 129 |
fetch-depth: "0" |
| 130 |
- name: Set up JDK 11 |
| 131 |
uses: actions/setup-java@v4 |
| 132 |
with: |
| 133 |
java-version: '11' |
| 134 |
distribution: 'zulu' |
| 135 |
- name: Generate code and format |
| 136 |
run: | |
| 137 |
./run_core_metamodel_generator.sh |
| 138 |
# ./run_core_generators.sh automatically runs ./mvnw spotless:apply |
| 139 |
./run_core_generators.sh |
| 140 |
git diff --exit-code |