Skip to content

Malnati/ops-errors

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Malnati/ops-errors

Centralized error logging for GitHub Actions, with reusable Bash helpers automatically loaded via BASH_ENV.

ops-errors

Release License

Repo Marketplace


What it does

ops-errors

  • Creates (or ensures) an error log file on disk.
  • Exports ERRORS_PATH to $GITHUB_ENV.
  • Exports BASH_ENV so every subsequent shell: bash step automatically loads helper functions.
  • Provides helpers like append_error_log and with_error_log to capture stderr and persist it in a single log file.

Why

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.


Quick start

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_PATH available
  • append_error_log available
  • with_error_log available

Example usage

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

Helpers

append_error_log <context> <stderr_file>

  • Appends a timestamped section with context and the content of stderr_file into $ERRORS_PATH.
  • Safe no-op if ERRORS_PATH is empty or the file is empty.

with_error_log <context> <command...>

  • Runs the command, captures stderr to a temp file, appends to $ERRORS_PATH if it fails, then re-throws the error (exit 1).
  • On success, it cleans up and returns 0.

Inputs

  • errors_path (optional): Path to the error log file. Default: .github/workflows/errors.log

Outputs

  • errors_path: Resolved error log file path.
  • bash_env: The library file used as BASH_ENV.

Notes

  • Use shell: bash for steps that rely on BASH_ENV auto-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.

About

Centralizes stderr capture and writes it to a single log file.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages