1414
1515exceptions=" docs/pingora-dependency-exceptions.tsv"
1616out_dir=" ${FLUXHEIM_PINGORA_POLICY_DIR:- target/ release-evidence/ pingora-dependency-policy} "
17+ current_version=" ${FLUXHEIM_PINGORA_POLICY_VERSION:- $(sed -n ' s/^version = "\([^"]*\)"/\1/p' Cargo.toml | sed -n ' 1p' )} "
1718
1819if [ ! -f " $exceptions " ]; then
1920 echo " pingora dependency policy: missing $exceptions " >&2
@@ -55,24 +56,40 @@ capture_tree() {
5556 esac
5657}
5758
59+ extract_pingora_crates () {
60+ profile=" $1 "
61+ tree_file=" $out_dir /cargo-tree/$profile .txt"
62+ matches_file=" $out_dir /cargo-tree/$profile .pingora-matches.txt"
63+
64+ if grep -Eo ' pingora[-_a-z]* v[0-9][^ )]*' " $tree_file " > " $matches_file " ; then
65+ sed ' s/ v/\t/' " $matches_file " \
66+ | sort -u \
67+ | while IFS=" $( printf ' \t' ) " read -r crate version; do
68+ printf ' %s\t%s\t%s\n' " $profile " " $crate " " $version "
69+ done
70+ else
71+ status=" $? "
72+ if [ " $status " -ne 1 ]; then
73+ echo " pingora dependency policy: failed to inspect $tree_file " >&2
74+ exit " $status "
75+ fi
76+ fi
77+ }
78+
5879profiles=" default full cache-edge proxy-edge load-balancer-edge php privacy"
5980current_tsv=" $out_dir /current.tsv"
6081current_keys=" $out_dir /current.keys"
6182exception_keys=" $out_dir /exceptions.keys"
6283unexpected=" $out_dir /unexpected.keys"
6384stale=" $out_dir /stale-exceptions.keys"
85+ expired=" $out_dir /expired-exceptions.tsv"
6486
6587{
6688 printf ' profile\tcrate\tversion\n'
6789 for profile in $profiles ; do
6890 echo " pingora dependency policy: cargo tree $profile " >&2
6991 capture_tree " $profile "
70- grep -Eo ' pingora[-_a-z]* v[0-9][^ )]*' " $out_dir /cargo-tree/$profile .txt" \
71- | sed ' s/ v/\t/' \
72- | sort -u \
73- | while IFS=" $( printf ' \t' ) " read -r crate version; do
74- printf ' %s\t%s\t%s\n' " $profile " " $crate " " $version "
75- done || true
92+ extract_pingora_crates " $profile "
7693 done
7794} > " $current_tsv "
7895
@@ -93,6 +110,54 @@ awk -F '\t' '
93110comm -23 " $current_keys " " $exception_keys " > " $unexpected "
94111comm -13 " $current_keys " " $exception_keys " > " $stale "
95112
113+ awk -F ' \t' -v current_version=" $current_version " -v current_keys=" $current_keys " '
114+ function compare_version(left, right, left_parts, right_parts, i) {
115+ sub(/^v/, "", left)
116+ sub(/^v/, "", right)
117+ split(left, left_parts, /[^0-9]+/)
118+ split(right, right_parts, /[^0-9]+/)
119+ for (i = 1; i <= 3; i++) {
120+ if (left_parts[i] !~ /^[0-9]+$/ || right_parts[i] !~ /^[0-9]+$/) {
121+ return "invalid"
122+ }
123+ if ((left_parts[i] + 0) < (right_parts[i] + 0)) {
124+ return -1
125+ }
126+ if ((left_parts[i] + 0) > (right_parts[i] + 0)) {
127+ return 1
128+ }
129+ }
130+ return 0
131+ }
132+ BEGIN {
133+ while ((getline key < current_keys) > 0) {
134+ current[key] = 1
135+ }
136+ close(current_keys)
137+ if (compare_version(current_version, "0.0.0") == "invalid") {
138+ print "pingora dependency policy: invalid current version " current_version > "/dev/stderr"
139+ exit 2
140+ }
141+ }
142+ /^[[:space:]]*#/ { next }
143+ NF == 0 { next }
144+ $1 == "profile" { next }
145+ NF < 4 { next }
146+ {
147+ key = $1 "\t" $2
148+ if (key in current) {
149+ comparison = compare_version(current_version, $3)
150+ if (comparison == "invalid") {
151+ print "pingora dependency policy: invalid removal_target " $3 " for " key > "/dev/stderr"
152+ exit 2
153+ }
154+ if (comparison >= 0) {
155+ print $1 "\t" $2 "\t" $3
156+ }
157+ }
158+ }
159+ ' " $exceptions " | sort -u > " $expired "
160+
96161if [ -s " $unexpected " ]; then
97162 echo " pingora dependency policy: unexpected Pingora crates:" >&2
98163 cat " $unexpected " >&2
@@ -103,7 +168,12 @@ if [ -s "$stale" ]; then
103168 cat " $stale " >&2
104169fi
105170
106- if [ " $mode " = " check" ] && { [ -s " $unexpected " ] || [ -s " $stale " ]; }; then
171+ if [ -s " $expired " ]; then
172+ echo " pingora dependency policy: expired Pingora exceptions still present for Fluxheim $current_version :" >&2
173+ cat " $expired " >&2
174+ fi
175+
176+ if [ " $mode " = " check" ] && { [ -s " $unexpected " ] || [ -s " $stale " ] || [ -s " $expired " ]; }; then
107177 exit 1
108178fi
109179
0 commit comments