Skip to content

Commit 0bf3cc0

Browse files
authored
store: fix issues with promote-bundle command (#1089)
No new tests because this fixes breakage of a spread test that wasn't running properly
1 parent 689acee commit 0bf3cc0

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

.github/workflows/spread.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ jobs:
9494
name: Run spread
9595
env:
9696
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
97-
CHARM_DEFAULT_NAME: charmcraft-ci-test-charm
98-
BUNDLE_DEFAULT_NAME: charmcraft-ci-test-bundle
97+
CHARM_DEFAULT_NAME: test-ci-charmcraft-charm
98+
BUNDLE_DEFAULT_NAME: test-ci-charmcraft-bundle
9999
run: |
100100
spread google:ubuntu-22.04-64:tests/spread/store/
101101

charmcraft/commands/store/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -966,17 +966,17 @@ def run(self, parsed_args: "Namespace") -> None:
966966
)
967967

968968
# Export a temporary bundle file with the charms in the target channel
969-
with tempfile.TemporaryDirectory() as bundle_dir:
970-
bundle_dir_path = pathlib.Path(bundle_dir)
971-
shutil.copy(self.config.project_dir, bundle_dir_path)
969+
with tempfile.TemporaryDirectory(prefix="charmcraft-") as bundle_dir:
970+
bundle_dir_path = pathlib.Path(bundle_dir) / bundle_name
971+
shutil.copytree(self.config.project.dirpath, bundle_dir_path)
972972
bundle_path = bundle_dir_path / "bundle.yaml"
973973
with bundle_path.open("w+") as bundle_file:
974974
yaml.dump(bundle_config, bundle_file)
975975

976976
# Pack the bundle using the modified bundle file
977977
emit.verbose(f"Packing temporary bundle in {bundle_dir}...")
978978
lifecycle = parts.PartsLifecycle(
979-
bundle_config,
979+
{},
980980
work_dir=bundle_dir_path / "build",
981981
project_dir=bundle_dir_path,
982982
project_name=bundle_name,
@@ -991,12 +991,12 @@ def run(self, parsed_args: "Namespace") -> None:
991991
from charmcraft.manifest import create_manifest
992992

993993
create_manifest(lifecycle.prime_dir, self.config.project.started_at, None, [])
994-
zipname = self.config.project.dirpath / (bundle_name + ".zip")
994+
zipname = bundle_dir_path / (bundle_name + ".zip")
995995
build_zip(zipname, lifecycle.prime_dir)
996996

997997
# Upload the bundle and release it to the target channel.
998-
store.upload(self.config.name, bundle_path)
999-
store.release(self.config.name, bundle_revision, parsed_args.to_channel, [])
998+
store.upload(bundle_name, zipname)
999+
store.release(bundle_name, bundle_revision, [parsed_args.to_channel], [])
10001000

10011001

10021002
class CloseCommand(BaseCommand):

charmcraft/commands/store/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def list_revisions(self, name):
347347
return result
348348

349349
@_store_client_wrapper()
350-
def release(self, name, revision, channels, resources):
350+
def release(self, name: str, revision: int, channels: List[str], resources):
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]

spread.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,6 @@ suites:
169169
# to not flood Charmhub with names the same two are always used in the Store related
170170
# tests (except in the names registration tests, of course); register them manually
171171
# in staging Charmhub authenticating with the configured credentials
172-
CHARM_DEFAULT_NAME: "$(HOST: echo ${SPREAD_CHARM_NAME:-$USER-test-charm})"
173-
BUNDLE_DEFAULT_NAME: "$(HOST: echo ${SPREAD_BUNDLE_NAME:-$USER-test-bundle})"
172+
CHARM_DEFAULT_NAME: "$(HOST: echo ${CHARM_DEFAULT_NAME:-$USER-test-charm})"
173+
BUNDLE_DEFAULT_NAME: "$(HOST: echo ${BUNDLE_DEFAULT_NAME:-$USER-test-bundle})"
174174

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ prepare: |
3030
3131
# If necessary, try to register the bundle.
3232
if ! charmcraft status $BUNDLE_DEFAULT_NAME; then
33-
if ! charmcraft register $BUNDLE_DEFAULT_NAME; then
33+
if ! charmcraft register-bundle $BUNDLE_DEFAULT_NAME; then
3434
ERROR Charm $BUNDLE_DEFAULT_NAME cannot be registered to this account.
3535
fi
3636
fi
@@ -70,7 +70,9 @@ execute: |
7070
# Test promotion to beta
7171
beta_release=$(charmcraft status $BUNDLE_DEFAULT_NAME --format=json | jq -r '.[] | select(.track=="latest") | .mappings[0].releases | .[] | select(.channel=="latest/beta")')
7272
old_beta_revision=$(echo $beta_release | jq -r .revision)
73-
test $old_beta_revision -le $edge_revision
73+
if [[ $old_beta_revision != null ]]; then # If there's no beta revision, skip this check.
74+
test $old_beta_revision -le $edge_revision
75+
fi
7476
charmcraft promote-bundle latest/edge latest/beta
7577
beta_release=$(charmcraft status $BUNDLE_DEFAULT_NAME --format=json | jq -r '.[] | select(.track=="latest") | .mappings[0].releases | .[] | select(.channel=="latest/beta")')
7678
beta_revision=$(echo $beta_release | jq -r .revision)

0 commit comments

Comments
 (0)