Use highest base for charms 68/13668/1
authorMark Beierl <mark.beierl@canonical.com>
Wed, 12 Jul 2023 18:06:04 +0000 (14:06 -0400)
committerMark Beierl <mark.beierl@canonical.com>
Wed, 12 Jul 2023 18:06:04 +0000 (14:06 -0400)
Updates to check if the charm being promoted uses 22.04 as its base, and promote that
one instead of 20.04

Change-Id: Ia5e34419729b1a2969eb4c10981aeeecc76fe544
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
tools/promote-charms-and-snaps.sh

index a83001d..1ace0dc 100755 (executable)
@@ -59,16 +59,25 @@ for charm in \
     echo "${charm}"
 
     charmcraft status $charm --format json > ${charm}.json
-    isCharm=$(grep architecture ${charm}.json | wc -l)
+    isCharm=$(grep architecture ${charm}.json | wc -l 2>/dev/null)
     resourceArgument=""
 
     if [ $isCharm -gt 0 ]; then
-        SOURCE_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .version"|head -1)
-        TARGET_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$CHANNEL/$TARGET\")| .version"|head -1)
+        base=20.04
+        is2204=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"22.04\")"|wc -l)
+        if [ $is2204 -gt 0 ]; then
+            base=22.04
+        fi
+
+
+        SOURCE_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .version"|head -1)
+        TARGET_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$TARGET\")| .version"|head -1)
+
+
         index=0
         while [ $index -lt 5 ]; do
-            resourceName=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].name"|head -1)
-            resourceRevs=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].revision"|head -1)
+            resourceName=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].name"|head -1)
+            resourceRevs=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].revision"|head -1)
             if [ "$resourceName" != "null" ] ; then
                 resourceArgument=" $resourceArgument --resource ${resourceName}:${resourceRevs}"
             else