#!/bin/sh
# Captures what the helm-diff plugin (v3.15.15) prints for chart/ at values-b.yaml against the
# release in seed.yaml (the chart at values-a.yaml), with the memory driver: no cluster is used.
# Usage: ./capture-helm-diff.sh <private-plugins-dir>   (must not be your own HELM_PLUGINS)
set -eu
plugins=$1
home=$(mktemp -d)
here=$(cd "$(dirname "$0")" && pwd)
export HELM_PLUGINS=$plugins HELM_CONFIG_HOME=$home/config HELM_CACHE_HOME=$home/cache \
  HELM_DATA_HOME=$home/data KUBECONFIG=/nonexistent HELM_DRIVER=memory \
  HELM_MEMORY_DRIVER_DATA=$here/seed.yaml HELM_NAMESPACE=shop NO_COLOR=1
mkdir -p "$here/helm-diff"
cd "$here"

capture() {
  name=$1
  shift
  helm diff upgrade web ./chart -f values-b.yaml --disable-validation --no-color "$@" \
    > "helm-diff/$name.txt"
}

capture default
capture show-secrets --show-secrets
capture decoded-context --show-secrets-decoded --context 1
capture suppress --suppress Secret --suppress Deployment
capture include-tests --include-tests
capture no-hooks --no-hooks
capture context-0 --context 0
capture normalize --normalize-manifests
helm diff upgrade web ./chart -f values-b.yaml --disable-validation --output structured \
  > helm-diff/structured.json
rm -rf "$home"
