Sub topic 14
Debugging and log output
This chapter assumes you can write a composite action with inputs, outputs and shell on every run step. It also assumes you know how a workflow calls the action. The goal is to find out why an action misbehaves, and to make its logs useful to the people who call it.
Where composite action logs appear
A workflow that calls a composite action shows one step in the job log. Expanding it shows the output of each inner step, one after another. You can't put a breakpoint inside the action, so logs are your main tool. Two habits help most:
- Write log lines that say what the action is doing and which values it received.
- Keep verbose detail hidden until someone asks for it.
flowchart TD
A[Step fails or output is wrong] --> B{Is the error in the log?}
B -- yes --> C[Read the failing inner step and its exit code]
B -- no --> D[Re-run with debug logging enabled]
D --> E[Check debug lines and inputs]
E --> F{Output empty?}
F -- yes --> G[Check step id, GITHUB_OUTPUT write and outputs value]
F -- no --> H[Add set -x or ::debug:: lines and re-run]The diagram above is a typical debugging path. The first question is whether the log already shows the failure.
Turning on debug logging
GitHub has several debug switches, and they do different things.
| Switch | Where you set it | Effect |
|---|---|---|
| "Enable debug logging" on re-run | Re-run dialog in the UI | Turns on step debug logging for one run |
| `ACTIONS_STEP_DEBUG` set to `true` | Repository secret or variable | Shows `::debug::` lines for every run |
| `ACTIONS_RUNNER_DEBUG` set to `true` | Repository secret or variable | Adds runner diagnostic logs |
| `runner.debug` context | Used in `if:` or expressions | Equals `'1'` only while debug logging is on |
Use the re-run checkbox first. It affects only that run and leaves no configuration behind. A failure you can't reproduce on demand is easier to catch with ACTIONS_STEP_DEBUG, but remember to remove it later, because debug logs are noisy.
Workflow commands for log output
A workflow command is a line of text that the runner reads from a step's standard output. The runner turns it into formatting or an annotation. Any run step in a composite action can print these commands.
| Command | What it does |
|---|---|
| `::debug::text` | A message shown only when debug logging is on |
| `::notice::text` | An annotation shown on the run summary page |
| `::warning::text` | A warning annotation |
| `::error::text` | An error annotation. It does not fail the step by itself. |
| `::group::title` and `::endgroup::` | A collapsible block in the log |
| `::add-mask::value` | Hides a value in later log output |
Annotation commands accept parameters before the colons, such as title=, file= and line=. A warning that points at a file looks like this:
echo "::warning file=src/app.js,line=12,title=Deprecated call::Use run() instead of exec()"An ::error:: line only creates an annotation. If the step must fail, you also have to exit with a non-zero status. This is a common mistake. The log shows a red error annotation, but the job carries on.
A composite action with useful logging
The action below counts the files in a directory. It uses a group, an error annotation with a real failure, a warning, debug-only tracing, and a step summary.
name: Count files
description: Count files in a directory and report the result
inputs:
target:
description: Directory to inspect
required: false
default: "."
outputs:
file-count:
description: Number of files found
value: ${{ steps.count.outputs.file-count }}
runs:
using: composite
steps:
- name: Trace inputs (debug runs only)
if: ${{ runner.debug == '1' }}
shell: bash
env:
TARGET: ${{ inputs.target }}
run: |
echo "::debug::target is '${TARGET}'"
echo "::debug::working directory is '$(pwd)'"
ls -la -- "$TARGET" || true
- id: count
name: Count files
shell: bash
env:
TARGET: ${{ inputs.target }}
run: |
echo "::group::Scanning the target directory"
if [ ! -d "$TARGET" ]; then
echo "::error title=Missing directory::The target directory does not exist"
exit 1
fi
count=$(find "$TARGET" -type f -not -path '*/.git/*' | wc -l | tr -d ' ')
echo "Found ${count} files"
echo "::endgroup::"
if [ "$count" -eq 0 ]; then
echo "::warning title=Empty directory::No files were found"
fi
echo "file-count=${count}" >> "$GITHUB_OUTPUT"
- name: Write summary
shell: bash
env:
COUNT: ${{ steps.count.outputs.file-count }}
run: |
{
echo "### Scan result"
echo ""
echo "Files found: ${COUNT}"
} >> "$GITHUB_STEP_SUMMARY"Several choices here are deliberate:
- Inputs go through
env, as in the chapter on script injection, so odd characters in a directory name can't change the script. - The
::group::title is fixed text. Putting raw input into a workflow command line is risky, because a value with a newline can start a second command. - The debug step uses
ls ... || trueso a tracing step never fails the action by itself. $GITHUB_STEP_SUMMARYtakes Markdown. It appears on the run summary page, which is a good place for results a person should read.
Here is a workflow that calls it:
name: Debug demo
on: [push]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: scan
uses: ./.github/actions/count-files
with:
target: src
- run: echo "Files: ${{ steps.scan.outputs.file-count }}"Run it normally and the debug step is skipped. Re-run it with "Enable debug logging" and the trace appears.
Tracing a shell script
The shell option set -x prints every command before it runs, with variables already expanded. It is the fastest way to see what a script really did. When you write shell: bash, GitHub starts bash with -eo pipefail. A failed command stops the step, and a failure anywhere in a pipeline counts as a failure of the pipeline.
Turn tracing on only when debugging, so it doesn't flood normal runs:
if [ "${RUNNER_DEBUG:-}" = "1" ]; then
set -x
fiThe runner sets the environment variable RUNNER_DEBUG to 1 when debug logging is on. This is the shell-side equivalent of the runner.debug context.
Inspecting contexts
When an expression returns something unexpected, print the context as JSON:
- shell: bash
env:
INPUTS_JSON: ${{ toJSON(inputs) }}
run: echo "::debug::${INPUTS_JSON}"Using ::debug:: keeps this out of normal logs. Check what the inputs may hold first. If a caller passes a secret as an input, the value is masked in the log, but you shouldn't rely on that as your only protection.
Common failures and their symptoms
| Symptom | Likely cause |
|---|---|
| Workflow fails early with "Required property is missing: shell" | A `run` step has no `shell` key |
| Output is an empty string | Wrong step `id`, missing `id`, or the `outputs.*.value` expression names the wrong step |
| Output is empty only for a multi-line value | A value with newlines needs the delimiter form for `$GITHUB_OUTPUT` |
| Step is red but the next step still runs | `continue-on-error: true` is set on the step |
| Error annotation shows but the job passes | The script printed `::error::` and never exited non-zero |
| Local path `./.github/actions/x` is not found | The workflow did not run `actions/checkout` first |
| Script from `action_path` is not found | The path was built from the wrong variable, or the script is missing from the tagged release |
Output problems are the most frequent. Work from the outside in: print the value in the step that writes it, then print ${{ steps.<id>.outputs.<name> }} in the next step, then check the calling workflow's step id.
Limits to keep in mind
- GitHub caps the number of annotations per step and per job, so don't emit one warning for every file in a large repository. Print a count and a short list instead.
- Debug output goes into the same log as normal output, so long dumps make the log hard to read. Wrap them in a
::group::. - You can't attach a debugger to a hosted runner. Tools that run workflows locally, such as the third-party project
act, can speed up iteration, but their support for composite features differs from GitHub's. Confirm a fix on a real runner.
Exercise
A composite action step prints echo "::error::Config file missing" when a file is absent. The run shows a red annotation, but the following steps still run and the job succeeds. What is wrong, and what is the fix? Also, how would you show a diagnostic line only when someone re-runs with debug logging?
Show answer
The ::error:: command only creates an annotation. It does not change the step's exit status. Add exit 1 right after the echo so the step fails and the job stops, unless a later step is meant to run with if: always(). For a debug-only line, either print it with echo "::debug::message", which the runner hides unless debug logging is on, or guard a whole step with if: ${{ runner.debug == '1' }}.
Exercise
Your action declares outputs.result.value: ${{ steps.build.outputs.result }}, but the caller always sees an empty string. List three checks you would make, in order.
Show answer
1) Confirm the writing step has id: build, since without an id nothing can reference its outputs. 2) In that step, confirm the line is written to the right file, for example echo "result=${value}" >> "$GITHUB_OUTPUT", and print ${value} first to see it isn't empty. 3) In the calling workflow, confirm the step that uses the action has an id and that the expression is steps.<that id>.outputs.result.