Automation should separate planning from applying changes. A dry-run branch shows the command that would run without allowing real changes.

Program

Play the script to switch between dry-run and apply mode.

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

mode="dry-run"
target="staging"
if [[ "$mode" == "dry-run" ]]; then
    command="printf preview:$target"
    effect="no-change"
else
    command="deploy --target $target"
    effect="changes-allowed"
fi
echo "$mode $effect $command"
#!/usr/bin/env bash

mode="apply"
target="staging"
if [[ "$mode" == "dry-run" ]]; then
    command="printf preview:$target"
    effect="no-change"
else
    command="deploy --target $target"
    effect="changes-allowed"
fi
echo "$mode $effect $command"
  1. mode ← dry-run

    3mode="dry-run"4target="staging"
    values this stepdry-runmode
  2. target ← staging

    3mode="dry-run"4target="staging"5if [[ "$mode" == "dry-run" ]]; then
    values this stepstagingtarget
  3. if [[ "$mode" == "dry-run" ]]; then

    4target="staging"5if [[ "$mode" == "dry-run" ]]; then6    command="printf preview:$target"
    values this stepdry-runmode
  4. command ← printf preview:staging

    5if [[ "$mode" == "dry-run" ]]; then6    command="printf preview:$target"7    effect="no-change"
    values this stepprintf preview:stagingcommandstagingtarget
  5. effect ← no-change

    6    command="printf preview:$target"7    effect="no-change"8else
    values this stepno-changeeffect
  6. echo "$mode $effect $command"

    11fi12echo "$mode $effect $command"
    outputdry-run no-change printf preview:staging
    values this stepdry-runmodeno-changeeffectprintf preview:stagingcommand
  1. mode ← apply

    3mode="apply"4target="staging"
    values this stepapplymode
  2. target ← staging

    3mode="apply"4target="staging"5if [[ "$mode" == "dry-run" ]]; then
    values this stepstagingtarget
  3. if [[ "$mode" == "dry-run" ]]; then

    4target="staging"5if [[ "$mode" == "dry-run" ]]; then6    command="printf preview:$target"
    values this stepapplymode
  4. command ← deploy --target staging

    8else9    command="deploy --target $target"10    effect="changes-allowed"
    values this stepdeploy --target stagingcommandstagingtarget
  5. effect ← changes-allowed

    9    command="deploy --target $target"10    effect="changes-allowed"11fi
    values this stepchanges-allowedeffect
  6. echo "$mode $effect $command"

    11fi12echo "$mode $effect $command"
    outputapply changes-allowed deploy --target staging
    values this stepapplymodechanges-allowedeffectdeploy --target stagingcommand
dry run A dry run reports intent without applying changes.
apply mode Apply mode is the branch that would permit changes.
command plan Keeping the command as data makes the selected action inspectable.