_default:
    @just --list

# Build CI image locally and update hash in workflows
ci_image:
   #!/usr/bin/env bash
   just ci_build_tar /tmp/ci.tar
   IMAGE=$(crane digest --tarball /tmp/ci.tar)
   echo digest $IMAGE
   ./scripts/bump_ci_image_hash_workflows.py --filter ci --skip ci_image_test.yaml,ci_image.yaml $IMAGE

# Dowload crane binary from the image
get_crane:
    docker create --name temp_container gcr.io/go-containerregistry/crane@sha256:fc86bcad43a000c2a1ca926a1e167db26c053cebc3fa5d14285c72773fb8c11d  # latest at 2025-04-14
    docker cp temp_container:/ko-app/crane crane
    docker rm temp_container

# build CI image into a tar file
ci_build_tar output:
    umask 002
    chmod 0600 ci_image/*
    docker buildx rm mybuilder || :
    docker buildx create --name mybuilder --driver docker-container --use
    cd ci_image && SOURCE_DATE_EPOCH=0 docker buildx build --progress=plain --no-cache --provenance=false -o type=docker,dest={{ output }},rewrite-timestamp=true .

# Show image difference, you need locally installed diffoscope
ci_diffoscope:
    just ci_build_tar /tmp/one.tar
    just ci_build_tar /tmp/two.tar
    diffoscope --html /tmp/report.html --output-empty /tmp/one.tar /tmp/two.tar

# build documentation
docs:
    ansible-galaxy collection install . --force
    rm -rf built-docs
    mkdir built-docs/
    chmod 0700  built-docs
    antsibull-docs sphinx-init --use-current --squash-hierarchy lidofinance.server --dest-dir built-docs
    mkdir -p built-docs/rst
    chmod og-w built-docs/rst
    cd built-docs && antsibull-docs --config-file antsibull-docs.cfg collection --cleanup everything --use-current --squash-hierarchy --dest-dir rst lidofinance.server --fail-on-error
    # cd built-docs && antsibull-docs --config-file antsibull-docs.cfg collection --cleanup everything --use-current --squash-hierarchy --dest-dir rst lidofinance.server --squash-hierarchy
    cd built-docs && sphinx-build -M html rst build -c . -W --keep-going

# tests that show that image for CI is sound and working
ci_image_tests:
    ansible --version
    antsibull-docs --version
    ansible-galaxy collection list
    echo "foo" > /tmp/inventory
    pytest --collect-only tests/ --ansible-inventory=/tmp/inventory
    molecule list
    poetry env activate
