Sync runbooks from git

Keep Veirox runbook entities in sync with a git repo. Any commit that changes a file under runbooks/ upserts the entity automatically.

Prerequisites

  • CLI authenticated with entities:write scope.
  • Runbooks stored under a runbooks/ directory in your git repo.

Steps

#!/usr/bin/env bash
# .git/hooks/post-commit
changed=$(git diff-tree --no-commit-id -r --name-only HEAD | grep '^runbooks/')

for file in $changed; do
  [ -f "$file" ] || continue
  slug="$(basename "$file" .md)"
  title="$(head -1 "$file" | sed 's/^# //')"
  echo "[veirox] upserting runbook: $slug"
  veirox entity update --kind runbook --ref "$slug" --body-file "$file" --title "$title" 2>/dev/null     || veirox entity create --kind runbook --slug "$slug" --title "$title" --body-file "$file"
done

Make the hook executable:

chmod +x .git/hooks/post-commit

Common pitfalls

  • Deleted files: add a check with git status --porcelain to handle deleted runbooks and call veirox entity delete.
  • CI pipelines: git hooks don't run in CI. Add an equivalent GitHub Actions step there instead.

See also