docker:
  docker context create docker-container-builder-context
  # see: https://docs.docker.com/build/building/multi-platform/
  # || true: `create` fails if it already exists
  docker buildx create --driver docker-container --name docker-container-builder --bootstrap --use docker-container-builder-context || true
  docker buildx build --cache-to=type=local,dest=./tmp/docker --platform linux/arm64 .

docker-push-gitlab:
  docker context create docker-container-builder-context
  # see: https://docs.docker.com/build/building/multi-platform/
  # || true: `create` fails if it already exists
  docker buildx create --driver docker-container --name docker-container-builder --bootstrap --use docker-container-builder-context || true
  docker buildx build --build-arg CI_PROJECT_PATH=${CI_PROJECT_PATH} --build-arg CI_REGISTRY=${CI_REGISTRY} --cache-to=type=local,dest=./tmp/docker --platform linux/arm64 --push --tag ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHORT_SHA} .

fmt:
  #! /usr/bin/env sh
  set -eu
  if command -v rustup >/dev/null; then rustup toolchain install stable ; fi
  if command -v cargo >/dev/null; then
    cargo fix --all-features --all-targets --allow-dirty --allow-staged --workspace
    cargo fmt
  fi
  if command -v prettier >/dev/null; then prettier --list-different --write .; fi
  if command -v stylua >/dev/null; then stylua .; fi
  if command -v tombi >/dev/null; then tombi format; fi

test:
  #! /usr/bin/env sh
  set -eu
  if command -v rustup >/dev/null; then rustup toolchain install stable ; fi
  if command -v cargo >/dev/null; then
    cargo fmt --check
    cargo clippy --all-features --all-targets --workspace
    cargo test --all-features --all-targets --workspace
  fi
  if command -v alex >/dev/null; then alex ./*.md; fi
  if command -v cargo-audit >/dev/null; then cargo audit; fi
  if command -v cargo-deny >/dev/null; then cargo deny check; fi
  if command -v prettier >/dev/null; then prettier --check .; fi
  if command -v tombi >/dev/null; then tombi format --check; fi
  if command -v tombi >/dev/null; then tombi lint; fi
  if command -v write-good >/dev/null; then write-good ./*.md; fi
