A capstone script should make the intended amount of work visible before it runs. This example builds a bounded task plan from a fixed list.

Program

Play the script to choose how many automation steps are planned for the run.

task_count
automation_task_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash

task_count=3
completed=0
plan=""
for task in lint test publish docs cleanup; do
    if [[ "$completed" -ge "$task_count" ]]; then
        break
    fi
    completed=$((completed + 1))
    plan="${plan}${task} "
done
summary="${plan% }"
echo "planned=$completed steps=$summary"
#!/usr/bin/env bash

task_count=5
completed=0
plan=""
for task in lint test publish docs cleanup; do
    if [[ "$completed" -ge "$task_count" ]]; then
        break
    fi
    completed=$((completed + 1))
    plan="${plan}${task} "
done
summary="${plan% }"
echo "planned=$completed steps=$summary"
  1. task_count ← 3

    3task_count=34completed=0
    values this step3task_count
  2. completed ← 0

    3task_count=34completed=05plan=""
    values this step0completed
  3. plan ← (empty)

    4completed=05plan=""6for task in lint test publish docs cleanup; do
    values this step(empty)plan
  4. completed ← 1

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step0 1completedlinttask
  5. plan ← lint

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this step(empty) lint planlinttask
  6. completed ← 2

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step1 2completedtesttask
  7. plan ← lint test

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this steplint lint test plantesttask
  8. completed ← 3

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step2 3completedpublishtask
  9. plan ← lint test publish

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this steplint test lint test publish planpublishtask
  10. if [[ "$completed" -ge "$task_count" ]]; then

    6for task in lint test publish docs cleanup; do7    if [[ "$completed" -ge "$task_count" ]]; then8        break
    values this stepdocstask3completed3task_count
  11. summary ← lint test publish

    12done13summary="${plan% }"14echo "planned=$completed steps=$summary"
    values this steplint test publishsummarylint test publish plan
  12. echo "planned=$completed steps=$summary"

    13summary="${plan% }"14echo "planned=$completed steps=$summary"
    outputplanned=3 steps=lint test publish
    values this step3completedlint test publishsummary
  1. task_count ← 5

    3task_count=54completed=0
    values this step5task_count
  2. completed ← 0

    3task_count=54completed=05plan=""
    values this step0completed
  3. plan ← (empty)

    4completed=05plan=""6for task in lint test publish docs cleanup; do
    values this step(empty)plan
  4. completed ← 1

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step0 1completedlinttask
  5. plan ← lint

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this step(empty) lint planlinttask
  6. completed ← 2

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step1 2completedtesttask
  7. plan ← lint test

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this steplint lint test plantesttask
  8. completed ← 3

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step2 3completedpublishtask
  9. plan ← lint test publish

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this steplint test lint test publish planpublishtask
  10. completed ← 4

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step3 4completeddocstask
  11. plan ← lint test publish docs

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this steplint test publish lint test publish docs plandocstask
  12. completed ← 5

    9fi10completed=$((completed + 1))11plan="${plan}${task} "
    values this step4 5completedcleanuptask
  13. plan ← lint test publish docs cleanup

    10    completed=$((completed + 1))11    plan="${plan}${task} "12done
    values this steplint test publish docs lint test publish docs cleanup plancleanuptask
  14. summary ← lint test publish docs cleanup

    12done13summary="${plan% }"14echo "planned=$completed steps=$summary"
    values this steplint test publish docs cleanupsummarylint test publish docs cleanup plan
  15. echo "planned=$completed steps=$summary"

    13summary="${plan% }"14echo "planned=$completed steps=$summary"
    outputplanned=5 steps=lint test publish docs cleanup
    values this step5completedlint test publish docs cleanupsummary
capstone plan A capstone automation script should expose the steps it intends to run.
work bound A numeric bound keeps a script from doing more work than intended.
plan summary A compact summary makes the selected steps easy to review.