The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Unify build logic in PR env and AI benchmarks (#78534)
lbrdnkf76865955203
diff --git a/.github/workflows/ai-benchmark.yml b/.github/workflows/ai-benchmark.ymlindex e56639ecf15..f13123428bc 100644--- a/.github/workflows/ai-benchmark.yml+++ b/.github/workflows/ai-benchmark.yml@@ -1,5 +1,5 @@name: AI Benchmark-run-name: "dispatch evals · ${{ github.event_name == 'pull_request' && format('smoke PR#{0}', github.event.pull_request.number) || (inputs.pr != '' && format('PR#{0}', inputs.pr) || (inputs.ref != '' && inputs.ref || 'master')) }}"+run-name: "dispatch evals · ${{ github.event_name == 'pull_request' && format('smoke PR#{0}', github.event.pull_request.number) || (inputs.ref != '' && inputs.ref || (inputs.pr != '' && format('PR#{0}', inputs.pr) || 'master')) }}"on:pull_request:@@ -11,7 +11,7 @@ on:required: falsedefault: ""ref:- description: "Metabase ref"+ description: "Metabase branch, tag or sha (resolved to a full sha; overrides the PR head, and must sit on the PR's branch when both are given)"required: falsedefault: ""scope:@@ -74,19 +74,85 @@ jobs:const { data } = await github.rest.issues.createComment({ owner, repo, issue_number, body });core.setOutput('comment_id', String(data.id));- uberjar:- needs: [announce]+ resolve:+ # Collapse the dispatch inputs into the one full sha everything downstream needs: it keys the+ # uberjar artifact, tags the ECR image, and tells eval-run which commit was measured. `pr` was+ # not consulted at all before, so `pr: 12345` built the tip of whatever branch the run was+ # launched from and then reported the result against the PR.+ if: github.event_name == 'workflow_dispatch'+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ timeout-minutes: 5+ permissions:+ contents: read+ pull-requests: read+ outputs:+ sha: ${{ steps.sha.outputs.sha }}+ steps:+ - name: Resolve pr/ref to a full commit sha+ id: sha+ env:+ GH_TOKEN: ${{ github.token }}+ PR: ${{ inputs.pr }}+ REF: ${{ inputs.ref }}+ DEFAULT_SHA: ${{ github.sha }}+ run: |+ set -euo pipefail+ # `ref` wins over `pr`, matching evals' eval-run.yml, which this dispatches into — same two+ # inputs with opposite precedence in chained workflows would be a trap. eval-run also+ # rejects a ref that doesn't sit on the PR's branch; that check stays there rather than+ # being duplicated here.+ if [[ -n "$REF" ]]; then+ # `ref` accepts a branch or tag; fetch-artifact and the image tag need a full sha.+ SHA=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${REF}" --jq .sha)+ echo "ref ${REF} -> ${SHA}"+ elif [[ -n "$PR" ]]; then+ SHA=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR}" --jq .head.sha)+ echo "PR #${PR} head -> ${SHA}"+ else+ SHA="$DEFAULT_SHA"+ echo "neither pr nor ref given; using this run's commit -> ${SHA}"+ fi+ if [[ ! "$SHA" =~ ^[0-9a-f]{40}$ ]]; then+ echo "::error::could not resolve a full commit sha (got '${SHA}')"+ exit 1+ fi+ echo "sha=${SHA}" >> "$GITHUB_OUTPUT"++ image:+ needs: [resolve]+ # `resolve` is workflow_dispatch-only, so tolerate it being skipped. The label guard is not+ # optional: the trigger is `pull_request: [labeled]` with no filter of its own, so without it+ # any label on any same-repo PR builds ee+oss and pushes to ECR — and since announce/smoke/+ # finalize all skip in that case, a failure shows up as a bare red check with nothing+ # explaining it.if: >-- github.event_name == 'pull_request'- && github.event.label.name == 'evals/smoke'- && github.event.pull_request.head.repo.full_name == github.repository- uses: ./.github/workflows/uberjar.yml- secrets: inherit+ !cancelled()+ && (needs.resolve.result == 'success' || needs.resolve.result == 'skipped')+ && (github.event_name == 'workflow_dispatch'+ || (github.event_name == 'pull_request'+ && github.event.label.name == 'evals/smoke'+ && github.event.pull_request.head.repo.full_name == github.repository))+ uses: ./.github/workflows/build-private-ee-docker-image.yml+ secrets:+ PR_ENV_IAM_ROLE: ${{ secrets.PR_ENV_IAM_ROLE }}+ PR_ENV_AWS_ACCOUNT_ID: ${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}+ with:+ # Empty on the label path on purpose — the image workflow then falls back to the PR head,+ # which is the artifact run-tests has already built and cached under that sha.+ commit: ${{ needs.resolve.outputs.sha }}smoke:- needs: [announce, uberjar]+ needs: [announce, image]+ # `!cancelled()` is load-bearing, not decoration: on the label path `resolve` is skipped by+ # design, and `image` only runs at all because it opts back in with its own `!cancelled()`.+ # GitHub propagates that skip *transitively*, so a plain boolean `if` here — carrying the+ # implicit `success()` — skips smoke even though image succeeded and the image is in ECR.+ # Opting out of the implicit check means the needs' results have to be asserted by hand.if: >-- github.event_name == 'pull_request'+ !cancelled()+ && needs.announce.result == 'success'+ && needs.image.result == 'success'+ && github.event_name == 'pull_request'&& github.event.label.name == 'evals/smoke'&& github.event.pull_request.head.repo.full_name == github.repositoryruns-on: ${{ vars.SLIM_RUNNER_KEY }}@@ -114,14 +180,14 @@ jobs:finalize:# If the build or dispatch fell over, eval-run never took over the comment — leave a# failure verdict instead of a comment stuck at "building the image…".- needs: [announce, uberjar, smoke]+ needs: [announce, image, smoke]if: always() && needs.announce.result == 'success' && needs.smoke.result != 'success'runs-on: ${{ vars.SLIM_RUNNER_KEY }}timeout-minutes: 5env:COMMENT_ID: ${{ needs.announce.outputs.comment_id }}SMOKE_RESULT: ${{ needs.smoke.result }}- UBERJAR_RESULT: ${{ needs.uberjar.result }}+ IMAGE_RESULT: ${{ needs.image.result }}steps:- name: Comment (build/dispatch failed)uses: actions/github-script@v9@@ -130,7 +196,7 @@ jobs:script: |const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;// A concurrency-cancelled retrigger lands here too; don't stamp it as an infra failure.- const cancelled = [process.env.SMOKE_RESULT, process.env.UBERJAR_RESULT].includes('cancelled');+ const cancelled = [process.env.SMOKE_RESULT, process.env.IMAGE_RESULT].includes('cancelled');const body = cancelled? `🤖 **Evals smoke** — ⚪ cancelled before evals started ([logs](${runUrl}))`: `🤖 **Evals smoke** — ❌ build or dispatch failed before evals started ([logs](${runUrl}))`;@@ -150,6 +216,10 @@ jobs:}).catch(() => {});dispatch:+ needs: [resolve, image]+ # Deliberately no `always()`: benchmarking without the image this run was supposed to produce+ # would measure a stale build or nothing at all. A failed `image` fails the run, which is the+ # signal here — unlike the PR path there is no comment for `finalize` to stamp.if: github.event_name == 'workflow_dispatch'runs-on: ${{ vars.SLIM_RUNNER_KEY }}timeout-minutes: 5@@ -159,7 +229,8 @@ jobs:GH_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}EVALS_BRANCH: ${{ github.event.inputs.evals_branch }}PR: ${{ inputs.pr }}- REF: ${{ inputs.ref }}+ # The sha the image was actually built and tagged with, not the raw `ref` input.+ REF: ${{ needs.resolve.outputs.sha }}SCOPE: ${{ inputs.scope }}SAMPLE: ${{ inputs.sample }}run: |diff --git a/.github/workflows/build-private-ee-docker-image.yml b/.github/workflows/build-private-ee-docker-image.ymlnew file mode 100644index 00000000000..b417b795a9d--- /dev/null+++ b/.github/workflows/build-private-ee-docker-image.yml@@ -0,0 +1,140 @@+name: Build & push private Metabase Docker image++# Builds the ee uberjar for a commit and pushes it to the private ECR repo, tagged with that+# commit's full SHA. Callers get the tag back as an output.+#+# The tag is per-commit rather than per-PR, so a PR leaves one image behind per pushed commit.+# Nothing in this repo prunes them — retention is whatever lifecycle policy the ECR repo carries.++on:+ workflow_dispatch:+ inputs:+ commit:+ description: Full sha of commit to build, optional+ workflow_call:+ inputs:+ commit:+ description: Full sha of commit to build, optional+ type: string++ secrets:+ PR_ENV_IAM_ROLE:+ description: Role assumed via OIDC to reach ECR+ required: true+ PR_ENV_AWS_ACCOUNT_ID:+ description: Account hosting the private ECR registry+ required: true++ outputs:+ tag:+ description: "Image tag (the commit SHA)"+ value: ${{ jobs.dockerize.outputs.tag }}++# Keyed on the calling workflow as well as the commit: pr-env and ai-benchmark both land here, and+# a shared group lets a re-label on one evict the other's queued run (`cancel-in-progress: false`+# still drops a *pending* run when a third queues). Before the extraction the two paths were+# independent; this keeps them that way.+concurrency:+ group: build-private-ee-docker-image-${{ github.workflow }}-${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}+ cancel-in-progress: false++permissions:+ contents: read+ actions: read # fetch-artifact reads the artifact API++jobs:++ build:+ if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository+ uses: ./.github/workflows/uberjar.yml+ with:+ # Pass through only an *explicit* commit and let uberjar apply its own event fallback.+ # Resolving head.sha here instead would pin the PR path's checkout to the head commit, while+ # run-tests' uberjar keeps building the merge ref — both upload under the same+ # `metabase-ee-<head.sha>-uberjar` name, so whichever raced first would decide what the tag+ # actually contains.+ commit: ${{ inputs.commit }}++ dockerize:+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ needs: [build]+ if: needs.build.result == 'success'+ timeout-minutes: 60+ permissions:+ id-token: write+ contents: read+ actions: read+ outputs:+ tag: ${{ steps.meta.outputs.tag }}+ steps:+ # Deliberately the workflow's own revision, not `inputs.commit`: this checkout is where+ # `./.github/actions/fetch-artifact` below comes from, and pinning it to the target commit+ # would run that commit's copy of the action instead of this one. Nothing else in this job+ # reads the tree.+ - name: Checkout source code+ uses: actions/checkout@v6+ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6.1.1+ with:+ role-to-assume: ${{ secrets.PR_ENV_IAM_ROLE }}+ role-session-name: GitHub_to_AWS_via_FederatedOIDC+ aws-region: us-east-1+ - name: Login to Amazon ECR+ uses: aws-actions/amazon-ecr-login@183a1442edf41672e66566b7fc560e297a290896 # v2+ with:+ registries: "${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}"+ - name: Compute image tag+ id: meta+ env:+ SHA: ${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}+ run: echo "tag=${SHA}" >> "$GITHUB_OUTPUT"+ - name: Check whether image already exists+ id: exists+ env:+ TAG: ${{ steps.meta.outputs.tag }}+ # Same registry the push below targets — the assumed role's default registry is not+ # necessarily this account, and querying the wrong one always reports "not found".+ REGISTRY_ID: ${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}+ run: |+ set +e+ OUT=$(aws ecr describe-images \+ --registry-id "${REGISTRY_ID}" \+ --repository-name metabase-enterprise \+ --image-ids imageTag="${TAG}" 2>&1)+ STATUS=$?+ set -e++ if [[ "${STATUS}" -eq 0 ]]; then+ echo "Image already present for ${TAG}; reusing it."+ echo "found=true" >> "$GITHUB_OUTPUT"+ elif grep -q 'ImageNotFoundException' <<< "${OUT}"; then+ echo "No image for ${TAG}; building."+ echo "found=false" >> "$GITHUB_OUTPUT"+ else+ # Anything else (missing ecr:DescribeImages, wrong registry, throttling) is+ # indistinguishable from "not found" if we swallow it, and we'd rebuild forever+ # without ever saying why. Rebuilding is still the safe answer, so warn and go on.+ echo "${OUT}" >&2+ echo "::warning::Could not determine whether ${TAG} exists in ECR (exit ${STATUS}); building unconditionally."+ echo "found=false" >> "$GITHUB_OUTPUT"+ fi+ - name: Retrieve uberjar artifact for ee+ if: steps.exists.outputs.found == 'false'+ uses: ./.github/actions/fetch-artifact+ with:+ commit: ${{ steps.meta.outputs.tag }}+ edition: ee+ extract-path: "target/uberjar"+ output-name: "metabase.jar"+ - name: Move uberjar to bin/docker+ if: steps.exists.outputs.found == 'false'+ run: mv target/uberjar/metabase.jar bin/docker/metabase.jar+ - name: Build container+ if: steps.exists.outputs.found == 'false'+ uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0+ with:+ context: bin/docker/+ platforms: linux/amd64+ network: host+ tags: ${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com/metabase-enterprise:${{ steps.meta.outputs.tag }}+ push: truediff --git a/.github/workflows/pr-env.yml b/.github/workflows/pr-env.ymlindex 4baf33131c4..154ce0fab55 100644--- a/.github/workflows/pr-env.yml+++ b/.github/workflows/pr-env.yml@@ -21,46 +21,12 @@ on:default: falsejobs:build:- runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}if: github.event.pull_request.head.repo.full_name == github.repositoryname: Build Metabase Docker image- timeout-minutes: 60- permissions:- id-token: write- contents: read- actions: read- steps:- - name: Checkout source code- uses: actions/checkout@v6- - name: Configure AWS credentials- uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6.1.1- with:- role-to-assume: ${{ secrets.PR_ENV_IAM_ROLE }}- role-session-name: GitHub_to_AWS_via_FederatedOIDC- aws-region: us-east-1- - name: Login to Amazon ECR- uses: aws-actions/amazon-ecr-login@183a1442edf41672e66566b7fc560e297a290896 # v2- with:- registries: "${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}"- - name: Retrieve uberjar artifact for ee- uses: ./.github/actions/fetch-artifact- with:- commit: ${{ github.event.pull_request.head.sha || github.sha }}- edition: ee- extract-path: "target/uberjar"- output-name: "metabase.jar"- - name: Move uberjar to bin/docker- run: |- jar xf target/uberjar/metabase.jar- mv target/uberjar/metabase.jar bin/docker/metabase.jar- - name: Build container- uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0- with:- context: bin/docker/- platforms: linux/amd64- network: host- tags: ${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com/metabase-enterprise:pr${{ github.event.number }}- push: true+ uses: ./.github/workflows/build-private-ee-docker-image.yml+ secrets:+ PR_ENV_IAM_ROLE: ${{ secrets.PR_ENV_IAM_ROLE }}+ PR_ENV_AWS_ACCOUNT_ID: ${{ secrets.PR_ENV_AWS_ACCOUNT_ID }}deploy_pr:needs: [build]runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}@@ -228,7 +194,7 @@ jobs:input: ./metabase.yml.tmploutput: ./metabase.ymlenv:- IMAGE_TAG: pr${{ github.event.number }}+ IMAGE_TAG: ${{ needs.build.outputs.tag }}PR_NUMBER: ${{ github.event.number }}MB_PREMIUM_EMBEDDING_TOKEN: ${{ secrets.PR_ENV_MB_PREMIUM_EMBEDDING_TOKEN }}SHA: ${{ github.event.pull_request.head.sha || github.sha }}@@ -289,7 +255,7 @@ jobs:input: ./values.yaml.tmploutput: ./values.yamlenv:- IMAGE_TAG: pr${{ github.event.number }}+ IMAGE_TAG: ${{ needs.build.outputs.tag }}PR_NUMBER: ${{ github.event.number }}MB_PREMIUM_EMBEDDING_TOKEN: ${{ secrets.PR_ENV_MB_PREMIUM_EMBEDDING_TOKEN }}SHA: ${{ github.event.pull_request.head.sha || github.sha }}diff --git a/.github/workflows/uberjar.yml b/.github/workflows/uberjar.ymlindex f486f3ff1c6..84fc4d5f65d 100644--- a/.github/workflows/uberjar.yml+++ b/.github/workflows/uberjar.yml@@ -4,7 +4,7 @@ name: Build Uberjar# or automatically for the listed branchesconcurrency:- group: uberjar-${{ github.event.inputs.commit || github.event.pull_request.head.sha || github.sha }}+ group: uberjar-${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}cancel-in-progress: falseon:@@ -29,6 +29,10 @@ on:commit:description: "Optional full-length commit SHA-1 hash"workflow_call:+ inputs:+ commit:+ description: "Optional full-length commit SHA-1 hash"+ type: stringjobs:check-existing-artifacts:@@ -46,7 +50,7 @@ jobs:continue-on-error: trueuses: ./.github/actions/fetch-artifactwith:- commit: ${{ github.event.inputs.commit || github.event.pull_request.head.sha || github.sha }}+ commit: ${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}edition: eeoutput-name: metabase-ee.jar@@ -55,7 +59,7 @@ jobs:continue-on-error: trueuses: ./.github/actions/fetch-artifactwith:- commit: ${{ github.event.inputs.commit || github.event.pull_request.head.sha || github.sha }}+ commit: ${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}edition: ossoutput-name: metabase-oss.jar@@ -135,7 +139,7 @@ jobs:- name: Check out the codeuses: actions/checkout@v6with:- ref: ${{ github.event.inputs.commit }}+ ref: ${{ inputs.commit }}- name: Prepare front-end environmentuses: ./.github/actions/prepare-frontendwith:@@ -151,7 +155,7 @@ jobs:continue-on-error: trueuses: actions/upload-artifact@v7with:- name: metabase-bundle-stats-${{ matrix.edition }}-${{ github.event.inputs.commit || github.event.pull_request.head.sha || github.sha }}+ name: metabase-bundle-stats-${{ matrix.edition }}-${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}path: target/bundle-statsif-no-files-found: warn- name: Mark with the commit hash@@ -165,7 +169,7 @@ jobs:with:# Same key the artifact lookups use, so a build for an explicitly dispatched commit# uploads where `check-existing-artifacts` and `check-jar-health` go looking for it.- name: metabase-${{ matrix.edition }}-${{ github.event.inputs.commit || github.event.pull_request.head.sha || github.sha }}-uberjar+ name: metabase-${{ matrix.edition }}-${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}-uberjarpath: |./target/uberjar/metabase.jar./COMMIT-ID@@ -200,7 +204,7 @@ jobs:- name: Retrieve uberjar artifactuses: ./.github/actions/fetch-artifactwith:- commit: ${{ github.event.inputs.commit || github.event.pull_request.head.sha || github.sha }}+ commit: ${{ inputs.commit || github.event.pull_request.head.sha || github.sha }}edition: ${{ matrix.edition }}- name: Verify license files are present in uberjarrun: |