diff --git a/scripts/shared/filter_dependabot.sh b/scripts/shared/filter_dependabot.sh new file mode 100755 index 000000000..23ef88def --- /dev/null +++ b/scripts/shared/filter_dependabot.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +declare -a seendeps + +function depseen() { + local dep + for dep in "${seendeps[@]}"; do + if [ "$dep" = "$1" ]; then + return 0 + fi + done + return 1 +} + +base="$(pwd)" +conffile="${base}/.github/dependabot.yml" + +for dir in $(yq '(.updates[] | select(.package-ecosystem == "gomod")).directory' "$conffile"); do + + (cd "${base}${dir}" || exit + + # Remove the existing ignores + yq -i '(.updates[] | select(.package-ecosystem == "gomod") | select(.directory == "'"$dir"'")).ignore = []' "$conffile" + + # Restore the submariner-io exclusion + yq -i '(.updates[] | select(.package-ecosystem == "gomod") | select(.directory == "'"$dir"'")).ignore[0].dependency-name = "github.com/submariner-io/*"' "$conffile" + yq -i '(.updates[] | select(.package-ecosystem == "gomod") | select(.directory == "'"$dir"'")).ignore[0] head_comment = "Our own dependencies are handled during releases"' "$conffile" + + # Ignore all parent dependencies + for parent in $(GOWORK=off go list -m -mod=mod -json all | jq -r 'select(.Path | contains("/submariner-io/")) | select(.Main != true) .Path | gsub("github.com/submariner-io/"; "")'); do + first=true + for dep in $(GOWORK=off go list -m -mod=mod -json all | jq -r 'select(.Path | contains("/submariner-io") | not) | select(.Indirect != true) | select(.Main != true) .Path'); do + if ! depseen "$dep"; then + if grep -q "$dep" "$base/../$parent/go.mod"; then + yq -i -P '(.updates[] | select(.package-ecosystem == "gomod") | select(.directory == "'"$dir"'")).ignore += { "dependency-name": "'"$dep"'" }' "$conffile" + if $first; then + yq -i -P 'with(.updates[] | select(.package-ecosystem == "gomod") | select(.directory == "'"$dir"'"); .ignore[.ignore | length - 1] head_comment = "Managed in '"$parent"'")' "$conffile" + first=false + fi + seendeps+=("$dep") + fi + fi + done + done) + +done