mod bench

# run the local test suite
test:
    zig build test

# run the local endpoint smoke test
smoke:
    tools/smoke.sh

# run the experimental permissioned-data endpoint smoke test
smoke-permissioned:
    tools/smoke-permissioned.sh

# mint an invite code with the configured admin token
invite pds="https://pds.zat.dev" use_count="1" for_account="":
    #!/usr/bin/env bash
    set -euo pipefail
    : "${ZDS_ADMIN_TOKEN:?set ZDS_ADMIN_TOKEN to the configured PDS admin token}"
    if [[ -n "{{for_account}}" ]]; then
      body="$(jq -nc --argjson useCount "{{use_count}}" --arg forAccount "{{for_account}}" '{useCount:$useCount,forAccount:$forAccount}')"
    else
      body="$(jq -nc --argjson useCount "{{use_count}}" '{useCount:$useCount}')"
    fi
    curl -fsS "{{pds}}/xrpc/com.atproto.server.createInviteCode" \
      -H "authorization: Bearer $ZDS_ADMIN_TOKEN" \
      -H 'content-type: application/json' \
      --data "$body" |
    jq -r '.code'

# repair an existing account's PLC rotation set from the local database
plc-repair did:
    zig build plc-repair -- {{did}}

# build the container image locally
docker-build tag="latest" platform="linux/amd64" arch="amd64":
    DOCKER_BUILDKIT=1 docker build --platform {{platform}} --build-arg TARGETARCH={{arch}} --build-arg ZDS_VERSION={{tag}} -t zds:{{tag}} .

# publish the container image to atcr.io
docker-publish tag="latest" platform="linux/amd64" arch="amd64":
    DOCKER_BUILDKIT=1 docker build --platform {{platform}} --build-arg TARGETARCH={{arch}} --build-arg ZDS_VERSION={{tag}} -t zds:{{tag}} .
    docker tag zds:{{tag}} atcr.io/zat.dev/zds:{{tag}}
    docker push atcr.io/zat.dev/zds:{{tag}}

# publish latest plus the current git commit tag
docker-publish-current:
    just docker-publish latest
    just docker-publish $(git rev-parse --short=12 HEAD)

# publish latest, a semver tag, and the current git commit tag
docker-publish-release version:
    just docker-publish {{version}}
    just docker-publish latest
    just docker-publish $(git rev-parse --short=12 HEAD)
