Skip to content

chore(deps): Bump the docs group across 1 directory with 2 updates #6

chore(deps): Bump the docs group across 1 directory with 2 updates

chore(deps): Bump the docs group across 1 directory with 2 updates #6

Workflow file for this run

name: PR Labels

Check warning on line 1 in .github/workflows/pr-labels.yaml

View workflow run for this annotation

GitHub Actions / PR Labels

Workflow execution policy warning (evaluate mode)

On December 2, 2026, GitHub will restrict `pull_request_target` on public repositories by default. To continue allowing the event trigger, configure an Actions policy. Learn more: https://gh.io/securely-using-pull_request_target#default-policy-for-pull_request_target
# Checks the PR title format and applies the labels that .github/release.yml
# uses to group release notes.
#
# pull_request_target is used so that labels can be applied to PRs from forks.
# This workflow never checks out or runs code from the PR.
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]
permissions:
contents: read
issues: write
pull-requests: write
concurrency:
group: pr-labels-${{ github.event.pull_request.number }}
# Queue rather than cancel, so a run is never stopped part-way through
# changing labels.
cancel-in-progress: false
jobs:
title:
name: Check title and label by type
# Runs on pushes too: GitHub keeps only one pending run per concurrency
# group, so a push can replace a queued run for a title edit.
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v8
with:
script: |
const issue_number = context.payload.pull_request.number;
const { owner, repo } = context.repo;
// Read the current title. The event payload keeps the title from when the
// run started, so a re-run of an old run would otherwise apply old labels.
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
const title = pr.title;
// Creates the label if it doesn't exist. A 422 means another run created
// it first, which is fine.
async function ensureLabel(name, color) {
try {
await github.rest.issues.getLabel({ owner, repo, name });
} catch (e) {
if (e.status !== 404) throw e;
try {
await github.rest.issues.createLabel({ owner, repo, name, color });
} catch (e2) {
if (e2.status !== 422) throw e2;
}
}
}
const typeLabels = new Map([
['feat', 'Feature'],
['fix', 'Bug'],
['perf', 'performance'],
['docs', 'Documentation'],
['refactor', 'maintenance'],
['chore', 'maintenance'],
['build', 'maintenance'],
['revert', null],
['ci', 'ci'],
['test', 'test'],
]);
// Scopes for internal-only work, which release notes leave out
// (e.g. "fix(ci): ..." is labelled ci, not bug).
const scopeLabels = new Map([['ci', 'ci'], ['test', 'test'], ['tests', 'test']]);
// Labels this job owns. The title is the source of truth for them:
// any that don't match the current title are removed. Feature, Bug and
// Documentation are the repo's existing labels. GitHub label names are
// case-insensitive, so labels are compared in lowercase.
const colors = new Map([
['breaking-change', 'b60205'],
['Feature', '0e8a16'],
['Bug', 'd73a4a'],
['performance', 'fbca04'],
['Documentation', '0075ca'],
['maintenance', 'c5def5'],
['ci', 'ededed'],
['test', 'ededed'],
]);
const owned = new Set([...colors.keys()].map((n) => n.toLowerCase()));
let wanted;
if (/^Revert "/.test(title)) {
// Title generated by GitHub's "Revert" button.
wanted = new Set();
} else {
// The type is matched in any case, so "Fix: ..." is labelled like "fix: ...".
const m = /^([A-Za-z]+)(?:\(([^)]+)\))?(!)?: \S/.exec(title);
if (!m || !typeLabels.has(m[1].toLowerCase())) {
core.setFailed(
`PR title "${title}" must look like "type(scope): description" or ` +
`"type: description", where type is one of: ` +
`${[...typeLabels.keys()].join(', ')}. Add "!" after the type or scope ` +
`for a breaking change, e.g. "feat(plan)!: ...". See CONTRIBUTING.md.`
);
return;
}
const [, rawType, scope, bang] = m;
const type = rawType.toLowerCase();
wanted = new Set();
if (bang) {
// Breaking changes always appear in the release notes, so they
// never get the ci/test labels that exclude a PR.
wanted.add('breaking-change');
const label = typeLabels.get(type);
if (label && label !== 'ci' && label !== 'test') wanted.add(label);
} else {
const label = (scope && scopeLabels.get(scope.toLowerCase())) || typeLabels.get(type);
if (label) wanted.add(label);
}
}
const { data: live } = await github.rest.issues.listLabelsOnIssue({
owner, repo, issue_number, per_page: 100,
});
const current = live.map((l) => l.name);
const currentLower = current.map((n) => n.toLowerCase());
const wantedLower = new Set([...wanted].map((n) => n.toLowerCase()));
for (const name of current) {
const lower = name.toLowerCase();
if (!owned.has(lower) || wantedLower.has(lower)) continue;
try {
await github.rest.issues.removeLabel({ owner, repo, issue_number, name });
} catch (e) {
if (e.status !== 404) throw e;
}
}
const toAdd = [...wanted].filter((name) => !currentLower.includes(name.toLowerCase()));
for (const name of toAdd) {
await ensureLabel(name, colors.get(name));
}
if (toAdd.length) {
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: toAdd });
}
migrations:
name: Label new state migrations
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v8
with:
script: |
const issue_number = context.payload.pull_request.number;
const { owner, repo } = context.repo;
const files = await github.paginate(github.rest.pulls.listFiles, {
owner, repo, pull_number: issue_number, per_page: 100,
});
const added = files.some(
(f) => f.status === 'added' && /^sqlmesh\/migrations\/v\d+_.*\.py$/.test(f.filename)
);
// Read live labels: a queued run's event payload can be out of date.
const { data: live } = await github.rest.issues.listLabelsOnIssue({
owner, repo, issue_number, per_page: 100,
});
const labels = live.map((l) => l.name);
if (!added) {
// The PR no longer adds a migration, e.g. the file was removed.
if (labels.includes('migration')) {
try {
await github.rest.issues.removeLabel({ owner, repo, issue_number, name: 'migration' });
} catch (e) {
if (e.status !== 404) throw e;
}
}
return;
}
if (labels.includes('migration')) return;
try {
await github.rest.issues.getLabel({ owner, repo, name: 'migration' });
} catch (e) {
if (e.status !== 404) throw e;
try {
await github.rest.issues.createLabel({ owner, repo, name: 'migration', color: '5319e7' });
} catch (e2) {
// Another run created it first.
if (e2.status !== 422) throw e2;
}
}
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: ['migration'] });