From ecc34d81407ec7f70dd4eb6431903d9233d630d6 Mon Sep 17 00:00:00 2001 From: Stefano Lusardi Date: Tue, 6 Aug 2024 00:40:34 +0200 Subject: [PATCH] Enable Conan package creation and Artifactory upload on CI. --- README.md | 2 +- ci/build.yml | 26 ++++++++++++-------------- scripts/conan/create.py | 3 ++- scripts/conan/upload.py | 15 ++++++++++++++- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 452a422..ceb021e 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ Now it is possible to create and upload a Conan package with the following comma python scripts/conan/create.py # Upload the package to Artifactory on the teicare remote -python scripts/conan/upload.py teiacare teiacare_video_io/@ +python scripts/conan/upload.py teiacare teiacare_video_io ``` diff --git a/ci/build.yml b/ci/build.yml index 2d5d72f..a212ec5 100644 --- a/ci/build.yml +++ b/ci/build.yml @@ -238,17 +238,15 @@ jobs: env: CONAN_USER_HOME: $(Build.SourcesDirectory) - # This step is disabled because we need to align all the settings in the conanfile.py (used to build our package) with the conanfile.txt that we use to consume FFmpeg. - - # - script: | - # $(ACTIVATE_VIRTUAL_ENV) - # $(SETUP_BUILD_ENV) - # conan config set general.revisions_enabled=0 - # conan remote add teiacare $(artifactory.url)/teiacare - # conan user $(artifactory.username) -p $(artifactory.password) -r teiacare - # python3 scripts/conan/create.py ${{BUILD_TYPE}} $(COMPILER) $(COMPILER_VERSION) - # python3 scripts/conan/upload.py teiacare teiacare_video_io/0.1.0@ - # displayName: 'Create Conan Package' - # timeoutInMinutes: 5 - # env: - # CONAN_USER_HOME: $(Build.SourcesDirectory) + - script: | + $(ACTIVATE_VIRTUAL_ENV) + $(SETUP_BUILD_ENV) + conan config set general.revisions_enabled=0 + conan remote add teiacare $(artifactory.url)/teiacare + conan user $(artifactory.username) -p $(artifactory.password) -r teiacare + python3 scripts/conan/create.py ${{BUILD_TYPE}} $(COMPILER) $(COMPILER_VERSION) + python3 scripts/conan/upload.py teiacare teiacare_video_io + displayName: 'Create Conan Package' + timeoutInMinutes: 5 + env: + CONAN_USER_HOME: $(Build.SourcesDirectory) diff --git a/scripts/conan/create.py b/scripts/conan/create.py index 71470d0..a6fdae7 100644 --- a/scripts/conan/create.py +++ b/scripts/conan/create.py @@ -31,7 +31,8 @@ def conan_create(conanfile_directory, profile_path, build_type): '--settings', f'build_type={build_type}', '--profile:build', f'{profile_path}', '--profile:host', f'{profile_path}', - '--build', 'missing' + '--build', 'missing', + '--test-folder', 'None' # TODO: remove this line once test_package is working properly ] run(command) diff --git a/scripts/conan/upload.py b/scripts/conan/upload.py index 4f471d2..afdf7ed 100644 --- a/scripts/conan/upload.py +++ b/scripts/conan/upload.py @@ -18,6 +18,16 @@ import pathlib import sys import os +import re + +def get_project_version(): + with open('VERSION', encoding='utf8') as version_file: + version_regex = r'^\d+\.\d+\.\d+$' + version = version_file.read().strip() + if re.match(version_regex, version): + return version + else: + raise ValueError(f"Invalid version detected into file VERSION: {version}") def setup_conan_home(): current_working_directory = pathlib.Path().resolve() @@ -39,6 +49,9 @@ def run(command): print(f'Unhandled Exception: {e}') def conan_create(remote_name, package_name, force): + package_version = get_project_version() + print(f'{package_name}/{package_version}') + command = [ 'conan', 'upload', @@ -46,7 +59,7 @@ def conan_create(remote_name, package_name, force): '--confirm', '--parallel', '--remote', remote_name, - package_name + f'{package_name}/{package_version}@' ] if force: