Run Lore in CI
This guide adds a GitHub Actions job that prints the rules for each pull request, fails when a rule file is broken, and audits rule sources.
lore check lists rules; it does not judge whether a change breaks them. That is a reviewer's job (see Hand a reviewer the rules). In CI it gives every pull request a log of the rules that apply, and with --strict it fails when an error in the rules left an entry out.
-
Add the workflow. Create
.github/workflows/lore.yml:name: loreon: pull_requestjobs:lore:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4with:fetch-depth: 0- uses: actions/setup-node@v4with:node-version: 20- name: Rules for this changerun: npx @mattstack/lore check --base origin/${{ github.base_ref }} --strict- name: Rule sourcesrun: npx @mattstack/lore auditfetch-depth: 0fetches the history--baseneeds to find where the branch left its target. -
Judge by the target branch's rules. To stop a pull request from loosening a rule in the same change that breaks it, read the rules from the target branch:
- name: Rules for this changerun: npx @mattstack/lore check --base origin/${{ github.base_ref }} --rules-ref origin/${{ github.base_ref }} --strict -
Decide what fails the build.
lore check --strictexits 1 when an entry was excluded by an error.lore auditexits 1 for a finding at levelerror: by default a cited file or heading that no longer exists. Raise or lower findings with--level, or with theauditkey of a.loreconfig:- name: Rule sourcesrun: npx @mattstack/lore audit --level source-changed=error -
Pin the version. Add
@mattstack/loreas a dev dependency, so CI and every machine use the same release. Install it before the Lore steps, then call the local command:- run: npm ci- name: Rules for this changerun: npx lore check --base origin/${{ github.base_ref }} --rules-ref origin/${{ github.base_ref }} --strict- name: Rule sourcesrun: npx lore auditWithout the install,
npx lorewould fetch an unrelated package namedlore. Without a dev dependency, keepnpx @mattstack/loreand pin a version, such asnpx @mattstack/lore@0.6.1.
The exit codes for every command are on Exit codes.
Next steps
- Sources and reviews: what
lore auditreports, and how to clear it. lore check: every option, including--baseand--rules-ref.- Keep rules in a shared repository: CI for a repo whose rules live elsewhere.