v0.3.2

Documentation version

v0.2.4v0.3.2
en

Documentation language

en

Search documentation

ESC

Documentation search

What are you working on?

Find a guide, configuration option, action, or ESH topic.

Browse documentation
DocsAutomation recipes

Automation recipes

These recipes cover common automation tasks: waiting for a service, reading project data, preparing a release, and running independent checks. Each recipe builds on patterns from the earlier ESH guides.

Start only when the service is ready

if ! wait_port 5432 30s; then
  echo "Database did not start" >&2
  exit 1
fi
diesel migration run

Give a recovering service another chance

retry -n 5 -d 2s http GET http://localhost:8080/health || {
  echo "Service health check failed" >&2
  exit 1
}

Let project data drive the script

VERSION="$(json -g version package.json)"
yaml -j config.yaml > config.json
echo "Building version $VERSION"

Let independent work move together

{
  cargo fmt --check &| \
  cargo clippy --all-targets -- -D warnings &| \
  cargo test
} || {
  echo "Failure at line $ESH_FAILED_LINE: $ESH_FAILED_CMD" >&2
  exit 1
}

Leave no temporary work behind

TEMP="$(mktemp -d)"
trap "rm -rf '$TEMP'" EXIT
cp -r ./src "$TEMP/"

Bring a release preflight into one script

The following script combines project data, parallel checks, cleanup, an archive, and a checksum. It still requires Cargo and sha256sum to be installed. ESH runs those external commands but does not provide their toolchains.

#!/usr/bin/env esh

set -e
VERSION="$(json -g version package.json)"
TEMP="$(mktemp -d)"
trap "rm -rf '$TEMP'" EXIT

{
  cargo fmt --check &| \
  cargo clippy --all-targets -- -D warnings &| \
  cargo test
} || {
  echo "Preflight failed in $ESH_FAILED_CMD at line $ESH_FAILED_LINE" >&2
  exit 1
}

mkdir -p ./dist
cargo build --release
cp ./target/release/app ./dist/app
archive "$TEMP/app-$VERSION.zip" ./dist
sha256sum "$TEMP/app-$VERSION.zip" > "./dist/app-$VERSION.zip.sha256"
cp "$TEMP/app-$VERSION.zip" "./dist/app-$VERSION.zip"
echo "Ready: ./dist/app-$VERSION.zip"

Next: consult the ESH Runtime Reference for individual command contracts or configure editor support.

Page source: book/esh/50.automation-recipes.md