-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsort-layers.sh
64 lines (55 loc) · 1.95 KB
/
sort-layers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Script to sort the layers and classify profiles by layers
#
set -eu
set -o pipefail
CHART_DIR=./charts/
CT_CONFIG=ct.yaml
charts=$(ls -d $CHART_DIR/*)
#Added to clear config for runner
rm -rf /tmp/layer*
touch /tmp/layers
for dir in $charts; do
if [[ $(yq e '.annotations."weave.works/layer"' $dir/Chart.yaml) != "null" ]]; then
echo $(yq e '.annotations."weave.works/layer"' $dir/Chart.yaml) >> /tmp/layers
fi
done
sort /tmp/layers | uniq > /tmp/layers-sorted
cat /tmp/platforms | while read platform || [[ -n $platform ]];
do
#Added to clear config for runner
rm -rf /tmp/$platform*
cat /tmp/layers-sorted | while read layer || [[ -n $layer ]];
do
echo Platform: $platform Layer: $layer
for dir in $charts; do
if [[ $(yq e '.annotations."weave.works/profile-ci"|contains("'$platform'")' $dir/Chart.yaml) = "true" ]] && $(yq e '.annotations."weave.works/layer"|contains("'$layer'")' $dir/Chart.yaml) = "true" ]]; then
echo $dir >> /tmp/$layer-$platform
fi
done
done
done
changed=$(ct list-changed --config $CT_CONFIG)
echo $changed
cat /tmp/platforms | while read platform || [[ -n $platform ]];
do
touch /tmp/$platform-top-layer-changed
for dir in $changed; do
echo Found changed: $dir
if [[ $(yq e '.annotations."weave.works/profile-ci"|contains("'$platform'")' $dir/Chart.yaml) = "true" ]]; then
layer=$(yq e '.annotations."weave.works/layer"' $dir/Chart.yaml)
top=$(cat /tmp/$platform-top-layer-changed)
echo $dir >> /tmp/$layer-$platform-changed
echo "::set-output name=$platform-ci::true"
# checks if the layer is not set and skips if it is not
if [[ "$layer" != "null" ]]; then
if [[ $top = "" || "$top" < "$layer" ]]; then
echo "$layer is lexicographically greater then $top."
echo $layer > /tmp/$platform-top-layer-changed
fi
fi
fi
done
echo top layer changed
cat /tmp/$platform-top-layer-changed
done