| # Licensed to the Apache Software Foundation (ASF) under one | |
| # or more contributor license agreements. See the NOTICE file | |
| # distributed with this work for additional information | |
| # regarding copyright ownership. The ASF licenses this file | |
| # to you under the Apache License, Version 2.0 (the | |
| # "License"); you may not use this file except in compliance | |
| # with the License. You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, | |
| # software distributed under the License is distributed on an | |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| # KIND, either express or implied. See the License for the | |
| # specific language governing permissions and limitations | |
| # under the License. | |
| name: "Java Test" | |
| description: "Run Java tests" | |
| inputs: | |
| artifact_name: | |
| description: "Unique name for uploaded artifacts for this run" | |
| required: true | |
| suites: | |
| description: 'Which Scalatest test suites to run' | |
| required: false | |
| default: '' | |
| maven_opts: | |
| description: 'Maven options passed to the mvn command' | |
| required: false | |
| default: '' | |
| upload-test-reports: | |
| description: 'Whether to upload test results including coverage to GitHub' | |
| required: false | |
| default: 'false' | |
| skip-native-build: | |
| description: 'Skip native build (when using pre-built artifact)' | |
| required: false | |
| default: 'false' | |
| runs: | |
| using: "composite" | |
| steps: | |
| - name: Run Cargo release build | |
| if: ${{ inputs.skip-native-build != 'true' }} | |
| shell: bash | |
| # it is important that we run the Scala tests against a release build rather than a debug build | |
| # to make sure that no tests are relying on overflow checks that are present only in debug builds | |
| run: | | |
| cd native | |
| cargo build --release | |
| # Evaluate hashFiles now, on the clean checkout, and reuse the result in the | |
| # cache key below. The cache step's inputs are re-evaluated when its post | |
| # (cache-save) phase runs, and by then the test run has left trees under the | |
| # workspace (e.g. the Hive-catalog warehouse from CometIcebergEncryptionSuite) | |
| # that make a fresh '**/pom.xml' walk throw "Fail to hash files under | |
| # directory". A precomputed string keeps the save phase from re-walking them. | |
| - name: Compute Maven cache key | |
| id: maven-cache-key | |
| if: ${{ runner.os != 'macOS' }} | |
| shell: bash | |
| run: echo "hash=${{ hashFiles('**/pom.xml') }}" >> "$GITHUB_OUTPUT" | |
| - name: Restore Maven dependencies | |
| # TODO: remove next line after working again | |
| # temporarily work around https://github.com/actions/runner-images/issues/13341 | |
| # by disabling caching for macOS | |
| if: ${{ runner.os != 'macOS' }} | |
| id: maven-cache | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: | | |
| ~/.m2/repository | |
| /root/.m2/repository | |
| key: ${{ runner.os }}-java-maven-${{ steps.maven-cache-key.outputs.hash }} | |
| restore-keys: | | |
| ${{ runner.os }}-java-maven- | |
| # Maven itself is stored outside the dependency repository. Keep its cache | |
| # independent of pom.xml changes and preserve the macOS cache workaround. | |
| - name: Restore Maven distribution | |
| id: maven-distribution | |
| if: ${{ runner.os != 'macOS' }} | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: | | |
| ~/.m2/wrapper/dists | |
| /root/.m2/wrapper/dists | |
| key: ${{ runner.os }}-${{ runner.arch }}-maven-wrapper-${{ hashFiles('.mvn/wrapper/maven-wrapper.properties') }} | |
| # Retry only the wrapper download, never compilation or test execution. | |
| # Delays use exponential backoff (10s, 20s, 40s) plus 0-4s of random jitter. | |
| - name: Bootstrap Maven | |
| shell: bash | |
| run: | | |
| for attempt in 1 2 3 4; do | |
| if ./mvnw -B --version; then | |
| break | |
| fi | |
| if [ "$attempt" -eq 4 ]; then | |
| echo "::error::Maven bootstrap failed after $attempt attempts; tests were not started." | |
| exit 1 | |
| fi | |
| delay=$((10 * (1 << (attempt - 1)) + RANDOM % 5)) | |
| echo "::warning::Maven bootstrap attempt $attempt failed; retrying in ${delay}s." | |
| sleep "$delay" | |
| done | |
| # Save a successful bootstrap even when the subsequent tests fail. | |
| - name: Save Maven distribution | |
| if: ${{ runner.os != 'macOS' && steps.maven-distribution.outputs.cache-hit != 'true' }} | |
| uses: actions/cache/save@v5 | |
| with: | |
| path: | | |
| ~/.m2/wrapper/dists | |
| /root/.m2/wrapper/dists | |
| key: ${{ steps.maven-distribution.outputs.cache-primary-key }} | |
| - name: Run all tests | |
| shell: bash | |
| if: ${{ inputs.suites == '' }} | |
| env: | |
| SPARK_LOCAL_HOSTNAME: "localhost" | |
| SPARK_LOCAL_IP: "127.0.0.1" | |
| run: | | |
| MAVEN_OPTS="-Xmx4G -Xms2G -XX:+UnlockDiagnosticVMOptions -XX:+ShowMessageBoxOnError -XX:+HeapDumpOnOutOfMemoryError -XX:ErrorFile=./hs_err_pid%p.log" SPARK_HOME=`pwd` ./mvnw -B -Prelease install ${{ inputs.maven_opts }} | |
| - name: Run specified tests | |
| shell: bash | |
| if: ${{ inputs.suites != '' }} | |
| env: | |
| SPARK_LOCAL_HOSTNAME: "localhost" | |
| SPARK_LOCAL_IP: "127.0.0.1" | |
| run: | | |
| MAVEN_SUITES="$(echo "${{ inputs.suites }}" | paste -sd, -)" | |
| echo "Running with MAVEN_SUITES=$MAVEN_SUITES" | |
| MAVEN_OPTS="-Xmx4G -Xms2G -DwildcardSuites=$MAVEN_SUITES -XX:+UnlockDiagnosticVMOptions -XX:+ShowMessageBoxOnError -XX:+HeapDumpOnOutOfMemoryError -XX:ErrorFile=./hs_err_pid%p.log" SPARK_HOME=`pwd` ./mvnw -B -Prelease install ${{ inputs.maven_opts }} | |
| - name: Upload crash logs | |
| if: failure() | |
| # These three stay on the plain action rather than | |
| # ../upload-artifact-retry: a local action calling another local action | |
| # is untested in this repo. The two failure-only uploads run on jobs that | |
| # are already red. The test-report upload also runs on green jobs, so it | |
| # is continue-on-error: a FinalizeArtifact 403 must not turn a passing test | |
| # run into a red check, and nothing downstream consumes the reports. | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: crash-logs-${{ inputs.artifact_name }} | |
| path: "**/hs_err_pid*.log" | |
| if-no-files-found: ignore | |
| - name: Debug listing | |
| if: failure() | |
| shell: bash | |
| run: | | |
| echo "CWD: $(pwd)" | |
| ls -lah . | |
| if [ -d target ]; then | |
| ls -lah target | |
| else | |
| echo "No root target directory; Maven may not have started." | |
| fi | |
| find . -name 'unit-tests.log' | |
| - name: Upload unit-tests.log | |
| if: failure() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: unit-tests-${{ inputs.artifact_name }} | |
| path: "**/target/unit-tests.log" | |
| if-no-files-found: ignore | |
| - name: Upload test results | |
| if: ${{ !cancelled() && inputs.upload-test-reports == 'true' }} | |
| continue-on-error: true | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: java-test-reports-${{ inputs.artifact_name }} | |
| path: "**/target/surefire-reports/*.txt" | |
| if-no-files-found: ignore | |
| retention-days: 7 # 1 week for test reports | |
| overwrite: true | |
| # Saved only on main, and only on a green run: an entry written from a pull request or a | |
| # `gh-readonly-queue/*` branch cannot be restored by any later run, and it | |
| # evicts main's from the shared budget. See "Large caches are written on | |
| # main only" in ../../workflows/README.md. | |
| - name: Save Maven dependencies | |
| if: ${{ runner.os != 'macOS' && github.ref == 'refs/heads/main' && steps.maven-cache.outputs.cache-hit != 'true' }} | |
| uses: actions/cache/save@v5 | |
| with: | |
| path: | | |
| ~/.m2/repository | |
| /root/.m2/repository | |
| key: ${{ runner.os }}-java-maven-${{ steps.maven-cache-key.outputs.hash }} |