Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[MINOR] fix(ci): Support trusted Fork CI for release branches (#15080)

Qi Yu78d2f2d1ddf7
diff --git a/.github/scripts/fork-ci-status.cjs b/.github/scripts/fork-ci-status.cjs
index 3bf8d192d4..63bfbbc2d3 100644
--- a/.github/scripts/fork-ci-status.cjs
+++ b/.github/scripts/fork-ci-status.cjs
@@ -353,11 +353,11 @@ function createService(github, { readWorkflow = sha => github.rest.repos.getCont
: evaluateSuites(jobs, await suitesAt(base), selected.trusted);
}
if (selected.trusted && result.conclusion === 'success' && await acceptedBase(pr, base) !== base) {
- result = requiredAction('Trusted CI tested a commit outside the current base branch. Dispatch trusted Fork CI again from the current default branch.');
+ result = requiredAction('Trusted CI tested a commit outside the current base branch. Dispatch trusted Fork CI again from the current upstream PR target branch.');
}
if (!selected.trusted && !sameDefinitions) {
const note = 'CI workflow/action/script definitions or branch protection differ from the base. ' +
- 'After reviewing these changes, a committer must dispatch Fork CI from the current upstream default branch with this PR number.';
+ 'After reviewing these changes, a committer must dispatch Fork CI from the current upstream PR target branch with this PR number.';
// Approval of CI edits is separate from execution progress. Never turn a running fork
// into a completed error, or hide an actual failure behind the trust requirement.
result = needsSuiteChecks
diff --git a/.github/scripts/resolve-fork-ci.cjs b/.github/scripts/resolve-fork-ci.cjs
index a1057bf600..ab61b603a5 100644
--- a/.github/scripts/resolve-fork-ci.cjs
+++ b/.github/scripts/resolve-fork-ci.cjs
@@ -32,13 +32,15 @@ async function resolve({ github, context, core }) {
const { data: pr } = await github.rest.pulls.get({ ...context.repo, pull_number: Number(number) });
if (pr.state !== 'open' || !pr.head.repo) throw new Error('The pull request must be open with an existing head repository.');
baseRef = pr.base.ref;
- if (baseRef !== context.payload.repository.default_branch || context.ref !== `refs/heads/${baseRef}`) {
- throw new Error('Dispatch the trusted workflow from the current default branch; release branches use their own CI.');
+ // Use only reviewed upstream default/release branch workflows, never a PR or feature ref.
+ const supportedTarget = baseRef === context.payload.repository.default_branch || /^branch-\d+\.\d+$/.test(baseRef);
+ if (!supportedTarget || context.ref !== `refs/heads/${baseRef}`) {
+ throw new Error(`Dispatch trusted Fork CI from the current upstream PR target branch (${baseRef}); only the default branch and branch-X.Y releases are supported.`);
}
// Pull requests retain an older base.sha after the base branch advances.
const { data: base } = await github.rest.repos.getBranch({ ...context.repo, branch: baseRef });
if (context.sha !== base.commit.sha) {
- throw new Error('Dispatch the trusted workflow from the current default branch; release branches use their own CI.');
+ throw new Error(`Dispatch trusted Fork CI from the current upstream PR target branch (${baseRef}); only the default branch and branch-X.Y releases are supported.`);
}
headSha = pr.head.sha;
headRepository = pr.head.repo.full_name;
diff --git a/.github/scripts/tests/fork-ci.test.cjs b/.github/scripts/tests/fork-ci.test.cjs
index ec3182c40f..267c614c7c 100644
--- a/.github/scripts/tests/fork-ci.test.cjs
+++ b/.github/scripts/tests/fork-ci.test.cjs
@@ -215,7 +215,7 @@ test('trusted dispatch rejects an arbitrary ref or a non-upstream repository', a
const ctx = context('fork/repo');ctx.eventName = 'workflow_dispatch';ctx.payload.inputs = { 'pull-request': '7' };
await assert.rejects(resolve({ context: ctx, core: coreFor({}), github: {} }), /apache/);
const upstream = context('apache/gravitino');upstream.eventName = 'workflow_dispatch';upstream.payload.inputs = { 'pull-request': '7' };
- await assert.rejects(resolve({ context: upstream, core: coreFor({}), github: { rest: { pulls: { get: async () => ({ data: pr() }) } } } }), /current default branch/);
+ await assert.rejects(resolve({ context: upstream, core: coreFor({}), github: { rest: { pulls: { get: async () => ({ data: pr() }) } } } }), /current upstream PR target branch/);
});
test('trusted dispatch resolves the current default branch after the PR base snapshot ages', async () => {
@@ -228,7 +228,60 @@ test('trusted dispatch resolves the current default branch after the PR base sna
assert.equal(output['base-sha'], C);
assert.equal(output['head-sha'], A);
ctx.sha = B;
- await assert.rejects(resolve({ context: ctx, core: coreFor({}), github }), /current default branch/);
+ await assert.rejects(resolve({ context: ctx, core: coreFor({}), github }), /current upstream PR target branch/);
+});
+
+test('trusted release dispatch freezes the current target tip and can satisfy the publisher', async () => {
+ for (const branch of ['branch-1.3', 'branch-2.0']) {
+ const p = pr(); p.base.ref = branch;
+ const ctx = context('apache/gravitino'); ctx.eventName = 'workflow_dispatch';
+ ctx.ref = `refs/heads/${branch}`; ctx.sha = C; ctx.payload.inputs = { 'pull-request': '7' };
+ const output = {};
+ await resolve({ context: ctx, core: coreFor(output), github: { rest: {
+ pulls: { get: async () => ({ data: p }) },
+ repos: { getBranch: async args => {
+ assert.equal(args.branch, branch); return { data: { commit: { sha: C } } };
+ } }
+ } } });
+ assert.deepEqual(output, { 'base-ref': branch, 'base-sha': C, 'head-sha': A,
+ 'head-repository': 'fork/repo', sync: 'true', valid: 'true' });
+ const tested = { ...p, base: { ref: output['base-ref'], sha: output['base-sha'] } };
+ const github = serviceMock({ changed: true, trusted: true, trustedSha: C,
+ forkJobs: jobs(p), trustedJobs: jobs(tested) });
+ github.rest.repos.compareCommitsWithBasehead = async args => {
+ assert.equal(args.basehead, `${C}...${branch}`); return { data: { status: 'ahead' } };
+ };
+ const list = github.rest.actions.listWorkflowRuns;
+ github.rest.actions.listWorkflowRuns = async args => {
+ const response = await list(args);
+ if (args.event === 'workflow_dispatch') {
+ assert.equal(args.branch, branch);
+ response.data.workflow_runs[0].head_branch = branch;
+ }
+ return response;
+ };
+ const mirrored = await createService(github).mirror(p);
+ assert.equal(mirrored.trusted, true);
+ assert.equal(mirrored.result.conclusion, 'success');
+ assert.equal(mirrored.base, C);
+ }
+});
+
+test('trusted release dispatch rejects mismatched refs, stale tips and arbitrary targets before output', async () => {
+ for (const scenario of ['main-ref', 'other-release', 'tag', 'stale-tip', 'feature-target']) {
+ const p = pr(); p.base.ref = scenario === 'feature-target' ? 'topic' : 'branch-2.0';
+ const ctx = context('apache/gravitino'); ctx.eventName = 'workflow_dispatch';
+ ctx.payload.inputs = { 'pull-request': '7' }; ctx.sha = scenario === 'stale-tip' ? B : C;
+ ctx.ref = scenario === 'main-ref' ? 'refs/heads/main'
+ : scenario === 'other-release' ? 'refs/heads/branch-1.3'
+ : scenario === 'tag' ? 'refs/tags/branch-2.0' : `refs/heads/${p.base.ref}`;
+ const output = {};
+ await assert.rejects(resolve({ context: ctx, core: coreFor(output), github: { rest: {
+ pulls: { get: async () => ({ data: p }) },
+ repos: { getBranch: async () => ({ data: { commit: { sha: C } } }) }
+ } } }), /Dispatch/);
+ assert.deepEqual(output, {}, scenario);
+ }
});
test('trusted runs on an advanced base are found by branch and verified against their actual tested SHA', async () => {
diff --git a/.github/workflows/fork-ci.yml b/.github/workflows/fork-ci.yml
index 2ee45f792f..704c1fbfa6 100644
--- a/.github/workflows/fork-ci.yml
+++ b/.github/workflows/fork-ci.yml
@@ -25,7 +25,7 @@ on:
workflow_dispatch:
inputs:
pull-request:
- description: 'In apache/gravitino: PR to test using the reviewed default-branch workflows (committers only). In a fork: leave empty to test the selected branch.'
+ description: 'In apache/gravitino: PR to test using the reviewed workflows on its current target branch (default or branch-X.Y) (committers only). In a fork: leave empty to test the selected branch.'
required: false
type: string
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 0d2174c2af..e4ce23d101 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -137,7 +137,7 @@ Known limitations of Fork CI:
* A pull request last pushed before this migration needs an update and another push. Old runs without the tested-context metadata cannot satisfy the new check.
* Coverage comments remain available for release branches. For PRs to `main`, inspect the fork run's `build / coverage` log and `coverage-report` artifact.
* Release branches (`branch-*`) keep their own upstream CI until this change is backported.
-* CI workflow, action, helper-script or `.asf.yaml` changes cannot approve themselves. After reviewing those changes, a committer runs **Fork CI** in `apache/gravitino`, from the current default branch, and supplies the PR number. This explicit exception uses upstream runner resources, reviewed default-branch workflow definitions, a read-only token and no repository secrets; it tests the exact contributor head against the current base. The run resolves the branch's current SHA even when the PR retains an older base snapshot. A later contributor push requires a new run; an existing trusted success remains valid while its tested base stays on the same base branch, with branch protection controlling freshness.
+* CI workflow, action, helper-script or `.asf.yaml` changes cannot approve themselves. After reviewing those changes, a committer runs **Fork CI** in `apache/gravitino`, from the current PR target branch (the default branch or a `branch-X.Y` release branch), and supplies the PR number. This explicit exception uses upstream runner resources, reviewed target-branch workflow definitions, a read-only token and no repository secrets; it tests the exact contributor head against the current base. The run resolves the branch's current SHA even when the PR retains an older base snapshot. Dispatch from the target branch's current tip; another branch, a tag, or an older workflow run is rejected. Release branches need this trusted-dispatch support backported before it can be used. A later contributor push requires a new run; an existing trusted success remains valid while its tested base stays on the same base branch, with branch protection controlling freshness.
* The independent allowlist scanner downloads bounded YAML data outside its trusted checkout and never executes PR code. It reports the **ASF Allowlist Check** on every PR, including PRs that do not change `.github/`. A committer can re-run **Trusted ASF Allowlist** with the PR number.
**Fork CI** and **ASF Allowlist Check** are not required status checks, so a trusted run stuck in the shared runner queue does not block an urgent merge. Branch protection still requires an up-to-date branch and an approving review. Release-branch protection is unchanged.