Skip to content

Commit

Permalink
added support to create package alias #200
Browse files Browse the repository at this point in the history
  • Loading branch information
boussaffawalid committed Jun 18, 2020
1 parent 470db2b commit 6b790df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ Check [Conan Build policies](https://docs.conan.io/en/latest/mastering/policies.
- **force_selinux**: Force docker to relabel file objects on the shared volumes
- **skip_recipe_export**: If True, the package recipe will only be exported on the first build. Default [False]
- **update_dependencies**: Update all dependencies before building e.g conan create -u
- **version_alias**: Create a version alias for created packages. For example: if CPT_VERSION_ALIAS=latest, the package alias pkg_name/latest@user/channel will be created.

Upload related parameters:

Expand Down Expand Up @@ -1287,7 +1288,7 @@ Check [Conan Build policies](https://docs.conan.io/en/latest/mastering/policies.
- **CONAN_FORCE_SELINUX**: Force docker to relabel file objects on the shared volumes
- **CONAN_SKIP_RECIPE_EXPORT**: If defined, the package recipe will only be exported on the first build.
- **CPT_UPDATE_DEPENDENCIES**: Update all dependencies before building e.g conan create -u

- **CPT_VERSION_ALIAS**: Create a version alias for created packages. For example: if CPT_VERSION_ALIAS=latest, the package alias pkg_name/latest@user/channel will be created.

# Full example

Expand Down
10 changes: 7 additions & 3 deletions cpt/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def __init__(self, username=None, channel=None, runner=None,
force_selinux=None,
skip_recipe_export=False,
update_dependencies=None,
lockfile=None):
lockfile=None,
version_alias=None):

conan_version = get_client_version()

Expand Down Expand Up @@ -205,6 +206,7 @@ def __init__(self, username=None, channel=None, runner=None,
self.partial_reference = reference or os.getenv("CONAN_REFERENCE", None)
self.channel = self._get_specified_channel(channel, reference)
self.conanfile = conanfile or os.getenv("CONAN_CONANFILE", "conanfile.py")
self.version_alias = version_alias or os.getenv("CPT_VERSION_ALIAS", None)

if self.partial_reference:
if "@" in self.partial_reference:
Expand Down Expand Up @@ -683,7 +685,8 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None):
conanfile=self.conanfile,
lockfile=self.lockfile,
skip_recipe_export=skip_recipe_export,
update_dependencies=self.update_dependencies)
update_dependencies=self.update_dependencies,
version_alias = self.version_alias)
r.run()
self._packages_summary.append({"configuration": build, "package" : r.results})
else:
Expand Down Expand Up @@ -718,7 +721,8 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None):
lockfile=self.lockfile,
force_selinux=self.force_selinux,
skip_recipe_export=skip_recipe_export,
update_dependencies=self.update_dependencies)
update_dependencies=self.update_dependencies,
version_alias = self.version_alias)

r.run(pull_image=not pulled_docker_images[docker_image],
docker_entry_script=self.docker_entry_script)
Expand Down
11 changes: 9 additions & 2 deletions cpt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, profile_abs_path, reference, conan_api, uploader,
cwd=None, printer=None, upload=False, upload_only_recipe=None,
test_folder=None, config_url=None, config_args=None,
upload_dependencies=None, conanfile=None, skip_recipe_export=False,
update_dependencies=False, lockfile=None):
update_dependencies=False, lockfile=None, version_alias=None):

self.printer = printer or Printer()
self._cwd = cwd or os.getcwd()
Expand Down Expand Up @@ -48,6 +48,7 @@ def __init__(self, profile_abs_path, reference, conan_api, uploader,
self.skip_recipe_export = skip_recipe_export
self._update_dependencies = update_dependencies
self._results = None
self._version_alias = version_alias

patch_default_base_profile(conan_api, profile_abs_path)
client_version = get_client_version()
Expand Down Expand Up @@ -154,6 +155,10 @@ def run(self):
else:
self._uploader.upload_packages(reference,
self._upload, package_id)
if self._version_alias:
reference_alias = reference.replace(installed["recipe"]["version"], self._version_alias)
self._conan_api.export_alias(reference_alias, reference)
self._uploader.upload_recipe(reference_alias, self._upload)
else:
self.printer.print_message("Skipping upload for %s, "
"it hasn't been built" % package_id)
Expand Down Expand Up @@ -182,7 +187,8 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
force_selinux=None,
skip_recipe_export=False,
update_dependencies=False,
lockfile=None):
lockfile=None,
latest_alias=None):

self.printer = printer or Printer()
self._upload = upload
Expand Down Expand Up @@ -217,6 +223,7 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
self._force_selinux = force_selinux
self._skip_recipe_export = skip_recipe_export
self._update_dependencies = update_dependencies
self._latest_alias = latest_alias

def _pip_update_conan_command(self):
commands = []
Expand Down

0 comments on commit 6b790df

Please sign in to comment.