Sub topic 12
Surfacing problems as inline annotations
This chapter assumes you have a working lint workflow that fails on a non-zero exit code, and that you know how pull requests display status checks. Here you will make failures easier to act on by showing each problem on the exact line of code that caused it.
Why annotations help
A failed lint job tells the author that something is wrong. To find out what, they open the job log and scroll through the output. An annotation moves that information into the pull request. GitHub draws a marker beside the offending line in the Files changed tab, and lists the message on the workflow run summary page.
Annotations do not change whether a job passes. The exit code still decides that. Annotations only improve how the failure is reported.
How annotations are created
GitHub reads the job log as it streams. When a line matches a workflow command, GitHub turns it into an annotation. The format is:
::error file=src/app.js,line=10,col=5::'foo' is assigned a value but never usedThe command name sets the severity: error, warning, or notice. The file, line, and col parameters point to the location. Everything after the second :: is the message.
Most linters can print this format themselves, so you rarely write these lines by hand.
Ruff: the built-in GitHub format
Ruff has an output format made for this purpose. Add --output-format=github to the check command:
name: Python lint
on:
pull_request:
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install ruff
- run: ruff check --output-format=github .
- run: ruff format --check .Ruff still exits non-zero when it finds violations, so the step fails. It also prints one workflow command per violation, so each one appears inline on the pull request.
ESLint: choose a formatter
ESLint's default output is plain text, which GitHub does not turn into annotations. You have two common options.
- Use ESLint's
--formatflag with a formatter that prints workflow commands. Install a formatter package such aseslint-formatter-githuband runeslint --format github .. - Use a problem matcher, which is a JSON file that tells GitHub how to parse the existing output with a regular expression.
The first option is simpler. Add a script so the workflow stays short:
{
"scripts": {
"lint": "eslint .",
"lint:ci": "eslint --format github ."
}
}Then run npm run lint:ci in the workflow. Keep lint for local use, where readable text output is better.
Formatter checks and annotations
Prettier's --check mode lists the files that differ from the expected style. It reports whole files, not lines, so there is nothing to place on a specific line. The file names appear in the log, and that is usually enough, because the fix is to run npm run format locally.
What the annotation flow looks like
Limits to know about
- GitHub shows a limited number of annotations per step and per run. In a project with hundreds of violations, some will appear only in the log.
- Annotations only attach to files that are part of the pull request diff in the Files changed view. Problems in untouched files show on the run summary instead.
- Workflow commands are read from the log, so a tool that prints them to a different stream, or a step that hides output, produces no annotations.
Exercise
Your ESLint step fails the job, but the pull request shows no inline markers. The log contains only plain text such as "10:5 error 'foo' is assigned a value but never used". What is missing, and does fixing it change whether the job fails?
Show answer
The linter is not printing workflow commands, so GitHub has nothing to parse. Use a GitHub-format formatter (for example eslint --format github . with eslint-formatter-github installed) or add a problem matcher. This does not change pass or fail, because the exit code already decides that. It only adds the inline markers.