Skip to content

Replace curl+bash API layer with zad-cli#41

Merged
anneschuth merged 8 commits into
mainfrom
feat/use-zad-cli
Apr 7, 2026
Merged

Replace curl+bash API layer with zad-cli#41
anneschuth merged 8 commits into
mainfrom
feat/use-zad-cli

Conversation

@anneschuth

Copy link
Copy Markdown
Member

Summary

  • All ZAD API interactions (retry, polling, payload building) now use zad-cli instead of raw curl+bash
  • Removes scripts/zad-common.sh (124 lines) - retry logic, task polling, URL building now handled by the CLI
  • Net reduction: ~310 lines of duplicated bash code
  • GitHub-specific logic (bot detection, PR comments, QR codes, env/deployment/container cleanup) unchanged

What changed per action

Action Before After
deploy ~200 lines curl/jq/polling Single zad deployment create call
cleanup ~80 lines curl/polling Single zad deployment delete --ignore-not-found call
scheduled-cleanup Same inline curl/polling Same zad deployment delete call

How it works

Each action gets a new "Install zad-cli" step (pipx install) before the ZAD API step. The CLI picks up configuration via env vars:

  • ZAD_API_KEY, ZAD_API_URL, ZAD_PROJECT_ID (existing)
  • ZAD_TASK_TIMEOUT, ZAD_TASK_POLL_INTERVAL (new in CLI)
  • ZAD_MAX_RETRIES, ZAD_RETRY_DELAY (new in CLI)

Dependencies

Requires RijksICTGilde/zad-cli with the env var support for retry/timeout settings (already merged to main).

Test plan

  • Test deploy action with single component
  • Test deploy action with multi-component
  • Test deploy action with clone-from
  • Test cleanup action (deployment exists)
  • Test cleanup action (deployment already deleted - 404)
  • Test scheduled-cleanup dry-run
  • Verify URL extraction produces identical outputs
  • Verify error messages on auth failure

🤖 Generated with Claude Code

@uittenbroekrobbert

Copy link
Copy Markdown
Collaborator

I like this. The CLI makes 'local' commands easier; and keeping the logic in one place (now the CLI) means the action can just be 'a wrapper'. So, LGTM! Go! :)

Replace all ZAD API interactions (curl_with_retry, poll_task,
build_poll_url, payload building) with zad-cli calls. The CLI
handles retry logic, task polling, and error handling identically.

- deploy: ~200 lines of curl/jq/polling replaced by single CLI call
- cleanup: ~80 lines of curl/polling replaced by single CLI call
- scheduled-cleanup: same ZAD delete logic replaced by CLI call
- Remove scripts/zad-common.sh (124 lines, now redundant)

GitHub-specific logic (bot detection, PR comments, QR codes,
environment/deployment/container cleanup) unchanged.

Net reduction: ~310 lines of duplicated bash.
- Structured error reporting: parse CLI JSON status_code for specific
  ::error:: annotations (401/403/404/5xx), matching original messages
- Add scripts/zad-error.sh helper for deploy action error reporting
- Remove zad_stderr.txt temp file usage: CLI JSON errors go to stdout
  in --output json mode, so stderr redirect was reading the wrong stream
- Restore domain_format subdomain-requires-subdomain validation in
  deploy action (not covered by CLI validation)
- Use uv for installation (faster, consistent with project tooling)
- Install from main without version pin (both repos under same team)
- Consolidate zad-error.sh into zad-common.sh with install_zad_cli,
  report_zad_error, and zad_delete_deployment functions
- All three actions now use the same shared functions (DRY)
- cleanup and scheduled-cleanup use zad_delete_deployment instead
  of duplicated inline error parsing
- Replace curl|sh uv install with pip install (available on all
  GitHub runners, no external script execution)
- Remove zad-error.sh (merged into zad-common.sh)
Install from a specific version tag (v0.1.1) instead of unpinned
main to prevent breaking changes from affecting all workflows.
Switch from pip to uv (faster, consistent with project tooling).
- Restore input validation (project-id, deployment-name, component
  names, numeric inputs, domain inputs) before logging to prevent
  injection. Extracted validate_input and validate_integer helpers
  to zad-common.sh for reuse across all three actions.
- Handle non-JSON CLI output in report_zad_error (crashes, missing
  binary, Python tracebacks no longer produce misleading messages).
- Check install_zad_cli exit code and verify zad is in PATH.
- Reset DELETE_RESULT/DELETE_REASON at start of zad_delete_deployment
  to prevent stale values when called in a loop.
- Use ::warning:: (not ::error::) for cleanup delete failures to
  match the original best-effort behavior.
- Add astral-sh/setup-uv@v6 step before zad-cli install (uv is not
  pre-installed on GitHub runners)
- Add $HOME/.local/bin to GITHUB_PATH so zad is available across steps
- Change validate_input/validate_integer from return 1 to exit 1
  (without set -e, return 1 was silently ignored)
- Add missing validate_input for project-id in scheduled-cleanup
- Improve error message for CLI failures with no HTTP status code
- Update CHANGELOG.md with full PR scope
Use `uv tool bin` instead of broken `uv tool dir/../bin` fallback,
and make PATH export consistent with whichever branch fires.

Count not_found deployments as successfully cleaned in scheduled-cleanup
since a missing deployment is already clean.
@anneschuth anneschuth merged commit 6d555f2 into main Apr 7, 2026
8 checks passed
@anneschuth anneschuth deleted the feat/use-zad-cli branch April 7, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants