VERSION --wait-block 0.7

# images builds all container images in the Repository
images:
    ARG CONTAINER_REGISTRY=quay.io/shivering-isles
    BUILD +images-earthly --CONTAINER_REGISTRY=${CONTAINER_REGISTRY}

images-src:
    FROM quay.io/fedora/fedora:39
    COPY images/ ./images

images-earthly:
    FROM +images-src
    ARG CONTAINER_REGISTRY=quay.io/shivering-isles
    FOR dir IN $(find ./images -type d -execdir test -f {}/Earthfile -a \! -e {}/.skip-earthly \; -print)
        BUILD "${dir}+container" --registry="$CONTAINER_REGISTRY/$(basename ${dir})"
    END

# changelog generates a local RELEASENOTES.md file using git-chglog
changelog:
  FROM quay.io/git-chglog/git-chglog:0.15.4
  COPY . /src
  WORKDIR /src
  RUN git-chglog --template .chglog/unreleased.tpl.md --next-tag "v$(date +%y.%m)" --output RELEASENOTES.md
  SAVE ARTIFACT RELEASENOTES.md AS LOCAL RELEASENOTES.md

# merge allows to merge branches in the origin remote, this helps to keep everything signed
merge:
    LOCALLY
    ARG --required branch
    RUN git fetch
    RUN git merge --no-ff origin/${branch} --no-edit
    RUN git push
    RUN git push origin --delete ${branch}

# rotate will rotate encryption keys in sops-encrypted files
rotate:
    LOCALLY
    RUN grep -Ril "sops:" ./**/*.yaml | xargs sops -r -i

# enable-autoupdates enables the fedora autoupdating form the system-upgrades namespace
enable-autoupdates:
    LOCALLY
    ARG --required node
    RUN kubectl label node "${node}" upgrade.shivering-isles.com/fedora-autoupdate=true

# vale-lint runs vale linting on documentation
vale-lint:
    FROM ./images/tools+vale
    RUN apk add --no-cache hunspell-en
    WORKDIR /src
    COPY .vale.ini .vale /src/
    COPY . /src
    ARG alertlevel=suggestion
    RUN vale --minAlertLevel=$alertlevel ./docs

# vale-sync runs a new vale sync locally
vale-sync:
    FROM ./images/tools+vale
    WORKDIR /src
    COPY .vale.ini /src
    RUN vale sync
    SAVE ARTIFACT ./.vale AS LOCAL .vale

# docs runs a local mdbook instance using koolbox that will listen on localhost:3000
docs:
    WAIT
        BUILD ./images/koolbox+install
    END
    LOCALLY
    RUN koolbox mdbook serve docs

docs-lint:
    BUILD +vale-lint --alertlevel=error

docs-build:
    FROM ./images/tools+mdbook
    COPY . .
    RUN mdbook build docs
    SAVE ARTIFACT ./docs/book AS LOCAL ./docs/book

renovate-lint:
    DO ./shared/earthly+RENOVATE_LINT