diff --git a/.agents/skills/cookbook-add-model/SKILL.md b/.agents/skills/cookbook-add-model/SKILL.md index 803ae11c7e..85b55c9d50 100644 --- a/.agents/skills/cookbook-add-model/SKILL.md +++ b/.agents/skills/cookbook-add-model/SKILL.md @@ -264,5 +264,5 @@ git add docs/src/snippets/configs//.jsx \ docs/docs.json docs/cookbook//intro.mdx git commit -m "Add cookbook" git push -u origin add--cookbook -gh pr create --title "Add cookbook" --body "..." +gh pr create --title "[Doc] cookbook: Add cookbook" --body "..." ``` diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a2338baf30..4f2ff0cf45 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,13 @@ + + ## Motivation diff --git a/.github/scripts/pr-title.test.cjs b/.github/scripts/pr-title.test.cjs new file mode 100644 index 0000000000..c2903ebb74 --- /dev/null +++ b/.github/scripts/pr-title.test.cjs @@ -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), []); + }); +} diff --git a/.github/workflows/bot-cherry-pick.yml b/.github/workflows/bot-cherry-pick.yml index 1c5e266712..5b3a3c6b04 100644 --- a/.github/workflows/bot-cherry-pick.yml +++ b/.github/workflows/bot-cherry-pick.yml @@ -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' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7c30400012..109226e1ae 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000000..6fae109018 --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -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".' + ); + } diff --git a/.github/workflows/sync-lmsys-sglang-blogs.yml b/.github/workflows/sync-lmsys-sglang-blogs.yml index 03d7f5a9da..de3788108c 100644 --- a/.github/workflows/sync-lmsys-sglang-blogs.yml +++ b/.github/workflows/sync-lmsys-sglang-blogs.yml @@ -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 diff --git a/.github/workflows/weekly-update-est-time.yml b/.github/workflows/weekly-update-est-time.yml index b61a669211..970e60e8f2 100644 --- a/.github/workflows/weekly-update-est-time.yml +++ b/.github/workflows/weekly-update-est-time.yml @@ -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" diff --git a/scripts/release/commit_and_pr.sh b/scripts/release/commit_and_pr.sh index b61ec6abab..be7fd69aae 100755 --- a/scripts/release/commit_and_pr.sh +++ b/scripts/release/commit_and_pr.sh @@ -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. diff --git a/scripts/release/commit_and_pr_kernel_to_sglang.sh b/scripts/release/commit_and_pr_kernel_to_sglang.sh index f636319103..d18d68cd5b 100755 --- a/scripts/release/commit_and_pr_kernel_to_sglang.sh +++ b/scripts/release/commit_and_pr_kernel_to_sglang.sh @@ -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\`.