Skip to content
shellhacks.dev
CI/CD

Write a Github Action job summary

Write Markdown to the file in GITHUB_STEP_SUMMARY to add a table or a note to the job summary page. Each step gets its own file, and output is limited in size.

1 min read
Summarize in AI

A job ends with numbers that deserve more than a line in the log, such as test counts or a list of files that changed.

Shell
export GITHUB_STEP_SUMMARY=$(mktemp)
{
  echo "### Test results"
  echo
  echo "| Suite | Passed | Failed |"
  echo "|---|---|---|"
  echo "| unit | 120 | 0 |"
  echo "| integration | 31 | 2 |"
} >> "$GITHUB_STEP_SUMMARY"
cat "$GITHUB_STEP_SUMMARY"
Text
### Test results

| Suite | Passed | Failed |
|---|---|---|
| unit | 120 | 0 |
| integration | 31 | 2 |

The runner uploads the Markdown in GITHUB_STEP_SUMMARY when the step ends and shows it on the summary page of the run, as the job summaries documentation describes. Use >> so that one step can add to its own summary in several writes. The file printed here is a temporary stand-in for the one the runner creates, and the table is plain GitHub flavored Markdown.

Each step has its own file, and the summaries are shown together in step order. The size of one summary is limited to 1 MiB and the page may drop the rest, so write counts, not logs. The summary is public to anyone who can read the run, so keep secrets out of it.

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

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
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.