diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 78df856d580c..710812bd688f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -74,6 +74,7 @@ List the user-visible scenarios this PR exercises. Example: #### Ingestion integration tests diff --git a/.github/workflows/playwright-e2e-reusable.yml b/.github/workflows/playwright-e2e-reusable.yml index 93ae3e82f6d0..2201486c1fba 100644 --- a/.github/workflows/playwright-e2e-reusable.yml +++ b/.github/workflows/playwright-e2e-reusable.yml @@ -168,85 +168,23 @@ concurrency: cancel-in-progress: ${{ !contains(fromJSON('["pull_request","pull_request_target"]'), github.event_name) || github.event.action != 'labeled' || (github.event.label.name == 'safe to test' && github.event.pull_request.head.repo.full_name != github.repository) }} jobs: - # Fork-vs-same-repo PR arbitration. GitHub fires BOTH pull_request and - # pull_request_target on every PR event; without a gate the pipeline - # would either double-run same-repo PRs or run fork PRs with the wrong - # secrets. Routing: - # merge_group / schedule / workflow_dispatch → always run - # push (main-scoped cache warm) → always run - # drafts → never run - # labeled event with label != "safe to test" → skip (spurious re-fire) - # same-repo PR → pull_request handles it - # fork PR → pull_request_target - # handles it, must carry - # the "safe to test" label + # Playwright runs only in the merge queue (plus schedule / dispatch / main + # cache-warm pushes); callers skip this workflow on PR events. gate: runs-on: ubuntu-latest - permissions: - checks: read - contents: read - pull-requests: read + permissions: {} outputs: should_run: ${{ steps.gate.outputs.should_run }} steps: - # Team Label atomically removes stale fork approval on synchronize and - # re-adds it only for allowlisted authors. Wait for that reconciliation - # instead of relying on another labeled event: GITHUB_TOKEN label writes - # intentionally do not trigger a new workflow run. - - name: Wait for fork label reconciliation - if: | - github.event_name == 'pull_request_target' && - github.event.pull_request.head.repo.full_name != github.repository - uses: lewagon/wait-on-check-action@369769072fe522a3a8a85c03c96af1e5242a1994 # v1.9.1 - with: - ref: ${{ github.event.pull_request.head.sha }} - check-name: Team Label - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 10 - - - name: Read reconciled fork labels - id: fork-labels - if: | - github.event_name == 'pull_request_target' && - github.event.pull_request.head.repo.full_name != github.repository - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} - REPO: ${{ github.repository }} - run: | - set -euo pipefail - labels=$(gh api "/repos/${REPO}/pulls/${PR_NUMBER}" \ - --jq '[.labels[].name] | @json') - echo "labels=$labels" >> "$GITHUB_OUTPUT" - - name: Compute gate decision id: gate env: EVENT: ${{ github.event_name }} - ACTION: ${{ github.event.action }} - LABEL: ${{ github.event.label.name }} - HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} - BASE_REPO: ${{ github.repository }} - LABELS_JSON: ${{ steps.fork-labels.outputs.labels || toJSON(github.event.pull_request.labels.*.name) }} - IS_DRAFT: ${{ github.event.pull_request.draft }} run: | - set -euo pipefail - decide() { echo "should_run=$1" >> "$GITHUB_OUTPUT"; exit 0; } case "$EVENT" in - merge_group|schedule|workflow_dispatch|push) decide true ;; + merge_group|schedule|workflow_dispatch|push) echo "should_run=true" >> "$GITHUB_OUTPUT" ;; + *) echo "should_run=false" >> "$GITHUB_OUTPUT" ;; esac - if [[ "$IS_DRAFT" == "true" ]]; then decide false; fi - if [[ "$ACTION" == "labeled" && "$LABEL" != "safe to test" ]]; then decide false; fi - if [[ "$HEAD_REPO" == "$BASE_REPO" ]]; then - if [[ "$EVENT" == "pull_request" ]]; then decide true; else decide false; fi - fi - # Fork PR — pull_request_target must fire and the reconciled labels - # for the current head SHA must include "safe to test". - if [[ "$EVENT" == "pull_request_target" ]] && \ - echo "$LABELS_JSON" | jq -e '. | index("safe to test")' >/dev/null; then - decide true - fi - decide false check-changes: needs: gate diff --git a/.github/workflows/playwright-postgresql-e2e.yml b/.github/workflows/playwright-postgresql-e2e.yml index 7f6cb8b67873..c31b72fffe38 100644 --- a/.github/workflows/playwright-postgresql-e2e.yml +++ b/.github/workflows/playwright-postgresql-e2e.yml @@ -62,26 +62,12 @@ on: required: true type: boolean default: true - # Same-repo PRs run under pull_request — unprivileged, secrets absent - # from the runner. These jobs build PR code, populate caches, and - # exchange artifacts. + # Playwright runs only in the merge queue. PRs still trigger the workflow + # because `playwright-summary` is a required check: every job is skipped by + # its `if:` (no runner starts), and GitHub counts a skipped required check + # as passing. With no PR trigger the check would hang at "Expected — waiting". pull_request: types: - - labeled - - opened - - synchronize - - reopened - - ready_for_review - # Fork PRs need cloud-connector secrets (TEST_SNOWFLAKE_*, TEST_BQ_*, - # TEST_REDSHIFT_* …) that pull_request events cannot access on forks. - # pull_request_target runs in the base repo's context so those secrets - # resolve, but requires a maintainer to apply the "safe to test" label - # first (enforced by the gate job in the reusable workflow). Same-repo - # PRs already ran under pull_request above; the reusable short-circuits - # on them via the head-repo check in the gate job. - pull_request_target: - types: - - labeled - opened - synchronize - reopened @@ -94,6 +80,7 @@ permissions: jobs: playwright: + if: ${{ github.event_name != 'pull_request' }} uses: ./.github/workflows/playwright-e2e-reusable.yml # secrets: inherit passes the full TEST_* / GITHUB_TOKEN set into the # reusable without re-listing each one; the reusable only reads what it @@ -116,24 +103,12 @@ jobs: coarse_bundle: ${{ github.event_name == 'workflow_dispatch' && inputs.coarse_bundle || true }} # One retry everywhere while the first-attempt signal is collected: the # main-health job alerts Slack on every failure and flaky pass so each can - # be fixed. Once main runs clean, flip PRs to zero retries with: - # retries: ${{ !contains(fromJSON('["pull_request","pull_request_target"]'), github.event_name) && 1 || 0 }} - # (numeric, inverted so `0` is the else branch: `X && 0 || 1` would - # short-circuit to 1, and a string breaks the reusable's `type: number`). + # be fixed. retries: 1 playwright-summary: - name: >- - ${{ - ( - github.event.action == 'labeled' - || needs.playwright.outputs.gate_result != 'success' - || needs.playwright.outputs.gate_should_run == 'true' - ) - && 'playwright-summary' - || 'playwright-summary (skipped)' - }} - if: ${{ always() && !cancelled() }} + name: playwright-summary + if: ${{ always() && !cancelled() && github.event_name != 'pull_request' }} needs: [playwright] runs-on: ubuntu-latest timeout-minutes: 20 @@ -655,21 +630,6 @@ jobs: echo "::error::gate did not succeed (result=${{ needs.playwright.outputs.gate_result }}, should_run=${{ needs.playwright.outputs.gate_should_run }}). Refusing synthetic green — this playwright-summary must not report success without a valid gate decision." exit 1 - # Short-circuit when gate explicitly decided should_run=false — - # every upstream job is legitimately `skipped` in that case - # (redundant pull_request_target for a same-repo PR, or fork PR - # without safe-to-test), and the renderer below counts each - # skipped upstream as a "CI/reporting failure" and fails the whole - # check. That's what turned run 30090391086 red on PR #30454 despite - # the pipeline correctly opting out. Match on the exact "false" - # string (not != 'true') so unset outputs never fall through here. - - name: Report gate-skipped run as green - if: ${{ github.event_name != 'merge_group' && needs.playwright.outputs.gate_should_run == 'false' }} - run: | - echo "Gate decided should_run=false for event=${{ github.event_name }}." - echo "This run is intentionally skipped; the authoritative playwright-summary comes from the sibling event's run." - echo "Exiting 0 so this check does not block branch protection." - - name: Render consolidated job summary and gate on results if: ${{ always() && github.event_name != 'merge_group' && needs.playwright.outputs.gate_should_run == 'true' }} uses: actions/github-script@v9 diff --git a/.github/workflows/playwright-postgresql-pr-comment.yml b/.github/workflows/playwright-postgresql-pr-comment.yml index b94f3e339c47..552c4c0cc910 100644 --- a/.github/workflows/playwright-postgresql-pr-comment.yml +++ b/.github/workflows/playwright-postgresql-pr-comment.yml @@ -29,9 +29,7 @@ concurrency: jobs: publish-playwright-comment: - if: >- - github.event.workflow_run.event == 'pull_request' || - github.event.workflow_run.event == 'workflow_dispatch' + if: ${{ github.event.workflow_run.event == 'workflow_dispatch' }} runs-on: ubuntu-latest steps: - name: Checkout trusted workflow helpers diff --git a/.github/workflows/py-tests-postgres.yml b/.github/workflows/py-tests-postgres.yml index 78f0f7c8082f..73000819a8a8 100644 --- a/.github/workflows/py-tests-postgres.yml +++ b/.github/workflows/py-tests-postgres.yml @@ -25,7 +25,8 @@ concurrency: cancel-in-progress: ${{ github.event_name != 'pull_request_target' || github.event.action != 'labeled' || (github.event.label.name == 'safe to test' && github.event.pull_request.head.repo.full_name != github.repository) }} jobs: - # Integration tests only; the unit-test and coverage jobs run in py-tests.yml. + # Integration tests only, so PR runs skip everything (merge queue runs the suite); + # the unit-test and coverage jobs run in py-tests.yml. python: uses: ./.github/workflows/py-tests-shared.yml with: diff --git a/.github/workflows/py-tests-shared.yml b/.github/workflows/py-tests-shared.yml index 84a1145c2e81..f4891ec01545 100644 --- a/.github/workflows/py-tests-shared.yml +++ b/.github/workflows/py-tests-shared.yml @@ -64,6 +64,8 @@ jobs: outputs: python: ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.filter.outputs.python }} e2e: ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.filter.outputs.e2e }} + # PRs run unit tests only; the integration suite runs in the merge queue (and on dispatch). + integration: ${{ github.event_name == 'workflow_dispatch' && 'true' || github.event_name == 'merge_group' && steps.filter.outputs.python || 'false' }} steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -122,7 +124,7 @@ jobs: build-distribution: name: Build Backend Distribution needs: changes - if: ${{ needs.changes.outputs.python == 'true' }} + if: ${{ needs.changes.outputs.integration == 'true' }} timeout-minutes: 45 runs-on: ubuntu-latest steps: @@ -168,7 +170,7 @@ jobs: prepare-spacy-model: name: Prepare spaCy model needs: changes - if: ${{ needs.changes.outputs.python == 'true' }} + if: ${{ needs.changes.outputs.python == 'true' && (inputs.run-unit-tests || needs.changes.outputs.integration == 'true') }} timeout-minutes: 10 runs-on: ubuntu-latest concurrency: @@ -322,7 +324,7 @@ jobs: py-integration-tests: name: "Integration Tests (${{ matrix.shard.name }}, ${{ matrix.py-version }})" needs: [changes, build-distribution, prepare-spacy-model] - if: ${{ needs.changes.outputs.python == 'true' }} + if: ${{ needs.changes.outputs.integration == 'true' }} timeout-minutes: 180 runs-on: ubuntu-latest strategy: @@ -538,6 +540,7 @@ jobs: env: CHANGES_RESULT: ${{ needs.changes.result }} PYTHON_CHANGED: ${{ needs.changes.outputs.python }} + RUN_INTEGRATION: ${{ needs.changes.outputs.integration }} BUILD_RESULT: ${{ needs.build-distribution.result }} UNIT_RESULT: ${{ needs.py-unit-tests.result }} INTEGRATION_RESULT: ${{ needs.py-integration-tests.result }} @@ -553,10 +556,15 @@ jobs: expected_unit="success" fi + expected_integration="skipped" + if [ "$RUN_INTEGRATION" = "true" ]; then + expected_integration="success" + fi + if [ "$PYTHON_CHANGED" = "true" ]; then - if [ "$BUILD_RESULT" != "success" ] || [ "$INTEGRATION_RESULT" != "success" ] \ + if [ "$BUILD_RESULT" != "$expected_integration" ] || [ "$INTEGRATION_RESULT" != "$expected_integration" ] \ || [ "$UNIT_RESULT" != "$expected_unit" ]; then - echo "Expected Python jobs did not succeed: build=$BUILD_RESULT unit=$UNIT_RESULT (expected $expected_unit) integration=$INTEGRATION_RESULT" + echo "Expected Python jobs did not succeed: build=$BUILD_RESULT integration=$INTEGRATION_RESULT (expected $expected_integration) unit=$UNIT_RESULT (expected $expected_unit)" exit 1 fi elif [ "$PYTHON_CHANGED" = "false" ]; then @@ -573,7 +581,7 @@ jobs: py-combine-coverage: needs: [changes, py-unit-tests, py-integration-tests] - if: ${{ always() && inputs.run-coverage && needs.changes.outputs.python == 'true' && needs.py-unit-tests.result == 'success' && needs.py-integration-tests.result == 'success' }} + if: ${{ always() && inputs.run-coverage && needs.changes.outputs.python == 'true' && needs.py-unit-tests.result == 'success' && contains(fromJSON('["success", "skipped"]'), needs.py-integration-tests.result) }} runs-on: ubuntu-latest timeout-minutes: 10 continue-on-error: true @@ -611,6 +619,7 @@ jobs: - name: Prepare coverage files run: | cd ingestion + shopt -s nullglob [ -f coverage-data/coverage-unit/.coverage ] && mv coverage-data/coverage-unit/.coverage .coverage.unit for dir in coverage-data/coverage-integration-*/; do shard=$(basename "$dir" | sed 's/coverage-integration-//') diff --git a/skills/pr-checklist/SKILL.md b/skills/pr-checklist/SKILL.md index 558dd1ef973c..88691323fad0 100644 --- a/skills/pr-checklist/SKILL.md +++ b/skills/pr-checklist/SKILL.md @@ -83,13 +83,36 @@ mvn jacoco:report -pl openmetadata-service mvn test -pl openmetadata-integration-tests -Dtest= ``` -**Ingestion (Python):** +**Ingestion (Python):** PR checks run only the unit tests (`py-tests` → "Unit Tests & Static +Checks"); `tests/integration/` runs **only in the merge queue**. So if the diff touches `ingestion/`, +you MUST run every unit and integration test that covers a changed file locally before opening the PR. +An integration break you skip here first shows up as a merge-queue ejection. + +List those tests: the changed test files, plus every test that imports a changed `src/metadata` module: ```bash -source env/bin/activate cd ingestion -make unit_ingestion_dev_env -python -m pytest tests/unit// --cov=metadata. --cov-report=term-missing +changed=$(git diff --name-only --diff-filter=d origin/main...HEAD -- . | sed 's|^ingestion/||') +{ + grep -E '^tests/(unit|integration)/.*test_[^/]*\.py$' <<<"$changed" + for f in $(grep -E '^src/metadata/.*\.py$' <<<"$changed"); do + mod=$(sed -E 's|^src/||; s|/__init__\.py$||; s|\.py$||; s|/|.|g' <<<"$f") + grep -rlE --include='*.py' "${mod//./\\.}([^a-zA-Z0-9_]|$)" tests/unit tests/integration + done +} | sort -u > /tmp/affected-tests.txt +``` +This finds `from metadata.x.y import z`. It misses `from metadata.x import y`, so also add the +connector's `tests/integration//` directory when you change a connector. + +Run them. Integration tests need a local server (`./docker/run_local_docker.sh -m no-ui -i false`) and Docker, for testcontainers: +```bash +source ../env/bin/activate +grep '^tests/unit/' /tmp/affected-tests.txt | xargs -r python -m pytest -n auto --cov=metadata --cov-report=term-missing +grep '^tests/integration/' /tmp/affected-tests.txt | xargs -r python -m pytest ``` +Put the commands you ran and their pass/fail counts in the PR body, under "Unit tests" and +"Ingestion integration tests". If the list is very large (you changed a shared module like +`metadata/utils/`), run the full unit suite with `nox --no-venv -s unit-tests`. Then run the +integration directories for the connectors you touched, and say in the PR body that you ran a subset. **Frontend unit tests (Jest):** ```bash @@ -165,6 +188,7 @@ Refuse to open the PR if any of these are missing — surface them to the user i - [ ] Tests section lists actual files and coverage numbers (not placeholders) - [ ] UI changes have a screen recording attached or marked as TODO with the PR opened as draft - [ ] Manual test steps are concrete and reproducible +- [ ] `ingestion/` changes: affected unit **and** integration tests were run locally (Step 3), with results in the PR body - [ ] Cross-layer checks for the change type pass (`make generate`, `mvn spotless:apply`, `yarn lint`, etc.) ## Common Gaps to Watch For