Require Documentation Update workflow (krkn-chaos/krkn)
The Require Documentation Update workflow from krkn-chaos/krkn, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Require Documentation Update workflow from the krkn-chaos/krkn repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Require Documentation Update
on:
pull_request:
types: [opened, edited, synchronize]
branches:
- main
jobs:
check-docs:
name: Check Documentation Update
runs-on: ubuntu-latest
steps:
- name: Check if Documentation is Required
id: check_docs
run: |
# Read PR body from the event JSON file - never from shell interpolation.
# jq handles all escaping; the shell never sees the user-controlled string.
if jq -r '.pull_request.body // ""' "$GITHUB_EVENT_PATH" | \
grep -qi '\[x\].*documentation needed'; then
echo "Documentation required detected."
echo "docs_required=true" >> "$GITHUB_OUTPUT"
else
echo "Documentation not required."
echo "docs_required=false" >> "$GITHUB_OUTPUT"
fi
- name: Enforce Documentation Update (if required)
if: steps.check_docs.outputs.docs_required == 'true'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const featureBranch = context.payload.pull_request.head.ref;
const repoOwner = context.repo.owner;
const websiteRepo = 'website';
core.info(`Searching for a merged documentation PR for feature branch: ${featureBranch} in ${repoOwner}/${websiteRepo}...`);
const { data: pulls } = await github.rest.pulls.list({
owner: repoOwner,
repo: websiteRepo,
state: 'closed',
per_page: 100,
});
const mergedPr = pulls.find(
(pr) => pr.merged_at && pr.title.includes(featureBranch)
);
if (!mergedPr) {
core.setFailed(
`❌ Documentation PR for branch '${featureBranch}' is required and has not been merged.`
);
} else {
core.info(`✅ Found merged documentation PR: ${mergedPr.html_url}`);
}The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Require Documentation Update on: pull_request: types: [opened, edited, synchronize] branches: - main concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: check-docs: timeout-minutes: 30 name: Check Documentation Update runs-on: latchkey-small steps: - name: Check if Documentation is Required id: check_docs run: | # Read PR body from the event JSON file - never from shell interpolation. # jq handles all escaping; the shell never sees the user-controlled string. if jq -r '.pull_request.body // ""' "$GITHUB_EVENT_PATH" | \ grep -qi '\[x\].*documentation needed'; then echo "Documentation required detected." echo "docs_required=true" >> "$GITHUB_OUTPUT" else echo "Documentation not required." echo "docs_required=false" >> "$GITHUB_OUTPUT" fi - name: Enforce Documentation Update (if required) if: steps.check_docs.outputs.docs_required == 'true' uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const featureBranch = context.payload.pull_request.head.ref; const repoOwner = context.repo.owner; const websiteRepo = 'website'; core.info(`Searching for a merged documentation PR for feature branch: ${featureBranch} in ${repoOwner}/${websiteRepo}...`); const { data: pulls } = await github.rest.pulls.list({ owner: repoOwner, repo: websiteRepo, state: 'closed', per_page: 100, }); const mergedPr = pulls.find( (pr) => pr.merged_at && pr.title.includes(featureBranch) ); if (!mergedPr) { core.setFailed( `❌ Documentation PR for branch '${featureBranch}' is required and has not been merged.` ); } else { core.info(`✅ Found merged documentation PR: ${mergedPr.html_url}`); }
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. - Cancel superseded runs when a branch or PR gets a newer push.
- 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.