Sub topic 7
Annotations and the run summary
This chapter assumes you can open a failed run in the Actions tab and read a step log, as covered in the earlier chapters. You should also be comfortable with YAML and with shell steps that use run:. Here you will learn what annotations and the run summary show, where they come from, and how to write your own.
Why the summary page matters
The log of a step is complete but long. The run's Summary page is the short version. It has three parts:
- The Annotations section lists errors, warnings, and notices, grouped by the job that produced them.
- The Artifacts section lists files the run uploaded.
- Any job summary text, written as Markdown by the steps themselves, appears below the job graph.
Open the Summary page before you open a log. If an annotation already says Process completed with exit code 1. for the step Run npm test, you know which log to open. Often the annotation also carries the actual error line.
Where annotations come from
Annotations reach the Summary page in three ways.
- The runner creates them. When a step exits with a non-zero code, the runner adds an error annotation such as
Process completed with exit code 1.It also adds warnings for things like deprecated Node.js runtimes in actions. - Your own commands print workflow commands. A line that starts with
::error,::warning, or::noticebecomes an annotation. - Problem matchers do it for you. A problem matcher is a set of regular expressions that turns tool output, such as compiler or linter messages, into annotations. Some actions register matchers for you.
The diagram shows how these paths end up in the same places.
Writing annotations with workflow commands
A workflow command is a specially formatted line written to standard output. The format is:
::error file=app/index.js,line=10,col=5,title=Lint failure::Unexpected console statementThe part after ::error is a comma-separated list of properties. The message follows the second ::. These properties are available:
| Property | Meaning |
|---|---|
| `title` | A short heading shown above the message |
| `file` | Path to the file, relative to the repository root |
| `line`, `endLine` | Start and end line numbers |
| `col`, `endColumn` | Start and end column numbers |
All properties are optional. Without file and line, the annotation shows on the run and job pages but is not attached to code. With file and line, and when the file is part of a pull request's diff, GitHub also shows the message inline on the Files changed tab.
Here is a step that emits all three levels:
name: Annotation demo
on: [push, pull_request]
jobs:
demo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Emit annotations
run: |
echo "::notice title=Info::Starting checks"
echo "::warning file=README.md,line=1,title=Docs::README has no install section"
echo "::error file=README.md,line=3,endLine=5,title=Broken link::Link target not found"This step exits with code 0, so the job still passes. The run shows one notice, one warning, and one error annotation on a green check mark.
An error annotation does not fail the step
This is a common point of confusion. ::error:: only creates a message. A step fails because of its exit code, not because it printed an error annotation. The example from the topic plan shows both together:
steps:
- name: Run checks
run: |
echo "::group::Install"
npm ci
echo "::endgroup::"
echo "::error file=app/index.js,line=10::Example error annotation"
exit 1
- name: Show diagnostics on failure
if: failure()
run: ls -laRemove exit 1 and the step succeeds, even though an error annotation appears. If you write a custom check script, make sure it prints the annotation and also exits non-zero.
Multi-line messages and special characters
A workflow command must fit on one line. To include a line break in the message, encode it as %0A. Encode a carriage return as %0D and a literal percent sign as %25.
echo "::error title=Tests failed::3 tests failed:%0A- login%0A- logout%0A- refresh"If your message contains user-controlled text, such as a pull request title, pass it through an environment variable and sanitize it. A value containing a newline followed by :: can inject extra commands into the log.
Limits you will run into
GitHub caps how many annotations are kept. The documented limits are 10 each of errors, warnings, and notices per step, 50 per job, and 50 per run. If a linter reports 400 problems, only a small fraction shows up as annotations. The log still has every line.
Two practical effects follow:
- A flood of annotations from one tool can hide the single error you care about. Open the log, not just the annotation list, when the count looks capped.
- Annotations are for pointing at the problem. Put the complete report in a job summary or an uploaded artifact.
The job summary
A job summary is Markdown that a step writes to the file named by the GITHUB_STEP_SUMMARY environment variable. The runner provides a different file for each step and renders the contents on the run's Summary page after the step finishes. GitHub-flavored Markdown works, including tables and code blocks.
This workflow writes a summary whether the tests pass or fail:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
- name: Write summary
if: always()
run: |
{
echo "## Test results"
echo ""
echo "| Item | Value |"
echo "| --- | --- |"
echo "| Job status | ${{ job.status }} |"
echo "| Commit | ${GITHUB_SHA::7} |"
echo "| Runner OS | $RUNNER_OS |"
} >> "$GITHUB_STEP_SUMMARY"Three details matter here:
- Use
>>, not>. Appending preserves what earlier commands in the same step wrote. Overwriting discards it. - Use
if: always(). Without a status condition, a step only runs when everything before it succeeded. The summary you most want is the one from a failed run.if: failure()is the other common choice if you only want the step on failure. job.statusreflects the job so far. In a step withalways(), it reportsfailureif an earlier step failed.
Each step's summary is limited to 1 MiB. A job can show at most 20 step summaries, and GitHub drops any beyond that. Keep summaries short: a table of failures, a link to an artifact, or the last 20 lines of a test report.
Summaries and secrets
Summary text is not scanned and masked the way log output is. Do not write secrets, tokens, or the content of environment variables you have not checked. Anyone who can view the run can read the summary.
A reading routine using annotations
Combine the Summary page with the earlier chapters' method:
- Open the run and read the Annotations section. Note the job and step names in each error.
- Check whether the count suggests a cap, such as exactly 10 errors from one step. If so, trust the log, not the list.
- Read any job summary for a pre-digested report.
- Open the failing job and step, then find the first real error in the log. The annotation tells you where to look. It does not always tell you the root cause.
- If an annotation names a file and line, jump to that line in the commit or pull request to see the code in context.
Common mistakes
| Symptom | Likely cause |
|---|---|
| Annotation shows on the run page but not on the code | `file` is missing, the path is not relative to the repository root, or the file is not in the pull request diff |
| Printed `::error::` but the job is green | The step exited with code 0 |
| Summary page has no job summary | The step wrote with `>` into the wrong file, never ran because of an earlier failure, or the Markdown was written after the variable was lost in a subshell |
| Summary missing on failed runs | The step has no `if: always()` or `if: failure()` |
| Only 10 errors appear for a large failure | Per-step annotation cap |
Exercise
A custom script prints ::error file=src/app.js,line=12::Missing semicolon and then finishes normally with exit code 0. The Summary page shows the error annotation, but the job has a green check. Why, and what is the minimal change that makes the job fail?
Show answer
An annotation is only a message. A step fails because of its exit code, and the script exited with 0. Make the script (or the run step) exit with a non-zero code after printing the annotation, for example by adding exit 1.
Exercise
You add a step that appends a results table to $GITHUB_STEP_SUMMARY, but on failed runs the table never appears. What is the likely cause, and how do you fix it?
Show answer
The step is placed after a step that fails, and steps without a status condition run only when all previous steps succeeded. Add if: always() (or if: failure()) to the summary step so it runs after a failure.