diff --git a/experiment/print-job-image-summary.sh b/experiment/print-job-image-summary.sh new file mode 100755 index 000000000000..dac26c7ca6ec --- /dev/null +++ b/experiment/print-job-image-summary.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Copyright 2021 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# a silly script to audit how many jobs are using which images for prow.k8s.io + +set -o errexit +set -o nounset +set -o pipefail + +script_root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) +repo_root=$(cd ${script_root}/.. && pwd) +jobs_dir="${1:-${repo_root}/config/jobs}" + +# NOTE: assumes ripgrep +if ! command -v rg >/dev/null; then + echo "please install ripgrep" >&2 + exit 1 +fi + +function images() { + rg --no-filename --iglob "*.yaml" image: "${jobs_dir}" | sed -e 's|.*image: ||' | sort | cut -d: -f 1 +} + +function image_include_exclude() { + local include="${1}" + local exclude="${2}" + local debug="${3:-false}" + echo "$(images | grep -Ev "${exclude}" | grep -Ec "${include}") total, $(images | uniq | grep -Ev "${exclude}" | grep -Ec "${include}") unique" + if ${debug}; then + images | uniq | grep -Ev "${exclude}" | grep -E "${include}" + fi +} + +cat <