Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Run CI on the top of a PR stack, not just the base (#83715)

Ryan Laurie5cc9f59ecb2e
diff --git a/.github/actions/create-test-plan/action.yml b/.github/actions/create-test-plan/action.yml
index 20d5285a2f2..54dabd7887a 100644
--- a/.github/actions/create-test-plan/action.yml
+++ b/.github/actions/create-test-plan/action.yml
@@ -2,6 +2,10 @@ name: Create frontend test plan
description: Compute the affected-tests plan for the changed files.
inputs:
+ diff-base:
+ description: The test gate's `diff-base`, the commit to diff against instead of the PR's base.
+ required: false
+ default: ''
stats-url:
description: Endpoint that stores the affected-tests stats row.
required: false
@@ -24,7 +28,9 @@ runs:
id: changes
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
with:
- token: ${{ github.token }}
+ # An empty token switches paths-filter to git, which is the only way to honor `base`.
+ token: ${{ inputs.diff-base == '' && github.token || '' }}
+ base: ${{ inputs.diff-base }}
list-files: csv
filters: .github/file-paths.yaml
- name: Prepare front-end environment
diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml
index 340dc63c3e6..2b6c83be1be 100644
--- a/.github/workflows/backend.yml
+++ b/.github/workflows/backend.yml
@@ -46,7 +46,9 @@ jobs:
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: static_viz
with:
- token: ${{ github.token }}
+ # An empty token switches paths-filter to git, which is the only way to honor `base`.
+ token: ${{ needs.gate.outputs.diff-base == '' && github.token || '' }}
+ base: ${{ needs.gate.outputs.diff-base }}
filters: .github/static-viz-sources.yaml
project-checks:
@@ -211,7 +213,7 @@ jobs:
- name: Compute changed test namespaces
id: changed
env:
- BASE_SHA: ${{ github.event.pull_request.base.sha }}
+ BASE_SHA: ${{ needs.gate.outputs.diff-base || github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
set -euo pipefail
diff --git a/.github/workflows/drivers.yml b/.github/workflows/drivers.yml
index 96981067b0a..1f0ba65922c 100644
--- a/.github/workflows/drivers.yml
+++ b/.github/workflows/drivers.yml
@@ -59,9 +59,17 @@ jobs:
uses: ./.github/actions/prepare-backend
- name: Fetch base branch
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref != ''
+ env:
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
+ DIFF_BASE: ${{ needs.gate.outputs.diff-base }}
run: |
- # Fetch the base branch to ensure its history is available for diffing
- git fetch --depth=1 origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
+ # Fetch what we diff against so its tree is available: the gate's diff-base on the top of
+ # a stack, the base branch otherwise.
+ if [ -n "$DIFF_BASE" ]; then
+ git fetch --depth=1 origin "$DIFF_BASE"
+ else
+ git fetch --depth=1 origin "$BASE_REF:$BASE_REF"
+ fi
- name: Determine which drivers should run
id: driver-decisions
run: |
@@ -83,7 +91,7 @@ jobs:
# Second call: output only key=value lines for GITHUB_OUTPUT
./bin/mage -driver-decisions "${MAGE_ARGS[@]}" --github-output-only >> "$GITHUB_OUTPUT"
env:
- BASE_REF: ${{ github.event.pull_request.base.ref || github.ref_name }}
+ BASE_REF: ${{ needs.gate.outputs.diff-base || github.event.pull_request.base.ref || github.ref_name }}
FORCE_RUN: ${{ needs.gate.outputs.force-run == 'true' }}
shell: bash
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index 6ec114810a0..a4e01aa8615 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -43,6 +43,7 @@ jobs:
id: compute
uses: ./.github/actions/create-test-plan
with:
+ diff-base: ${{ needs.gate.outputs.diff-base }}
stats-url: ${{ secrets.ENG_STATS_URL }}
stats-api-key: ${{ secrets.ENG_STATS_API_KEY }}
diff --git a/.github/workflows/test.gate.yml b/.github/workflows/test.gate.yml
index f8f6805fb5e..a3f861ae5be 100644
--- a/.github/workflows/test.gate.yml
+++ b/.github/workflows/test.gate.yml
@@ -6,9 +6,12 @@ name: Test gate
# `force-run` and `force-skip` are global overrides; `defer` hands the decision
# to the paths filter, which is the only path that pays for a checkout.
#
-# Only the lowest unmerged PR of a stack runs CI: it is the one whose base ref
-# is the stack base. Every PR above it is force-skipped and gets tested once it
-# reaches the bottom of the stack.
+# In a stack of PRs, only the ends run CI: the lowest unmerged PR (the one whose
+# base ref is the stack base) and the top PR (the one at the last position).
+# Every PR in between is force-skipped and gets tested once it reaches the
+# bottom of the stack, unless it carries the `ci:run-all` label. The top diffs
+# against `diff-base`, where the stack forked from its base, so the whole stack
+# decides what runs and not just the top PR's own slice.
on:
workflow_call:
inputs:
@@ -40,6 +43,12 @@ on:
verdict:
description: force-run, force-skip, or defer.
value: ${{ jobs.should-run.outputs.verdict }}
+ diff-base:
+ description: >-
+ The commit to diff against instead of the PR's own base: set only on the top PR of a
+ stack, to where the stack forked from its base. Callers that narrow by diff should use it
+ when it is set.
+ value: ${{ jobs.should-run.outputs.diff-base }}
jobs:
should-run:
@@ -49,6 +58,7 @@ jobs:
outputs:
verdict: ${{ steps.decide.outputs.verdict }}
filters: ${{ steps.decide.outputs.filters }}
+ diff-base: ${{ steps.diff-base.outputs.sha }}
steps:
- name: Decide
id: decide
@@ -59,12 +69,36 @@ jobs:
${{ (github.ref_name == 'master' || startsWith(github.ref_name, 'release-x.')) && 'force-run'
|| contains(github.event.pull_request.labels.*.name, 'ci:run-all') && 'force-run'
|| contains(github.event.pull_request.labels.*.name, 'ci:skip') && 'force-skip'
- || (github.event.pull_request.stack != null && github.event.pull_request.stack.base.ref != github.event.pull_request.base.ref) && 'force-skip'
+ || (github.event.pull_request.stack != null
+ && github.event.pull_request.stack.base.ref != github.event.pull_request.base.ref
+ && github.event.pull_request.stack.position != github.event.pull_request.stack.size) && 'force-skip'
|| 'defer' }}
run: |
echo "verdict=$VERDICT" | tee -a "$GITHUB_OUTPUT"
# Echoed back as JSON so a force-run can report every requested filter as matched.
echo "filters=$(jq -Rc 'split("[,\\s]+";"") | map(select(length > 0))' <<< "$FILTERS")" | tee -a "$GITHUB_OUTPUT"
+ # A stacked PR that defers is the bottom or the top, and only the top has a base ref other
+ # than the stack's. The merge base, not the stack base's SHA, so commits that landed on the
+ # base after the stack last synced don't count as the stack's changes.
+ - name: Find where the stack forked from its base
+ id: diff-base
+ if: >-
+ ${{ steps.decide.outputs.verdict == 'defer'
+ && github.event.pull_request.stack != null
+ && github.event.pull_request.stack.base.ref != github.event.pull_request.base.ref }}
+ uses: actions/github-script@v9
+ env:
+ STACK_BASE_SHA: ${{ github.event.pull_request.stack.base.sha }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ with:
+ script: | # js
+ const { data } = await github.rest.repos.compareCommitsWithBasehead({
+ ...context.repo,
+ basehead: `${process.env.STACK_BASE_SHA}...${process.env.HEAD_SHA}`,
+ per_page: 1,
+ });
+ core.info(`diff-base: ${data.merge_base_commit.sha}`);
+ core.setOutput('sha', data.merge_base_commit.sha);
files-changed:
name: Detect changed files
@@ -87,7 +121,10 @@ jobs:
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: changes
with:
- token: ${{ github.token }}
+ # The API only lists the PR's own files, so a `diff-base` needs git, which an empty token
+ # switches paths-filter to. It fetches the commit itself.
+ token: ${{ needs.should-run.outputs.diff-base == '' && github.token || '' }}
+ base: ${{ needs.should-run.outputs.diff-base }}
filters: .github/file-paths.yaml
- name: Match the diff against the requested filters
id: match