Last active
May 31, 2024 17:08
-
-
Save jlongman/8261ceaf387c6e3222f5f0ed692d5613 to your computer and use it in GitHub Desktop.
CDK without Tags: awk script to hide Tag-only changes in CDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env | |
# strict mode | |
set -euo pipefail | |
IFS=$'\n\t' | |
# from https://github.com/aws/aws-cdk/issues/25742 | |
# why am i debugging^Wworking in awk | |
format_cdk_diff() { | |
DEBUGGING=$1; | |
awk 'BEGIN{ inTagBlock=0; previousLine=""; debugging='$DEBUGGING'; } | |
{ | |
if (debugging){print "pre " previousLine " / " $0;} | |
if (intTagBlock = 1) { | |
if (debugging){ | |
print "exit? : " (!(previousLine ~ /^ .. \[~] Tags/)) " && \ | |
(" (previousLine ~ /^\[~]/) " || "( previousLine ~ /^ .. \[~]/ )" || "( previousLine == "") ")"; | |
print "why : " previousLine; | |
} | |
if ( \ | |
!(previousLine ~ /^ .. \[~] Tags/) && \ | |
(previousLine ~ /^\[~]/ || previousLine ~ /^ .. \[~]/ || previousLine == "") \ | |
) | |
{ | |
if (debugging){print "exit";} | |
inTagBlock=0; | |
} | |
} | |
if (inTagBlock == 0 && (previousLine ~ /\[~] (AWS|Custom)::/ && $0 ~ /Tags/ || $0 ~ /Tags/ )) | |
{ | |
if (debugging){print "enter";} | |
print previousLine " / " $0; | |
inTagBlock=1; | |
} | |
if (inTagBlock == 0) { | |
if (debugging){ | |
print "show : " previousLine; | |
} else { | |
print previousLine; | |
} | |
} else if (debugging) { | |
print "hide : " previousline; | |
} | |
if (debugging){print "line " inTagBlock " " $0;} | |
previousLine=$0; | |
}' | |
} | |
# actually, permit unset $2 so we can do `all` case | |
set +u | |
DEBUGGING=$1 | |
shift | |
echo '"'$*'"' | |
# note color breaks the matching | |
cdk diff $* 2>&1 >/dev/null | format_cdk_diff $DEBUGGING |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no debug version