Centralized error logging for GitHub Actions, with reusable Bash helpers automatically loaded via BASH_ENV.
- Creates (or ensures) an error log file on disk.
- Exports
ERRORS_PATHto$GITHUB_ENV. - Exports
BASH_ENVso every subsequentshell: bashstep automatically loads helper functions. - Provides helpers like
append_error_logandwith_error_logto capture stderr and persist it in a single log file.
Composite actions often repeat the same append_error_log() function across multiple steps.
This action eliminates that duplication by shipping a shared Bash library and auto-sourcing it for you.
Add this as the first step in your job (or before any step that should log errors):
- name: "🧯 Setup error logging"
uses: Malnati/ops-errors@v1.0.0
with:
errors_path: .github/workflows/errors.log
From this point on, all subsequent shell: bash steps automatically have:
ERRORS_PATHavailableappend_error_logavailablewith_error_logavailable
name: "Example - ops-errors"
on:
workflow_dispatch:
permissions:
contents: read
jobs:
demo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "🧯 Setup error logging"
uses: Malnati/ops-errors@v1.0.0
with:
errors_path: .github/workflows/errors.log
- name: "✅ Command with logged stderr (success)"
shell: bash
run: |
set -euo pipefail
err="$(mktemp)"
echo "This goes to stderr (but command succeeds)" >&2
append_error_log "demo: manual stderr capture" "$err" || true
- name: "❌ Command with logged stderr (failure)"
shell: bash
run: |
set -euo pipefail
with_error_log "demo: failing command" bash -lc 'echo "Boom" >&2; exit 1'
- name: "📄 Show the first lines of the error log"
shell: bash
run: |
set -euo pipefail
echo "ERRORS_PATH=$ERRORS_PATH"
test -f "$ERRORS_PATH"
head -n 50 "$ERRORS_PATH" || true
- Appends a timestamped section with
contextand the content ofstderr_fileinto$ERRORS_PATH. - Safe no-op if
ERRORS_PATHis empty or the file is empty.
- Runs the command, captures stderr to a temp file, appends to
$ERRORS_PATHif it fails, then re-throws the error (exit 1). - On success, it cleans up and returns 0.
errors_path(optional): Path to the error log file. Default:.github/workflows/errors.log
errors_path: Resolved error log file path.bash_env: The library file used asBASH_ENV.
- Use
shell: bashfor steps that rely onBASH_ENVauto-loading. - The error log is appended; you can rotate it in your workflow if desired.
Made for consistent, low-noise, reusable error logging across composite actions and workflows.