# Copyright 2021 Collate # Licensed 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: OpenMetadata Service Unit Tests on: merge_group: workflow_dispatch: push: branches: - main pull_request: types: [labeled, opened, synchronize, reopened, ready_for_review] permissions: contents: read checks: write pull-requests: write concurrency: group: openmetadata-service-unit-tests-${{ github.head_ref || github.run_id }} cancel-in-progress: ${{ github.event_name != 'pull_request' || github.event.action != 'labeled' || github.event.label.name == 'safe to test' }} jobs: # Detect whether relevant paths changed. When no Java service files # are modified the downstream jobs are skipped via their `if` condition. # A job skipped by `if` reports as "Success", so required checks still pass. # This replaces the old openmetadata-service-unit-tests-skip.yml companion workflow. changes: name: Detect Changes runs-on: ubuntu-latest if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (github.event_name != 'pull_request' || github.event.action != 'labeled' || github.event.label.name == 'safe to test') }} outputs: java: ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.filter.outputs.java }} k8s_operator: ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.filter.outputs.k8s_operator }} steps: - name: Checkout uses: actions/checkout@v4 if: ${{ github.event_name != 'workflow_dispatch' }} - uses: dorny/paths-filter@v3 id: filter if: ${{ github.event_name != 'workflow_dispatch' }} with: filters: | java: - '.github/workflows/openmetadata-service-unit-tests.yml' - 'openmetadata-service/**' - 'openmetadata-spec/**' - 'openmetadata-clients/**' - 'openmetadata-sdk/**' - 'common/**' - 'pom.xml' - 'Makefile' - 'bootstrap/**' k8s_operator: - 'openmetadata-k8s-operator/**' # The openmetadata-service unit tests are pure JVM tests with no database # interaction (no testcontainers, no JDBC). The {mysql, postgresql} matrix used # to run the suite twice with different `-Pmysql` / `-Ppostgresql` profiles, but # those profiles are only defined in openmetadata-sdk/pom.xml and only affect # failsafe (integration) tests that aren't enabled in this workflow. Result: # both matrix jobs ran an identical surefire suite. DB-specific coverage # belongs in `openmetadata-integration-tests`, not here. openmetadata-service-unit-tests: runs-on: ubuntu-latest timeout-minutes: 90 needs: changes if: ${{ needs.changes.outputs.java == 'true' }} steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - name: Cache Maven dependencies uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: "21" distribution: "temurin" - name: Install Ubuntu dependencies run: | sudo apt-get update sudo apt-get install -y unixodbc-dev python3-venv librdkafka-dev gcc libsasl2-dev build-essential libssl-dev libffi-dev \ librdkafka-dev unixodbc-dev libevent-dev jq sudo make install_antlr_cli - name: Run openmetadata-service unit tests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | mvn -B clean package -pl openmetadata-service -am \ -Pstatic-code-analysis \ -DfailIfNoTests=false \ -Dsonar.skip=true - name: Upload surefire reports if: ${{ failure() && hashFiles('openmetadata-service/target/surefire-reports/TEST-*.xml') != '' }} uses: actions/upload-artifact@v4 with: name: openmetadata-service-surefire-reports path: openmetadata-service/target/surefire-reports/ - name: Publish Test Report if: ${{ always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && hashFiles('openmetadata-service/target/surefire-reports/TEST-*.xml') != '' }} uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} fail_on_test_failures: true report_paths: "openmetadata-service/target/surefire-reports/TEST-*.xml" check_name: "Test Report" k8s_operator-unit-tests: runs-on: ubuntu-latest timeout-minutes: 30 needs: changes if: ${{ needs.changes.outputs.k8s_operator == 'true' }} steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - name: Cache Maven dependencies uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: "21" distribution: "temurin" - name: Build k8s-operator dependencies run: | mvn -B clean install -pl openmetadata-k8s-operator -am -DskipTests - name: Run k8s-operator unit tests run: | mvn -B test -pl openmetadata-k8s-operator - name: Upload surefire reports if: ${{ failure() && hashFiles('openmetadata-k8s-operator/target/surefire-reports/TEST-*.xml') != '' }} uses: actions/upload-artifact@v4 with: name: k8s-operator-surefire-reports path: openmetadata-k8s-operator/target/surefire-reports/ - name: Publish Test Report if: ${{ always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && hashFiles('openmetadata-k8s-operator/target/surefire-reports/TEST-*.xml') != '' }} uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} fail_on_test_failures: true report_paths: "openmetadata-k8s-operator/target/surefire-reports/TEST-*.xml" check_name: "K8s Operator Test Report" # Single required-check gate for branch protection. # Skipped (= "Success") when all test jobs pass or are legitimately skipped. # Runs and exits 1 only when a test job fails or is cancelled. # Set "OpenMetadata Service Unit Tests / openmetadata-service-unit-tests-status" as the sole required check for this workflow. openmetadata-service-unit-tests-status: name: openmetadata-service-unit-tests-status needs: [changes, openmetadata-service-unit-tests, k8s_operator-unit-tests] if: ${{ failure() || cancelled() }} runs-on: ubuntu-latest steps: - run: exit 1