---
name: run_steps
kind: function
lang: bash
domain: shell
version: "1.0.0"
purity: impure
signature: "run_steps(yaml_file: string, [--strict]) -> string"
description: "Ejecuta pasos de un YAML generico donde cada step tiene action=command. Lee el YAML con yq, ejecuta cada paso secuencialmente con timeout configurable, captura exit code y output, respeta continue_on_error, y al final reporta JSON estandar a stdout via report_execution_json. Sale con exit code 0 (success), 1 (failure) o 2 (partial). Con --strict mapea partial a failure."
tags: [execution, yaml, runner, standard, pipeline]
uses_functions: [exit_with_status_bash_shell, report_execution_json_bash_shell]
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
params:
  - name: yaml_file
    desc: "archivo YAML con especificación de pasos"
  - name: --strict
    desc: "flag opcional para mapear partial a failure"
output: "JSON de ejecución con detalles de cada paso"
tested: false
tests: []
test_file_path: ""
file_path: "bash/functions/shell/run_steps.sh"
---

## Ejemplo

```yaml
# /tmp/test_flow.yaml
name: test_flow
steps:
  - name: check
    action: command
    command: "echo hello"
  - name: list
    action: command
    command: "ls /tmp"
    continue_on_error: true
  - name: slow_step
    action: command
    command: "sleep 2"
    timeout_ms: 1000
    continue_on_error: true
```

```bash
source bash/functions/shell/run_steps.sh

run_steps /tmp/test_flow.yaml
# Imprime JSON a stdout:
# {
#   "name": "test_flow",
#   "status": "partial",
#   "exit_code": 2,
#   "started_at": "2026-04-01T10:00:00Z",
#   "ended_at": "2026-04-01T10:00:01Z",
#   "duration_ms": 1250,
#   "steps_total": 3,
#   "steps_ok": 2,
#   "steps_failed": 1,
#   "steps": [
#     {"name": "check", "action": "command", "status": "ok", "elapsed_ms": 10, "output": "hello"},
#     {"name": "list", "action": "command", "status": "ok", "elapsed_ms": 15},
#     {"name": "slow_step", "action": "command", "status": "error", "elapsed_ms": 1001, "error": "timeout: comando excedio 1000ms"}
#   ]
# }
# Sale con exit code 2 (partial)

run_steps /tmp/test_flow.yaml --strict
# Igual pero status="failure" y exit code=1
```

## Notas

Requiere `yq` (v4+, modo expression `-e`) y `jq` (o la implementacion printf de report_execution_json). Solo soporta `action: command` — otros actions se marcan como error del paso. El campo `timeout_ms` por defecto es 30000 (30s); si el comando excede el timeout, `timeout(1)` sale con exit code 124 y se registra el error correspondiente. El output del comando (stdout+stderr combinados) se sanitiza reemplazando tabuladores y saltos de linea por espacios antes de escribir al TSV temporal. Las funciones `exit_with_status` y `report_execution_json` se cargan via `source` desde el mismo directorio que `run_steps.sh`.
