Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci(review): source eng/design owners from repo variables; eng-owner clears code gate (#3904)

Cindy Zhang27a88a6cb2b5
diff --git a/.github/workflows/review-clear.yml b/.github/workflows/review-clear.yml
index 80b5121c79..9e42b5b62e 100644
--- a/.github/workflows/review-clear.yml
+++ b/.github/workflows/review-clear.yml
@@ -40,6 +40,8 @@ jobs:
steps:
- name: Clear the code gate if an entitled owner approved
uses: actions/github-script@v9
+ env:
+ ENG_OWNERS: ${{ vars.ENGOWNERS }}
with:
script: |
const { owner, repo } = context.repo;
@@ -88,24 +90,24 @@ jobs:
const headSha = full.head.sha;
const labels = full.labels.map((l) => l.name);
- // Read CODEOWNERS default owners (the `*` line), ignoring comments.
- async function codeownerHandles() {
- try {
- const { data } = await github.rest.repos.getContent({
- owner, repo, path: '.github/CODEOWNERS', ref: full.base.ref,
- });
- const text = Buffer.from(data.content, 'base64').toString('utf8');
- const star = text.split('\n').map((l) => l.trim())
- .filter((l) => !l.startsWith('#')).find((l) => l.startsWith('*'));
- return ((star || '').match(/@[A-Za-z0-9-]+/g) || []).map((h) => h.slice(1).toLowerCase());
- } catch (e) {
- core.warning(`Could not read CODEOWNERS: ${e.message}`);
- return [];
- }
+ // Entitled code approvers come from the ENGOWNERS repo variable
+ // (passed in as env above). Any eng owner's approval clears the code
+ // gate — eng owns the code, and the GitHub-native CODEOWNERS set is
+ // a subset of ENGOWNERS, so ENGOWNERS covers it. No file read / no
+ // content API, so there is nothing to 502 on. If the variable is
+ // empty/unset, DON'T clear (leave the gate as-is) and let
+ // review-signal's flag job reconcile — declining to clear is the
+ // safe direction here; an empty list is never "everyone".
+ const codeApprovers = new Set(
+ ((process.env.ENG_OWNERS || '').match(/@?[A-Za-z0-9-]+/g) || [])
+ .map((h) => h.replace(/^@/, '').toLowerCase()),
+ );
+ if (!codeApprovers.size) {
+ core.warning('ENGOWNERS variable empty/unset; not clearing (flag job will reconcile).');
+ return;
}
- const codeOwners = await codeownerHandles();
- // Did an entitled CODEOWNER approve (latest review state per user)?
+ // Did an entitled owner approve (latest review state per user)?
let codeApproved = false;
try {
const reviews = await github.paginate(github.rest.pulls.listReviews, {
@@ -117,14 +119,14 @@ jobs:
latest.set(r.user.login.toLowerCase(), r.state);
}
for (const [login, state] of latest) {
- if (state === 'APPROVED' && codeOwners.includes(login)) codeApproved = true;
+ if (state === 'APPROVED' && codeApprovers.has(login)) codeApproved = true;
}
} catch (e) {
core.warning(`Could not read reviews: ${e.message}`);
}
if (!codeApproved) {
- core.info(`PR #${prNumber}: no entitled code-owner approval; leaving gate as-is.`);
+ core.info(`PR #${prNumber}: no entitled code owner (CODEOWNER/ENGOWNER) approval; leaving gate as-is.`);
return;
}
diff --git a/.github/workflows/review-signal.yml b/.github/workflows/review-signal.yml
index 7f04b60860..f4ac2e49f7 100644
--- a/.github/workflows/review-signal.yml
+++ b/.github/workflows/review-signal.yml
@@ -41,9 +41,10 @@
# self-serve code.
#
# Uses pull_request_target so it can label / request reviewers / disable
-# auto-merge on fork PRs. It only reads the PR file LIST and repo owner files via
-# the API — it never checks out or runs PR-controlled code. Do not add checkout
-# or build steps here.
+# auto-merge on fork PRs. It reads the PR file LIST via the API and the eng/
+# design owner lists from repo VARIABLES (vars.ENGOWNERS / vars.DESIGNOWNERS) —
+# no checkout, no owner-file content API. It never checks out or runs
+# PR-controlled code. Do not add checkout or build steps here.
name: Review signal
@@ -96,6 +97,9 @@ jobs:
steps:
- name: Detect signals and route
uses: actions/github-script@v9
+ env:
+ ENG_OWNERS: ${{ vars.ENGOWNERS }}
+ DESIGN_OWNERS: ${{ vars.DESIGNOWNERS }}
with:
script: |
const { owner, repo } = context.repo;
@@ -144,34 +148,31 @@ jobs:
// and the community label entirely.
const authorIsBot = pr.user.type === 'Bot' || /\[bot\]$/.test(author);
- // --- Read owner sets from repo files at the base ref. ---
- async function handlesFrom(path, { starLineOnly = false } = {}) {
- try {
- const { data } = await github.rest.repos.getContent({
- owner, repo, path, ref: pr.base.ref,
- });
- let text = Buffer.from(data.content, 'base64').toString('utf8');
- if (starLineOnly) {
- const star = text.split('\n').map((l) => l.trim())
- .find((l) => l.startsWith('*'));
- text = star || '';
- }
- // Strip comment lines (# ...) so an @handle mentioned in a
- // file header comment is not parsed as a real owner.
- const body = text
- .split('\n')
- .filter((l) => !l.trim().startsWith('#'))
- .join('\n');
- return (body.match(/@[A-Za-z0-9-]+/g) || [])
- .map((h) => h.slice(1).toLowerCase());
- } catch (e) {
- core.warning(`Could not read ${path}: ${e.message}`);
- return [];
+ // --- Owner sets come from repo VARIABLES (vars.ENGOWNERS /
+ // vars.DESIGNOWNERS), passed in as env above. No file read, no
+ // content API — so there is nothing to 502 on. CODEOWNERS is NOT
+ // read here: it is GitHub-native and auto-requests its reviewers on
+ // every PR regardless of branch protection, which covers code
+ // review for contributor and design-owner PRs. These lists are
+ // CRITICAL: an empty/unset value would mis-bucket a real owner as a
+ // community contributor and wrongly gate them. So treat an empty
+ // owner list as a configuration error and THROW — the caller's
+ // per-PR try/catch then skips this PR, LEAVES ITS GATE UNTOUCHED
+ // (never a false success), and fails the run visibly. An unreadable
+ // owner list is never "no owners".
+ function parseHandles(text) {
+ return ((text || '').match(/@?[A-Za-z0-9-]+/g) || [])
+ .map((h) => h.replace(/^@/, '').toLowerCase());
+ }
+ function ownersFromVar(name) {
+ const handles = parseHandles(process.env[name]);
+ if (!handles.length) {
+ throw new Error(`Owner variable ${name} is empty or unset — refusing to bucket authors from an empty list.`);
}
+ return handles;
}
- const engOwners = await handlesFrom('.github/ENGOWNERS');
- const designOwners = await handlesFrom('.github/DESIGNOWNERS');
- const codeOwners = await handlesFrom('.github/CODEOWNERS', { starLineOnly: true });
+ const engOwners = ownersFromVar('ENG_OWNERS');
+ const designOwners = ownersFromVar('DESIGN_OWNERS');
const authorIsEng = engOwners.includes(author);
const authorIsDesign = designOwners.includes(author);
@@ -324,8 +325,8 @@ jobs:
// the PR's reviews here (this job runs on pull_request_target and
// workflow_dispatch, both of which work for forks) and treat a gate
// as satisfied when an entitled owner has approved:
- // code gate → a CODEOWNER approval
- // design gate → a DESIGNOWNER or CODEOWNER approval
+ // code gate → an ENGOWNER approval
+ // design gate → a DESIGNOWNER approval
// We use each reviewer's LATEST review state so a later
// CHANGES_REQUESTED/DISMISSED correctly un-satisfies it.
let codeApproved = false;
@@ -344,8 +345,12 @@ jobs:
}
for (const [login, state] of latestByUser) {
if (state !== 'APPROVED') continue;
- if (codeOwners.includes(login)) { codeApproved = true; designApproved = true; }
- else if (designOwners.includes(login)) { designApproved = true; }
+ // Code gate: any ENGOWNER approval satisfies it (eng owns the
+ // code; the CODEOWNERS subset is a subset of ENGOWNERS, so
+ // ENGOWNERS covers it). Design gate: only a DESIGNOWNER — an
+ // eng approval does NOT clear a design gate.
+ if (engOwners.includes(login)) codeApproved = true;
+ if (designOwners.includes(login)) designApproved = true;
}
} catch (e) {
core.warning(`Could not read reviews: ${e.message}`);
@@ -400,6 +405,10 @@ jobs:
if (!designGated && current.includes(DESIGN)) await dropLabel(DESIGN);
// --- Request reviewers (can't request the author; ignore 422s). ---
+ // Code review is left to GitHub-native CODEOWNERS auto-request (it
+ // requests the codeowners on every PR regardless of branch
+ // protection). We only add DESIGN owners, and only when a design
+ // gate actually fires — so design owners aren't pinged on every PR.
async function requestReviewers(handles) {
const reviewers = [...new Set(handles)].filter((h) => h !== author);
if (!reviewers.length) return;
@@ -411,7 +420,6 @@ jobs:
core.warning(`requestReviewers(${reviewers.join(',')}) failed: ${e.message}`);
}
}
- if (codeGated) await requestReviewers(codeOwners);
if (designGated) await requestReviewers(designOwners);
// --- Only the CODE gate blocks. Design review is advisory: