Adding resources to charm promotion 70/12770/1 v13.0.0rc2
authorMark Beierl <mark.beierl@canonical.com>
Thu, 8 Dec 2022 15:24:53 +0000 (10:24 -0500)
committerbeierlm <mark.beierl@canonical.com>
Thu, 8 Dec 2022 17:55:18 +0000 (18:55 +0100)
Some charms have resources, and others, like prometheus have
multiple resources.  This change takes those resources into
account when promothing charms

Change-Id: I0ecb3634e379e5f1eb7036dadb591d73db773099
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
(cherry picked from commit 4a9860409030d08ad8371f89885d66a8bab66f09)

jenkins/ci-pipelines/ci_stage_3.groovy

index 70f350f..620faba 100644 (file)
@@ -704,9 +704,23 @@ EOF"""
                                 withCredentials([string(credentialsId: 'Charmstore', variable: 'CHARMCRAFT_AUTH')]) {
                                     sh "charmcraft status $charm --format json > ${charm}.json"
                                     isCharm = sh(returnStdout: true, script: "grep architecture ${charm}.json | wc -l").trim() as int
+                                    resourceArgument = ""
                                     if (isCharm) {
                                         jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .version'|head -1"
                                         jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/beta\")| .version'|head -1"
+                                        index=0
+                                        while (index < 5) {
+                                            resourceNameScript = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .resources[$index].name'|head -1"
+                                            resourceRevsScript = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .resources[$index].revision'|head -1"
+                                            resourceName = sh(returnStdout: true, script: resourceNameScript).trim()
+                                            resourceRevs = sh(returnStdout: true, script: resourceRevsScript).trim()
+                                            if (resourceName != "null") {
+                                                resourceArgument += " --resource ${resourceName}:${resourceRevs}"
+                                            } else {
+                                                break
+                                            }
+                                            index ++
+                                        }
                                     } else {
                                         jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"$channel/edge/merged\")| .version'|head -1"
                                         jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"$channel/beta\")| .version'|head -1"
@@ -717,12 +731,12 @@ EOF"""
                                     try { edge_rev = edge_rev as int } catch (NumberFormatException nfe) {edge_rev = 0}
                                     try { beta_rev = beta_rev as int } catch (NumberFormatException nfe) {beta_rev = 0}
 
-                                    print "Edge: $edge_rev, Beta: $beta_rev"
+                                    print "Edge: $edge_rev, Beta: $beta_rev $resourceArgument"
 
                                     if (edge_rev > beta_rev) {
                                         print "Promoting $edge_rev to beta in place of $beta_rev"
                                         beta_track = channel + 'beta'
-                                        sh "charmcraft release ${charm} --revision=${edge_rev} --channel=${channel}/beta"
+                                        sh "charmcraft release ${charm} --revision=${edge_rev}  ${resourceArgument} --channel=${channel}/beta"
                                     }
 
                                 }