#!/usr/bin/env bash # Uso: scripts/plano-imagem.sh # Imprime inputs=, image= e reuse= (para $GITHUB_OUTPUT). O hash cobre só os # arquivos que entram no build da imagem, não a documentação nem a configuração # de ferramentas. reuse=true quando o registro já tem inputs-. set -euo pipefail registry=$1; ns=${2,,} inputs=$(git ls-tree -r HEAD \ | awk -F'\t' '$2 !~ /^(\.gitea|\.github|\.claude|\.superset|docs)\// && $2 !~ /^(README.*|CLAUDE\.md|DESIGN\.md|LICENSE|\.gitignore|CHANGELOG\.md|scripts\/release-notes\.sh)$/' \ | sha256sum | cut -c1-16) token=$(curl -fsS "https://$registry/v2/token?service=container_registry&scope=repository:$ns:pull" | jq -r .token) code=$(curl -s -o /dev/null -w '%{http_code}' -I \ -H "Authorization: Bearer $token" \ -H 'Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.oci.image.manifest.v1+json' \ "https://$registry/v2/$ns/manifests/inputs-$inputs") echo "inputs-$inputs -> HTTP $code" >&2 reuse=false; [ "$code" = 200 ] && reuse=true echo "inputs=$inputs" echo "image=$registry/$ns" echo "reuse=$reuse"