|
| 1 | +# Shellflow |
| 2 | + |
| 3 | +A minimal shell script orchestrator with SSH support. Shellflow allows you to write shell scripts that execute across local and remote environments using simple comment markers. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Block-based execution**: Use comment markers to define local and remote execution blocks |
| 8 | +- **SSH support**: Automatically reads SSH configuration from `~/.ssh/config` |
| 9 | +- **Fail-fast execution**: Stops on first error with clear error reporting |
| 10 | +- **Context passing**: The previous block output is passed via `SHELLFLOW_LAST_OUTPUT` |
| 11 | +- **CLI interface**: Simple command-line tool for running scripts |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +# Install the package and dependencies |
| 17 | +uv sync --all-groups |
| 18 | + |
| 19 | +# Install in development mode |
| 20 | +uv pip install -e . |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Writing Scripts |
| 26 | + |
| 27 | +Shellflow scripts use comment markers to define execution blocks: |
| 28 | + |
| 29 | +```bash |
| 30 | +# @LOCAL |
| 31 | +echo "Running locally" |
| 32 | + |
| 33 | +# @REMOTE myserver |
| 34 | +echo "Running on myserver" |
| 35 | + |
| 36 | +# @LOCAL |
| 37 | +echo "Back to local" |
| 38 | +``` |
| 39 | + |
| 40 | +### Running Scripts |
| 41 | + |
| 42 | +```bash |
| 43 | +# Run a script |
| 44 | +shellflow run script.sh |
| 45 | + |
| 46 | +# Run with verbose output |
| 47 | +shellflow run script.sh --verbose |
| 48 | +shellflow run script.sh -v |
| 49 | + |
| 50 | +# Use a non-default SSH config file |
| 51 | +shellflow run script.sh --ssh-config ./ssh_config |
| 52 | +``` |
| 53 | + |
| 54 | +### SSH Configuration |
| 55 | + |
| 56 | +Shellflow reads SSH configuration from `~/.ssh/config`. The following options are supported: |
| 57 | + |
| 58 | +```ssh |
| 59 | +Host myserver |
| 60 | + HostName 192.168.1.100 |
| 61 | + User admin |
| 62 | + Port 2222 |
| 63 | + IdentityFile ~/.ssh/myserver_key |
| 64 | +``` |
| 65 | + |
| 66 | +If `paramiko` is installed, it will be used for parsing. Otherwise, a basic parser is used as fallback. |
| 67 | + |
| 68 | +### Execution Model |
| 69 | + |
| 70 | +Blocks are intentionally stateless. Shell state such as `cd`, shell variables, and `export` commands do not persist into the next block. If you need to pass data forward, use the previous block output via `SHELLFLOW_LAST_OUTPUT`: |
| 71 | + |
| 72 | +```bash |
| 73 | +# @LOCAL |
| 74 | +echo "Step 1 output" |
| 75 | + |
| 76 | +# @LOCAL |
| 77 | +echo "Previous output was: $SHELLFLOW_LAST_OUTPUT" |
| 78 | +``` |
| 79 | + |
| 80 | +Lines before the first marker, such as a shebang or shared shell options, are prepended to every block. That lets you define common guardrails once: |
| 81 | + |
| 82 | +```bash |
| 83 | +#!/bin/bash |
| 84 | +set -euo pipefail |
| 85 | + |
| 86 | +# @LOCAL |
| 87 | +echo "runs with the shared prelude" |
| 88 | + |
| 89 | +# @REMOTE myserver |
| 90 | +echo "remote block gets the same prelude" |
| 91 | +``` |
| 92 | + |
| 93 | +## Testing |
| 94 | + |
| 95 | +### Unit Tests (pytest) |
| 96 | + |
| 97 | +Run unit tests with pytest: |
| 98 | + |
| 99 | +```bash |
| 100 | +# Run all tests |
| 101 | +just test |
| 102 | + |
| 103 | +# Run specific test file |
| 104 | +uv run pytest tests/test_shellflow.py |
| 105 | + |
| 106 | +# Run with coverage |
| 107 | +uv run pytest --cov=shellflow --cov-report=term-missing |
| 108 | +``` |
| 109 | + |
| 110 | +### BDD Tests (behave) |
| 111 | + |
| 112 | +Run acceptance tests with behave: |
| 113 | + |
| 114 | +```bash |
| 115 | +# Run BDD tests |
| 116 | +just bdd |
| 117 | + |
| 118 | +# Or directly |
| 119 | +uv run behave |
| 120 | +``` |
| 121 | + |
| 122 | +### Running All Tests |
| 123 | + |
| 124 | +```bash |
| 125 | +# Run format, lint, test, and BDD |
| 126 | +just test-all |
| 127 | +``` |
| 128 | + |
| 129 | +## Development Commands |
| 130 | + |
| 131 | +```bash |
| 132 | +just format # Format code with ruff |
| 133 | +just lint # Lint with ruff |
| 134 | +just test # Run pytest |
| 135 | +just bdd # Run behave BDD tests |
| 136 | +just test-all # Run format, lint, test, and bdd |
| 137 | +just typecheck # Type check with ty |
| 138 | +``` |
| 139 | + |
| 140 | +## Project Structure |
| 141 | + |
| 142 | +```text |
| 143 | +shellflow/ |
| 144 | +├── src/shellflow.py # Main module |
| 145 | +├── tests/ # Unit tests |
| 146 | +├── features/ # BDD feature files |
| 147 | +│ ├── parser.feature |
| 148 | +│ └── runner.feature |
| 149 | +├── pyproject.toml # Project configuration |
| 150 | +└── README.md |
| 151 | +``` |
| 152 | + |
| 153 | +## CLI Reference |
| 154 | + |
| 155 | +```text |
| 156 | +shellflow run <script> # Run a shellflow script |
| 157 | +shellflow run <script> -v # Run with verbose output |
| 158 | +shellflow --version # Show version |
| 159 | +``` |
| 160 | + |
| 161 | +## License |
| 162 | + |
| 163 | +Apache-2.0 |
0 commit comments