Assign PR to DRI workflow (knex/knex)
The Assign PR to DRI workflow from knex/knex, explained and optimized by Latchkey.
A
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Assign PR to DRI workflow from the knex/knex repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: Assign PR to DRI
on:
pull_request_target:
types: [opened, labeled, synchronize]
permissions:
issues: write
pull-requests: write
jobs:
assign:
runs-on: ubuntu-latest
steps:
- name: Assign based on DRI label
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
core.info('No pull request payload; exiting.');
return;
}
const labels = (pr.labels || []).map((label) => label.name);
const labelMatch = labels.find((name) => /^DRI:@/i.test(name));
if (!labelMatch) {
core.info('No DRI label found; skipping assignment.');
return;
}
const driUser = labelMatch
.replace(/^DRI:@/i, '')
.trim()
.replace(/^@+/, '');
core.info(`Found DRI label: ${labelMatch} -> ${driUser}`);
const driUserLower = driUser.toLowerCase();
const assignees = (pr.assignees || [])
.map((assignee) => assignee.login?.toLowerCase())
.filter(Boolean);
if (assignees.includes(driUserLower)) {
core.info('DRI already assigned; skipping assignment.');
return;
}
if (context.payload.action === 'synchronize') {
const sender = context.payload.sender?.login || '';
if (sender.toLowerCase() === driUserLower) {
core.info('Latest commit by DRI; skipping assignment.');
return;
}
}
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
assignees: [driUser],
});
core.info(`Set assignee for PR #${pr.number} to ${driUser}`);
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Assign PR to DRI on: pull_request_target: types: [opened, labeled, synchronize] permissions: issues: write pull-requests: write jobs: assign: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Assign based on DRI label uses: actions/github-script@v7 with: script: | const pr = context.payload.pull_request; if (!pr) { core.info('No pull request payload; exiting.'); return; } const labels = (pr.labels || []).map((label) => label.name); const labelMatch = labels.find((name) => /^DRI:@/i.test(name)); if (!labelMatch) { core.info('No DRI label found; skipping assignment.'); return; } const driUser = labelMatch .replace(/^DRI:@/i, '') .trim() .replace(/^@+/, ''); core.info(`Found DRI label: ${labelMatch} -> ${driUser}`); const driUserLower = driUser.toLowerCase(); const assignees = (pr.assignees || []) .map((assignee) => assignee.login?.toLowerCase()) .filter(Boolean); if (assignees.includes(driUserLower)) { core.info('DRI already assigned; skipping assignment.'); return; } if (context.payload.action === 'synchronize') { const sender = context.payload.sender?.login || ''; if (sender.toLowerCase() === driUserLower) { core.info('Latest commit by DRI; skipping assignment.'); return; } } await github.rest.issues.update({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.number, assignees: [driUser], }); core.info(`Set assignee for PR #${pr.number} to ${driUser}`);
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.