Skip to content

Commit db5d54e

Browse files
author
Sergio Schvezov
authored
commands: cosmetic fixes to promote-bundle (#1094)
Make channel parameters options instead of positional arguments and display what was done at the end (which also gets rid of an upload artifact left over from the last progress message). Signed-off-by: Sergio Schvezov <[email protected]>
1 parent a0e8233 commit db5d54e

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

charmcraft/commands/store/__init__.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,25 @@ class PromoteBundleCommand(BaseCommand):
793793
"""
794794
Promote a bundle to another channel in the Store.
795795
796-
797-
""" # TODO (amlowe): complete this description.
796+
This command must be run from the bundle project directory to be
797+
promoted.
798+
"""
798799
)
799800

800801
def fill_parser(self, parser: "ArgumentParser") -> None:
801802
"""Add promote-bundle parameters to the general parser."""
802-
parser.add_argument("from_channel", help="The channel from which to promote the bundle")
803-
parser.add_argument("to_channel", help="The target channel for the promoted bundle")
803+
parser.add_argument(
804+
"--from-channel",
805+
type=SingleOptionEnsurer(str),
806+
required=True,
807+
help="The channel from which to promote the bundle",
808+
)
809+
parser.add_argument(
810+
"--to-channel",
811+
type=SingleOptionEnsurer(str),
812+
required=True,
813+
help="The target channel for the promoted bundle",
814+
)
804815
parser.add_argument(
805816
"--output-bundle",
806817
type=pathlib.Path,
@@ -996,7 +1007,14 @@ def run(self, parsed_args: "Namespace") -> None:
9961007

9971008
# Upload the bundle and release it to the target channel.
9981009
store.upload(bundle_name, zipname)
999-
store.release(bundle_name, bundle_revision, [parsed_args.to_channel], [])
1010+
release_info = store.release(bundle_name, bundle_revision, [parsed_args.to_channel], [])
1011+
1012+
# There should only be one revision.
1013+
release_info = release_info["released"][0]
1014+
emit.message(
1015+
f"Created revision {release_info['revision']!r} and "
1016+
f"released it to the {release_info['channel']!r} channel"
1017+
)
10001018

10011019

10021020
class CloseCommand(BaseCommand):

charmcraft/commands/store/store.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,16 @@ def list_revisions(self, name):
347347
return result
348348

349349
@_store_client_wrapper()
350-
def release(self, name: str, revision: int, channels: List[str], resources):
350+
def release(self, name: str, revision: int, channels: List[str], resources) -> Dict[str, Any]:
351351
"""Release one or more revisions for a package."""
352352
endpoint = "/v1/charm/{}/releases".format(name)
353353
resources = [{"name": res.name, "revision": res.revision} for res in resources]
354354
items = [
355355
{"revision": revision, "channel": channel, "resources": resources}
356356
for channel in channels
357357
]
358-
self._client.request_urlpath_json("POST", endpoint, json=items)
358+
359+
return self._client.request_urlpath_json("POST", endpoint, json=items)
359360

360361
@_store_client_wrapper()
361362
def list_releases(self, name: str) -> Tuple[List[Release], List[Channel], List[Revision]]:

tests/spread/store/bundle-upload-and-release/task.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ execute: |
7373
if [[ $old_beta_revision != null ]]; then # If there's no beta revision, skip this check.
7474
test $old_beta_revision -le $edge_revision
7575
fi
76-
charmcraft promote-bundle latest/edge latest/beta
76+
charmcraft promote-bundle --from-channel latest/edge --to-channel latest/beta
7777
beta_release=$(charmcraft status $BUNDLE_DEFAULT_NAME --format=json | jq -r '.[] | select(.track=="latest") | .mappings[0].releases | .[] | select(.channel=="latest/beta")')
7878
beta_revision=$(echo $beta_release | jq -r .revision)
7979
test $beta_revision -ge $edge_revision

0 commit comments

Comments
 (0)