Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow upload --list to accept empty lists #14254

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions conan/cli/commands/upload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conan.api.conan_api import ConanAPI
from conan.api.model import ListPattern, MultiPackagesList
from conan.api.output import cli_out_write
from conan.api.output import cli_out_write, ConanOutput
from conan.cli import make_abs_path
from conan.cli.command import conan_command, OnceArgument
from conan.cli.commands.list import print_list_json, print_serial
Expand Down Expand Up @@ -81,24 +81,28 @@ def upload(conan_api: ConanAPI, parser, *args):
ref_pattern = ListPattern(args.pattern, package_id="*", only_recipe=args.only_recipe)
package_list = conan_api.list.select(ref_pattern, package_query=args.package_query)

if not package_list.recipes:
if package_list.recipes:
if args.check:
conan_api.cache.check_integrity(package_list)
# Check if the recipes/packages are in the remote
conan_api.upload.check_upstream(package_list, remote, args.force)

# If only if search with "*" we ask for confirmation
if not args.list and not args.confirm and "*" in args.pattern:
_ask_confirm_upload(conan_api, package_list)

conan_api.upload.prepare(package_list, enabled_remotes, args.metadata)

if not args.dry_run:
conan_api.upload.upload(package_list, remote)
conan_api.upload.upload_backup_sources(package_list)
elif args.list:
# Don't error on no recipes for automated workflows using list,
# but warn to tell the user that no packages were uploaded
ConanOutput().warning(f"No packages were uploaded because the package list is empty.")
else:
raise ConanException("No recipes found matching pattern '{}'".format(args.pattern))
n-morales marked this conversation as resolved.
Show resolved Hide resolved

if args.check:
conan_api.cache.check_integrity(package_list)
# Check if the recipes/packages are in the remote
conan_api.upload.check_upstream(package_list, remote, args.force)

# If only if search with "*" we ask for confirmation
if not args.list and not args.confirm and "*" in args.pattern:
_ask_confirm_upload(conan_api, package_list)

conan_api.upload.prepare(package_list, enabled_remotes, args.metadata)

if not args.dry_run:
conan_api.upload.upload(package_list, remote)
conan_api.upload.upload_backup_sources(package_list)

pkglist = MultiPackagesList()
pkglist.add(remote.name, package_list)
return {
Expand Down
6 changes: 6 additions & 0 deletions conans/test/integration/command/upload/upload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def test_pattern_upload(self):
assert "Uploading recipe 'hello0/1.2.1@" in client.out
assert "Uploading package 'hello0/1.2.1@" in client.out

def test_pattern_upload_no_recipes(self):
client = TestClient(default_server_user=True)
client.save({"conanfile.py": conanfile})
client.run("upload bogus/*@dummy/testing --confirm -r default", assert_error=True)
self.assertIn("No recipes found matching pattern 'bogus/*@dummy/testing'", client.out)

def test_broken_sources_tgz(self):
# https://github.com/conan-io/conan/issues/2854
client = TestClient(default_server_user=True)
Expand Down
13 changes: 13 additions & 0 deletions conans/test/integration/command_v2/test_combined_pkglist_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ def test_list_upload_packages(self, client):
assert f"Uploading recipe '{r}'" in client.out
assert str(client.out).count("Uploading package") == 2

def test_list_upload_empty_list(self, client):
client.run(f"install --requires=zlib/1.0.0@user/channel -f json",
redirect_stdout="install_graph.json")

# Generate an empty pkglist.json
client.run(f"list --format=json --graph=install_graph.json --graph-binaries=bogus",
redirect_stdout="pkglist.json")

# No binaries should be uploaded since the pkglist is empty, but the command
# should not error
client.run("upload --list=pkglist.json -r=default")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
assert "No packages were uploaded because the package list is empty." in client.out


class TestGraphCreatedUpload:
def test_create_upload(self):
Expand Down