Repository navigation
Confine asset servlet paths to the resource root (#38590) #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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: [opened, synchronize, reopened, ready_for_review] | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| concurrency: | |
| group: openmetadata-service-unit-tests-${{ github.event.pull_request.number || github.run_id }} | |
| cancel-in-progress: true | |
| 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 }} | |
| 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 }} | |
| docker: ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.filter.outputs.docker }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| if: ${{ github.event_name != 'workflow_dispatch' }} | |
| with: | |
| persist-credentials: false | |
| - uses: dorny/paths-filter@v4 | |
| 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/**' | |
| # Everything that ends up inside the server image or decides how it | |
| # is launched. Not 'openmetadata-service/**': the smoke test asserts | |
| # image properties, not application behaviour, so a Java-only change | |
| # has nothing new for it to find. | |
| docker: | |
| - '.github/workflows/openmetadata-service-unit-tests.yml' | |
| - 'docker/openmetadata-start.sh' | |
| - 'docker/development/Dockerfile' | |
| - 'docker/docker-compose-quickstart/Dockerfile' | |
| - 'scripts/docker_smoke_test.sh' | |
| - 'openmetadata-dist/**' | |
| - 'conf/**' | |
| - 'bin/**' | |
| # The openmetadata-service unit tests need no shared database; the few classes | |
| # that touch one start their own Testcontainers. 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@v7 | |
| with: | |
| persist-credentials: false | |
| ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | |
| # Restore-only here; the save after the build runs on push to main only. | |
| # A PR-scoped copy is readable by that PR alone but still evicts the | |
| # main-scoped caches every run restores from the shared 10 GB budget. | |
| - name: Restore Maven dependencies | |
| id: maven-cache | |
| uses: actions/cache/restore@v6 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: "21" | |
| distribution: "temurin" | |
| # No -Pstatic-code-analysis: its JaCoCo agent slowed every test, yet `package` | |
| # never builds the report and nothing uploads it. No apt/ANTLR install either: | |
| # nothing here uses them (openmetadata-spec's prepare_model_schemas.py needs | |
| # only stdlib python3). | |
| - name: Run openmetadata-service unit tests | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| mvn -B clean package -pl openmetadata-service -am \ | |
| -DfailIfNoTests=false | |
| - name: Save Maven dependencies | |
| if: github.event_name == 'push' && steps.maven-cache.outputs.cache-hit != 'true' | |
| continue-on-error: true | |
| uses: actions/cache/save@v6 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ steps.maven-cache.outputs.cache-primary-key }} | |
| - name: Upload surefire reports | |
| if: ${{ failure() && hashFiles('openmetadata-service/target/surefire-reports/TEST-*.xml') != '' }} | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: openmetadata-service-surefire-reports | |
| path: openmetadata-service/target/surefire-reports/ | |
| 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@v7 | |
| with: | |
| persist-credentials: false | |
| ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | |
| - name: Restore Maven dependencies | |
| id: maven-cache | |
| uses: actions/cache/restore@v6 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| 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: Save Maven dependencies | |
| if: github.event_name == 'push' && steps.maven-cache.outputs.cache-hit != 'true' | |
| continue-on-error: true | |
| uses: actions/cache/save@v6 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ steps.maven-cache.outputs.cache-primary-key }} | |
| - name: Upload surefire reports | |
| if: ${{ failure() && hashFiles('openmetadata-k8s-operator/target/surefire-reports/TEST-*.xml') != '' }} | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: k8s-operator-surefire-reports | |
| path: openmetadata-k8s-operator/target/surefire-reports/ | |
| # The server image is distroless: no package manager, a non-root uid, a shell | |
| # that exists only because busybox is deliberately kept, and the glibc | |
| # libraries the JNI natives link against. Every one of those is a way for the | |
| # image to break without a single Java test noticing, so the build gets its own | |
| # smoke test. It needs no database and no search cluster -- see the script. | |
| docker-image-smoke-test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| needs: changes | |
| if: ${{ needs.changes.outputs.docker == 'true' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | |
| - name: Restore Maven dependencies | |
| id: maven-cache | |
| uses: actions/cache/restore@v6 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: "21" | |
| distribution: "temurin" | |
| - name: Install antlr cli | |
| run: sudo make install_antlr_cli | |
| # Sets SKIP_UI_BUILD=true on a hit, which the skip-ui-build profile in | |
| # openmetadata-ui/pom.xml reads. The smoke test never loads a page, so a | |
| # stale UI bundle costs it nothing and a cold yarn build costs it minutes. | |
| - name: Restore openmetadata-ui dist cache | |
| uses: ./.github/actions/cache-ui-dist | |
| - name: Build the distribution tarball | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| mvn -B -DskipTests package -pl openmetadata-dist -am | |
| - name: Save Maven dependencies | |
| if: github.event_name == 'push' && steps.maven-cache.outputs.cache-hit != 'true' | |
| continue-on-error: true | |
| uses: actions/cache/save@v6 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ steps.maven-cache.outputs.cache-primary-key }} | |
| - name: Smoke test the server image | |
| run: ./scripts/docker_smoke_test.sh | |
| # Single required-check gate for branch protection. | |
| # `always()` so the context reports on every PR: when the workflow is legitimately | |
| # skipped (draft PR / no relevant paths changed) this | |
| # exits 0; otherwise every triggered job must have succeeded. | |
| # 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, docker-image-smoke-test] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| if: ${{ always() }} | |
| steps: | |
| - name: Verify unit test suite | |
| env: | |
| CHANGES_RESULT: ${{ needs.changes.result }} | |
| JAVA_CHANGED: ${{ needs.changes.outputs.java }} | |
| K8S_CHANGED: ${{ needs.changes.outputs.k8s_operator }} | |
| DOCKER_CHANGED: ${{ needs.changes.outputs.docker }} | |
| SERVICE_RESULT: ${{ needs.openmetadata-service-unit-tests.result }} | |
| K8S_RESULT: ${{ needs.k8s_operator-unit-tests.result }} | |
| DOCKER_RESULT: ${{ needs.docker-image-smoke-test.result }} | |
| run: | | |
| # `changes` is skipped by its own `if:` on draft PRs. Nothing downstream | |
| # can have run, so the required check is legitimately green. | |
| if [[ "$CHANGES_RESULT" == "skipped" ]]; then | |
| echo "Detect Changes was skipped (draft PR); nothing to gate." | |
| exit 0 | |
| fi | |
| if [[ "$CHANGES_RESULT" != "success" ]]; then | |
| echo "::error::Detect Changes did not succeed: ${CHANGES_RESULT}" | |
| exit 1 | |
| fi | |
| fail=0 | |
| check() { | |
| local name="$1" changed="$2" result="$3" | |
| if [[ "$changed" != "true" ]]; then | |
| echo "${name}: no relevant paths changed, skipped." | |
| return | |
| fi | |
| if [[ "$result" != "success" ]]; then | |
| echo "::error::${name} did not succeed (result=${result})" | |
| fail=1 | |
| else | |
| echo "${name}: success" | |
| fi | |
| } | |
| check "openmetadata-service-unit-tests" "$JAVA_CHANGED" "$SERVICE_RESULT" | |
| check "k8s_operator-unit-tests" "$K8S_CHANGED" "$K8S_RESULT" | |
| check "docker-image-smoke-test" "$DOCKER_CHANGED" "$DOCKER_RESULT" | |
| exit $fail |