The manual
Everything ela does, in its own words.
The language, its packages, the shell, the editors and the agent guide, one page per section. It is the text the binary carries: ela --spec jobs in a terminal prints the part this site has at /docs/jobs/.
Spreadsheets as tables
A spreadsheet's export made into a table with typed columns, sorted by a comparator passed by name, filtered with where, shown a page at a time and written back as CSV; every field is text until types says otherwise. A one-line for makes a list of its rows, when keeping some, and sum adds one up. See Tables in the manual.
# report.ela: the open orders from a spreadsheet's export,# largest first, back out as CSV.# Run as: ela report.ela orders.csv FILE :: $args[0] # A table of the export, Excel's ; and byte order mark both# fine. Every field is text until types says otherwise, so a# postcode 01234 stays one.rows = csv.decode(file.read($FILE), sep = ";")orders = table.of($rows, header = true, types = {"amount": Type.NUMBER, "paid": Type.BOOL}) # The largest first, by a comparator passed by name; then# the unpaid ones, in that order.proc largest_first(a, b) -> (before: bool) return $a["amount"] > $b["amount"]end proc largest = table.sort($orders, by = largest_first)open = table.filter($largest, where = {"paid": false}) # Twenty rows a page for the terminal, and every open order# for the spreadsheet.for p in table.pages($open, size = 20) echo "page ${$p.page + 1} of $p.pages" for row in $p; echo " $row['region'] $row['amount']"end forfile.write("open.csv", csv.encode($open)) # A list from a loop, and its sum: what is owed, and who# owes more than 100.owed = for r in $open; $r["amount"]large = for r in $open when $r["amount"] > 100; $r["region"]echo "owed ${list.sum($owed)}, \ over 100 in ${str.join($large, ", ")}"Environment and secrets
Defaults for unset variables, a block with its own environment, and a token from the keyring that reaches docker through a pipe, never an argument. See Keyring in the manual.
# publish.ela: push an image with a token kept in the# keyring, never in a file or an argument.# Store the token once, typed unseen, at the prompt:# keyring.store("registry")# Run as: ela publish.ela # $env.NAME is an error when NAME is not set; env.get gives# a default instead.registry = env.get("REGISTRY", "registry.example")tag = "$registry/app:${env.get("TAG", "latest")}" # A variable the caller's shell set, removed: docker talks# to the local daemon.env.DOCKER_HOST = null # For one block only: the variables go back as they were at# end with, however it ends.with env.DOCKER_BUILDKIT = "1", env.SOURCE_DATE_EPOCH = $(git log -1 --format=%ct) docker build -t $tag .end with # The secret is read from the desktop keyring; every message# shows it as <secret>.token = $keyring.registry# It reaches docker through a pipe: ps and /proc/PID/cmdline# show only /dev/fd/N.fd = secret_file($token)docker login --username ci --password-stdin $registry < $fddocker push $tagA block with its own folder, environment and time
A release built in its own folder, with its own LANG and a time limit read from a config file, all in one with; the folder and the variable come back at end with, and a build that runs past the limit is ended there. See with in the manual.
# release.ela: build a release in its own folder, with its# own environment and a time limit.# Run as: ela release.ela 1.4.0 VERSION :: $args[0]limit = toml.decode(file.read("release.toml"))["timeout"] # The folder, a variable and a time limit, for these lines# only; all put back at end with, however the block ends.# Past the limit, the build is ended and the script# stops here.with dir "build", env.LANG = "C", time.block = $limit cmake -DCMAKE_BUILD_TYPE=Release .. make -j $(nproc) tar -czf "app-${VERSION}.tar.gz" append with # Back in the folder the script started in.dir.create("dist")mv build/app-${VERSION}.tar.gz dist/echo "dist/app-${VERSION}.tar.gz built"Clean-up and failed jobs
A restart on every host at once: catch run takes each failed restart while the wait goes on with the others, catch signal takes Ctrl-C, and a defer takes the markers away however the script ends. See catch in the manual.
# rollout.ela: restart a service on every host at once, and# say which hosts failed.# Run as: ela rollout.ela hosts.txt hosts = str.fields(file.read($args[0]))failed = [] proc restart(host: string) -> (state: string) ssh $host sudo systemctl restart app return $(ssh $host systemctl is-active app)end proc # A marker on each host while the rollout runs, taken away# however the script ends.for h in $hosts; ssh $h touch /run/app.rolloutdefer for h in $hosts; ssh $h rm -f /run/app.rolloutend defer jobs = []for h in $hosts; jobs = list.append($jobs, run restart($h))wait $jobs # A failed restart is taken here, once for each, and the# wait goes on with the others.catch run restart failed = list.append($failed, $job) warn "$job failed with $code"end catch # Ctrl-C or kill while the lines above run: the block, then# the defer.catch signal INT TERM; warn "rollout stopped"; exit 130 restarted = len($hosts) - len($failed)echo "$restarted of ${len($hosts)} hosts restarted"