fix(ci): restore PR metadata checks (#5374)

GitHub's default Actions policy blocks `pull_request_target` in public
repositories before any jobs start. The same annotation appears on a
fork PR and a repository branch. [Fork
run](https://github.com/lancedb/lancedb/actions/runs/47003484815) ·
[Repository branch
run](https://github.com/lancedb/lancedb/actions/runs/46997657674)

`PR Checks` validates the squash-merge title and description on
`pull_request` with an empty token permission set. Commitlint reports
failures in the check log. The default-branch `PR Labels` workflow uses
`pull-requests: write` to append release and language labels after it
verifies the current open PR and reads its metadata and changed paths
through the GitHub API. The TypeScript rule covers the current `nodejs/`
directory.

GitHub activates the `workflow_run` subscriber once the workflow file
reaches the default branch. Local verification used GitHub data from
#4918 to exercise fork lookup, label rules, and rejection of stale or
ambiguous matches with the write stubbed.
This commit is contained in:
Xuanwo
2026-12-03 01:39:39 +00:00
committed by GitHub
parent b7d83d0362
commit 3031e7c2c7
3 changed files with 104 additions and 90 deletions
-33
View File
@@ -1,33 +0,0 @@
version: 1
appendOnly: true
# Labels are applied based on conventional commits standard
# https://www.conventionalcommits.org/en/v1.0.0/
# These labels are later used in release notes. See .github/release.yml
labels:
# If the PR title has an ! before the : it will be considered a breaking change
# For example, `feat!: add new feature` will be considered a breaking change
- label: breaking-change
title: "^[^:]+!:.*"
- label: breaking-change
body: "BREAKING CHANGE"
- label: enhancement
title: "^feat(\\(.+\\))?!?:.*"
- label: bug
title: "^fix(\\(.+\\))?!?:.*"
- label: documentation
title: "^docs(\\(.+\\))?!?:.*"
- label: performance
title: "^perf(\\(.+\\))?!?:.*"
- label: ci
title: "^ci(\\(.+\\))?!?:.*"
- label: chore
title: "^(chore|test|build|style)(\\(.+\\))?!?:.*"
- label: Python
files:
- "^python\\/.*"
- label: Rust
files:
- "^rust\\/.*"
- label: typescript
files:
- "^node\\/.*"
+10 -57
View File
@@ -1,29 +1,17 @@
name: PR Checks
on:
pull_request_target:
pull_request:
types: [opened, edited, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
permissions: {}
jobs:
labeler:
permissions:
pull-requests: write
name: Label PR
runs-on: ubuntu-latest
steps:
- uses: srvaroa/labeler@9c29ad1ef33d169f9ef33c52722faf47a566bcf3 # v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
commitlint:
permissions:
pull-requests: write
name: Verify PR title / description conforms to semantic-release
runs-on: ubuntu-latest
steps:
@@ -45,46 +33,11 @@ jobs:
"body-leading-blank": [0, "always"]
}
}' > .commitlintrc.js
- run: >
pnpm dlx
--package @commitlint/cli@21.2.2
--package @commitlint/config-conventional@21.2.2
commitlint --extends @commitlint/config-conventional --verbose <<< $COMMIT_MSG
env:
COMMIT_MSG: >
${{ github.event.pull_request.title }}
${{ github.event.pull_request.body }}
- if: failure()
uses: actions/github-script@v7
with:
script: |
const message = `**ACTION NEEDED**
Lance follows the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) for release automation.
The PR title and description are used as the merge commit message.\
Please update your PR title and description to match the specification.
For details on the error please inspect the "PR Title Check" action.
`
// Get list of current comments
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
// Check if this job already commented
for (const comment of comments) {
if (comment.body === message) {
return // Already commented
}
}
// Post the comment about Conventional Commits
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
})
core.setFailed(message)
- name: Check PR title and description
shell: bash
run: |
jq -er '.pull_request | select(.title != null) | .title + "\n\n" + (.body // "")' "$GITHUB_EVENT_PATH" | \
pnpm dlx \
--package @commitlint/cli@21.2.2 \
--package @commitlint/config-conventional@21.2.2 \
commitlint --extends @commitlint/config-conventional --verbose
+94
View File
@@ -0,0 +1,94 @@
name: PR Labels
on:
workflow_run:
workflows: [PR Checks]
types: [completed]
permissions: {}
jobs:
labeler:
name: Label PR
if: >-
github.event.workflow_run.path == '.github/workflows/dev.yml' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.repository.id == github.event.repository.id &&
(github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
# This workflow runs from the default branch. Read PR metadata only through the API.
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const run = context.payload.workflow_run;
const repository = context.payload.repository;
if (!run.head_repository || !run.head_branch || !run.head_sha) {
core.info('The triggering run has no PR head.');
return;
}
// GitHub can omit pull_requests from the run for fork PRs.
const associated = new Set((run.pull_requests ?? []).map(pull => pull.number));
const matchesRun = pull => pull.state === 'open' &&
pull.base.repo.id === repository.id &&
pull.head.repo?.id === run.head_repository.id &&
pull.head.ref === run.head_branch &&
pull.head.sha === run.head_sha &&
(!associated.size || associated.has(pull.number));
const pulls = await github.paginate(github.rest.pulls.list, {
...context.repo,
state: 'open',
head: `${run.head_repository.owner.login}:${run.head_branch}`,
per_page: 100,
});
const matches = pulls.filter(matchesRun);
if (matches.length !== 1) {
core.info('The triggering run does not identify a unique open PR at its current head.');
return;
}
const [pull] = matches;
const params = { ...context.repo, pull_number: pull.number };
const files = await github.paginate(github.rest.pulls.listFiles, { ...params, per_page: 100 });
const { data: current } = await github.rest.pulls.get(params);
if (!matchesRun(current) || current.base.ref !== pull.base.ref || current.base.sha !== pull.base.sha) {
core.info('The PR head or base changed while reading its files.');
return;
}
const labels = new Set();
for (const [label, pattern] of [
['breaking-change', /^[^:]+!:/],
['enhancement', /^feat(\(.+\))?!?:/],
['bug', /^fix(\(.+\))?!?:/],
['documentation', /^docs(\(.+\))?!?:/],
['performance', /^perf(\(.+\))?!?:/],
['ci', /^ci(\(.+\))?!?:/],
['chore', /^(chore|test|build|style)(\(.+\))?!?:/],
]) {
if (pattern.test(current.title)) labels.add(label);
}
if (current.body?.includes('BREAKING CHANGE')) labels.add('breaking-change');
for (const [label, pattern] of [
['Python', /^python\//],
['Rust', /^rust\//],
['typescript', /^node(?:js)?\//],
]) {
if (files.some(file => pattern.test(file.filename) || pattern.test(file.previous_filename ?? ''))) {
labels.add(label);
}
}
const existing = new Set(current.labels.map(label => label.name));
const missing = [...labels].filter(label => !existing.has(label));
if (missing.length) {
await github.rest.issues.addLabels({
...context.repo,
issue_number: current.number,
labels: missing,
});
}