[CI] pr-title: Validate pull request title format (#44165)

This commit is contained in:
Cheng Wan
2026-10-13 19:53:52 -07:00
committed by GitHub
parent 4f5fcbfef5
commit c053fc71d3
10 changed files with 281 additions and 7 deletions
+1 -1
View File
@@ -264,5 +264,5 @@ git add docs/src/snippets/configs/<hf-org>/<slug>.jsx \
docs/docs.json docs/cookbook/<category>/intro.mdx
git commit -m "Add <Display-Name> cookbook"
git push -u origin add-<model>-cookbook
gh pr create --title "Add <Display-Name> cookbook" --body "..."
gh pr create --title "[Doc] cookbook: Add <Display-Name> cookbook" --body "..."
```
+8
View File
@@ -1,5 +1,13 @@
<!-- Thank you for your contribution! Please follow these guidelines to enhance your pull request. If anything is unclear, submit your PR and reach out to maintainers for assistance. Join our Slack community at https://slack.sglang.io to discuss further. -->
<!-- PR title: [Type] scope: title, or [Type] [Hardware] scope: title.
Type: Feat, Fix, Refactor, Perf, Doc, Test, CI, or Chore.
Scope: any module or model name (no fixed list or letter-case restriction), e.g. attention, qwen3, or flash-attn.
Hardware: optional single tag without spaces. Use uppercase hardware tags (AMD, NVIDIA, NPU, MI300X), except for exactly these four spellings: Intel, Apple, Huawei, Ascend.
Title: no letter-case restriction.
Reverts: use GitHub's default title, Revert "original title".
Examples: [Fix] attention: Fix KV cache indexing; [Perf] [AMD] flash-attn: Optimize decode performance. -->
## Motivation
<!-- Describe the purpose and goals of this pull request. -->
+207
View File
@@ -0,0 +1,207 @@
const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const { test } = require('node:test');
const { resolve } = require('node:path');
// Exercise the exact metadata-only script used by the workflow.
const workflow = readFileSync(
resolve(__dirname, '../workflows/pr-title.yml'),
'utf8'
);
function extractScript(source) {
const lines = source.split('\n');
const step = lines.findIndex(line => /^\s*- name: Validate PR title\s*$/.test(line));
assert.notEqual(step, -1, 'Missing PR title validation step');
const stepIndent = lines[step].match(/^ */)[0].length;
for (let i = step + 1; i < lines.length; i++) {
if (lines[i].trim() && lines[i].match(/^ */)[0].length <= stepIndent) break;
const header = /^( *)script: \|[-+]?\s*$/.exec(lines[i]);
if (!header) continue;
const body = [];
let indent;
for (const line of lines.slice(i + 1)) {
if (!line.trim()) { body.push(''); continue; }
const spaces = line.match(/^ */)[0].length;
if (spaces <= header[1].length) break;
indent ??= spaces;
assert.ok(spaces >= indent, 'Invalid script block indentation');
body.push(line.slice(indent));
}
assert.ok(body.some(line => line.trim()), 'Empty PR title validation script');
return body.join('\n').trimEnd();
}
assert.fail('Missing PR title validation script');
}
const script = extractScript(workflow);
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
const checkTitle = new AsyncFunction('github', 'context', 'core', script);
async function validate(title) {
const failures = [];
let requests = 0;
await checkTitle({
rest: { pulls: { get: async params => {
assert.deepEqual(params, { owner: 'sgl-project', repo: 'sglang', pull_number: 123 });
requests++;
return { data: { title } };
} } },
}, {
repo: { owner: 'sgl-project', repo: 'sglang' },
issue: { number: 123 },
// A rerun must validate the current API title, not the frozen event title.
payload: { pull_request: { title: 'An outdated title' } },
}, {
setFailed: message => failures.push(message),
});
assert.equal(requests, 1);
return failures;
}
const valid = [
'[Fix] Attention: Fix output',
'[Feat] Qwen3.5: add model support',
'[Fix] Flash-Attn: FIX OUTPUT',
'[Fix] [Apple] MLX: fix output',
'[Fix] [HYGON] cpu: Fix output',
'[Fix] [QUALCOMM] cpu: Fix output',
'[Fix] [Huawei] model/Qwen3: Fix output',
'[Fix] [Ascend] attention: Fix output',
'[Perf] [TPU] Attention: optimize decode',
'Revert "[Fix] attention: Fix output"',
'Revert "A legacy title without tags or scope"',
'Revert "Revert "[Fix] attention: Fix output""',
'Revert "x"',
...['Feat', 'Fix', 'Refactor', 'Perf', 'Doc', 'Test', 'CI', 'Chore']
.map(type => `[${type}] attention: Update implementation`),
'[Feat] qwen3: Add model support',
'[Perf] [AMD] flash-attn: Optimize decode performance',
'[Fix] [Intel] sgl-kernel: Fix output',
'[Fix] [NVIDIA] model/qwen3: Fix output',
'[Test] qwen3.5: Add coverage',
'[CI] pr_title: Check format',
'[Perf] [MI300X] moe: Optimize dispatch',
'[Doc] contribution: 文档更新',
'[Chore] ci: x',
'[Fix] ci: Handle `quotes`, "text", and $(commands) as data',
];
const invalid = [
'[Fix] [Hygon] cpu: Fix output',
'[Fix] [Qualcomm] cpu: Fix output',
...['amd', 'Amd', 'nvidia', 'Nvidia', 'intel', 'INTEL',
'apple', 'APPLE', 'huawei', 'HUAWEI', 'ascend', 'ASCEND',
'tpu', 'Tpu', 'mi300x', 'Mi300X']
.map(hardware => `[Fix] [${hardware}] attention: Fix output`),
'[Revert] attention: Revert output fix',
'Revert ""',
'Revert " "',
'Revert " title"',
'Revert "title "',
'Revert "title',
'Revert title',
'revert "title"',
'Revert "title"',
'Revert "title" extra text',
'Revert "title"\n',
'Revert "multi\nline"',
'Fix KV cache indexing',
'[Fix] Fix KV cache indexing',
'[Feature] model: Add support',
'[fix] attention: Fix output',
'[Fix][AMD] attention: Fix output',
'[Fix] [AMD][NVIDIA] attention: Fix output',
'[Fix] [AMD] [NVIDIA] attention: Fix output',
'[Fix] [] attention: Fix output',
'[Fix] [ AMD ] attention: Fix output',
'[Fix] [AMD GPU] attention: Fix output',
'[Fix] : Fix output',
'[Fix] flash attn: Fix output',
'[Fix] attention : Fix output',
'[Fix] attention:Fix output',
'[Fix] attention: Fix output',
'[Fix] attention: ',
'[Fix] attention: ',
'[Fix] attention: Fix output',
'[Fix]\tattention: Fix output',
'[Fix] attention:\tFix output',
' [Fix] attention: Fix output',
'[Fix] attention: Fix output ',
'[Fix] attention: Fix output\n',
'[Fix] attention: Fix\noutput',
];
for (const title of valid) {
test(`accept ${JSON.stringify(title)}`, async () => {
assert.deepEqual(await validate(title), []);
});
}
for (const title of invalid) {
test(`reject ${JSON.stringify(title)}`, async () => {
const failures = await validate(title);
assert.equal(failures.length, 1);
assert.match(failures[0], /\[Type\] scope: title/);
assert.match(failures[0], /\[Type\] \[Hardware\] scope: title/);
});
}
for (const indicator of ['|-', '|+']) {
test(`extract script with ${indicator}`, () => {
assert.equal(extractScript(workflow.replace('script: |', `script: ${indicator}`)), script);
});
}
test('extract script without absorbing later steps', () => {
const extended = workflow + ' - name: Later step\n run: echo done\n';
assert.equal(extractScript(extended), script);
});
test('extract script with different indentation', () => {
const indented = workflow.split('\n').map(line => ' ' + line).join('\n');
assert.equal(extractScript(indented), script);
});
// Read the actual title templates without executing release scripts or creating PRs.
function loadSource(path) {
return readFileSync(resolve(__dirname, '../..', path), 'utf8');
}
function expand(template, variables) {
return template.replace(/\$\{([A-Z_]+)\}/g, (_, name) => {
assert.ok(Object.hasOwn(variables, name), `Missing variable ${name}`);
return variables[name];
});
}
function titleTemplate(path) {
const match = /--title "([^"\n]+)"/.exec(loadSource(path));
assert.ok(match, `Missing title in ${path}`);
return match[1];
}
for (const versionType of ['SGLang', 'sgl-kernel', 'flashinfer', 'docs install']) {
test(`release helper title for ${versionType}`, async () => {
const title = expand(titleTemplate('scripts/release/commit_and_pr.sh'), {
VERSION_TYPE: versionType, NEW_VERSION: '1.2.3',
});
assert.deepEqual(await validate(title), []);
});
}
test('kernel sync helper title', async () => {
const title = expand(titleTemplate('scripts/release/commit_and_pr_kernel_to_sglang.sh'), {
KERNEL_VERSION: '1.2.3',
});
assert.deepEqual(await validate(title), []);
});
for (const path of ['.github/workflows/sync-lmsys-sglang-blogs.yml',
'.github/workflows/weekly-update-est-time.yml']) {
test(`automated title in ${path}`, async () => {
assert.deepEqual(await validate(titleTemplate(path)), []);
});
}
const cherryPick = loadSource('.github/workflows/bot-cherry-pick.yml');
const cherryPickTemplates = [...cherryPick.matchAll(/CHERRY_PICK_TITLE="([^"\n]+)"/g)];
assert.equal(cherryPickTemplates.length, 2);
for (const [i, match] of cherryPickTemplates.entries()) {
test(`cherry-pick title variant ${i}`, async () => {
const title = expand(match[1], {
TARGET_BRANCH: 'release/v0.5.7', PR_TITLE: 'Legacy title without a scope',
SOURCE_PR: '#123', SHORT_SHA: 'abcdef12',
});
assert.deepEqual(await validate(title), []);
});
}
+2 -2
View File
@@ -215,9 +215,9 @@ jobs:
NEW_BRANCH: ${{ steps.cherry_pick.outputs.new_branch }}
run: |
if [[ -n "$SOURCE_PR" ]]; then
CHERRY_PICK_TITLE="[Cherry-pick to ${TARGET_BRANCH}] ${PR_TITLE} (${SOURCE_PR})"
CHERRY_PICK_TITLE="[Chore] release: Cherry-pick ${PR_TITLE} to ${TARGET_BRANCH} (${SOURCE_PR})"
else
CHERRY_PICK_TITLE="[Cherry-pick to ${TARGET_BRANCH}] ${PR_TITLE} (${SHORT_SHA})"
CHERRY_PICK_TITLE="[Chore] release: Cherry-pick ${PR_TITLE} to ${TARGET_BRANCH} (${SHORT_SHA})"
fi
BODY="Cherry-pick of commit \`${FULL_SHA}\` to \`${TARGET_BRANCH}\`."$'\n\n'
+3
View File
@@ -78,6 +78,9 @@ jobs:
node docs/scripts/check_cookbook_configs.mjs
node --test docs/scripts/tests/*.test.mjs
- name: Test PR title check
run: node --test .github/scripts/pr-title.test.cjs
- name: Test PR health action
run: node --test .github/actions/check-pr-test-health/action.test.cjs
+56
View File
@@ -0,0 +1,56 @@
name: PR Title
on:
pull_request_target:
types: [opened, edited, synchronize, reopened, ready_for_review]
permissions:
pull-requests: read
concurrency:
group: pr-title-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check-pr-title:
name: Check PR title
runs-on: ubuntu-latest
steps:
# Read metadata only; never check out or execute code from the PR.
- name: Validate PR title
uses: actions/github-script@v8
with:
script: |
// Fetch the current title so reruns also reflect title edits.
const { data: pr } = await github.rest.pulls.get({
...context.repo,
pull_number: context.issue.number,
});
const types = ['Feat', 'Fix', 'Refactor', 'Perf', 'Doc', 'Test', 'CI', 'Chore'];
const pattern = new RegExp(
String.raw`^\[(${types.join('|')})\] (?:\[([A-Za-z0-9][A-Za-z0-9._+-]*)\] )?` +
String.raw`[A-Za-z0-9]+(?:[._/-][A-Za-z0-9]+)*: \S(?:[^\r\n]*\S)?$`
);
const match = pattern.exec(pr.title);
const hardware = match?.[2];
// Hardware is uppercase except for these four canonical brand spellings.
const brands = ['Intel', 'Apple', 'Huawei', 'Ascend'];
const brand = brands.find(name => name.toLowerCase() === hardware?.toLowerCase());
const validHardware = !hardware || hardware === (brand || hardware.toUpperCase());
// Preserve GitHub's generated revert titles, including legacy originals.
const isRevert = /^Revert "\S(?:[^\r\n]*\S)?"$/.test(pr.title);
if ((!(match && validHardware) && !isRevert) || pr.title !== pr.title.trim()) {
core.setFailed(
'PR title must use "[Type] scope: title" or "[Type] [Hardware] scope: title". ' +
`Type must be one of: ${types.join(', ')}. ` +
'Scope is required and may be any module or model name, with unrestricted letter case ' +
'(letters, numbers, dots, underscores, slashes, or hyphens). ' +
'Hardware is optional; use a single tag without spaces. Use uppercase hardware tags (AMD, NVIDIA, NPU, MI300X), except for exactly these four spellings: Intel, Apple, Huawei, Ascend. ' +
'Reverts must use GitHub\'s default format: Revert "original title". ' +
'Use one space between fields and after the colon, with a non-empty title ' +
'and no leading or trailing whitespace. ' +
'Examples: "[Fix] attention: Fix KV cache indexing", ' +
'"[Feat] qwen3: Add model support", ' +
'"[Perf] [AMD] flash-attn: Optimize decode performance".'
);
}
@@ -55,6 +55,6 @@ jobs:
gh pr create \
--base main \
--head "$BRANCH" \
--title "docs: sync LMSYS SGLang blog cards" \
--title "[Doc] blogs: Sync LMSYS SGLang blog cards" \
--body $'Automated sync of the LMSYS SGLang blog cards in `docs/index.mdx`.\n\n🤖 Generated with GitHub Actions'
fi
+1 -1
View File
@@ -74,7 +74,7 @@ jobs:
} > /tmp/pr_body.md
gh pr create \
--title "chore: update CI test est_time values" \
--title "[Chore] ci: Update test est_time values" \
--body-file /tmp/pr_body.md \
--base main \
--head "$BRANCH_NAME"
+1 -1
View File
@@ -41,7 +41,7 @@ git push origin "${BRANCH_NAME}"
# Create pull request
echo "Creating pull request..."
PR_URL=$(gh pr create \
--title "chore: bump ${VERSION_TYPE} version to ${NEW_VERSION}" \
--title "[Chore] release: Bump ${VERSION_TYPE} version to ${NEW_VERSION}" \
--body "## Summary
This PR bumps the ${VERSION_TYPE} version to \`${NEW_VERSION}\` across all relevant files.
@@ -42,7 +42,7 @@ git push origin "${BRANCH_NAME}"
# Create pull request
echo "Creating pull request..."
PR_URL=$(gh pr create \
--title "chore: bump sglang-kernel version to ${KERNEL_VERSION}" \
--title "[Chore] release: Bump sglang-kernel version to ${KERNEL_VERSION}" \
--body "## Summary
This PR bumps the \`sglang-kernel\` version to \`${KERNEL_VERSION}\` across SGLang files to match the version defined in \`python/sglang/kernels/aot/pyproject.toml\`.