Skip to content

Instantly share code, notes, and snippets.

@stepan-anokhin
Last active November 21, 2022 08:53
Show Gist options
  • Save stepan-anokhin/4640acfb3519f0be0b099fbc62a31a7b to your computer and use it in GitHub Desktop.
Save stepan-anokhin/4640acfb3519f0be0b099fbc62a31a7b to your computer and use it in GitHub Desktop.
Find Argo Template References
# Find template references in the given file
function find-refs-in-file() {
local file="$1"
local workflow="$2"
local template="$3"
local query=".. | select(type==\"object\") | .templateRef | select(.name==\"$workflow\") | select(.template==\"$template\")"
if ! cat "$file" | yq "$query"; then
echo "ERROR: $1" 1>&2;
fi
}
# Select workflow templates files, potentially
# containing references to the given workflow template
function sel() {
grep -lP "name:\s+([\"']?)$1" -R . | grep -v node_modules | grep yaml
}
# Find references to the given template in the current directory
function refs() {
local workflow="$1"
local template="$2"
local pattern="template:\s+['\"]?$template"
for file in $(sel "$workflow"); do
if [ ! -z "$(find-refs-in-file "$file" "$workflow" "$template")" ]; then
echo $file:$(grep -nP "$pattern" $file) | grep -P "$pattern";
fi;
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment