Skip to content
shellhacks.dev
CI/CD

Print a warning annotation

Print ::warning file=...,line=...::message from a step to show an annotation on the run and in the pull request diff. Newlines in the text must be encoded.

1 min read
Summarize in AI

A script finds a problem that should not fail the build, and a line in a log nobody opens will be missed.

Shell
echo "::warning::disk usage is above 80 percent"
echo "::warning file=src/app.sh,line=12,title=Slow query::query took 3.2 seconds"
msg=$'first line\nsecond line'
msg=${msg//$'\n'/%0A}
echo "::warning::$msg"
Text
::warning::disk usage is above 80 percent
::warning file=src/app.sh,line=12,title=Slow query::query took 3.2 seconds
::warning::first line%0Asecond line

A line that starts with ::warning is a workflow command: the runner removes it from the log and creates an annotation, shown in the run summary. With file and line the annotation is attached to that line of the pull request diff, and title adds a heading, according to the workflow commands reference. The text ends at the end of the line, so a newline has to be written as %0A, as the last command does, and a percent sign as %25.

Outside the runner the lines print as they are, as above. ::error:: and ::notice:: take the same properties, and an error annotation does not fail the step by itself, so exit non-zero as well. GitHub caps how many annotations it shows per step, so a loop over many files may be cut off.

Share

More snippets

CI/CD

Check what changed in a pull request

List the files a pull request changed with git diff --name-only origin/main...HEAD. Three dots compare against the merge base, and a shallow checkout cannot do it.

2 min read
CI/CD

Group log lines in GitHub Actions

Fold log output in GitHub Actions by printing ::group::Title and ::endgroup::. A wrapper function keeps the pair together and passes the command's status on.

1 min read
CI/CD

Run a script from the repo

Run a repository script from a workflow with run: ./script.sh only if Git stores it as executable. Otherwise the step fails with Permission denied, status 126.

2 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.