mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
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.
95 lines
3.9 KiB
YAML
95 lines
3.9 KiB
YAML
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,
|
|
});
|
|
}
|