Skip to content

Commit

Permalink
Merge branch 'release/0.23.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Jan 31, 2019
2 parents e2f2243 + ce73ddb commit 06f959a
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .ci/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ if [[ "$(uname -s)" == 'Darwin' ]]; then
pyenv install 3.6.0
pyenv virtualenv 3.6.0 conan
;;
py37)
pyenv install 3.7.1
pyenv virtualenv 3.7.1 conan
;;

esac
pyenv rehash
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ python:
- 2.7
- 3.6
os: linux
sudo: required
dist: trusty
dist: xenial

matrix:
include:
Expand Down
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,23 @@ Use the `remove_build_if` helper with a lambda function to filter configurations


from cpt.packager import ConanMultiPackager

builder = ConanMultiPackager(username="myuser")
builder.add_common_builds()
builder.remove_build_if(lambda build: build.settings["compiler.version"] == "4.6" and settings["build_type"] == "Debug")
builder.remove_build_if(lambda build: build.settings["compiler.version"] == "4.6" and build.settings["build_type"] == "Debug")

Use the `update_build_if` helper with a lambda function to alter configurations:


from cpt.packager import ConanMultiPackager

builder = ConanMultiPackager(username="myuser")
builder.add_common_builds()
builder.update_build_if(lambda build: build.settings["os"] == "Windows",
new_build_requires={"*": ["7zip_installer/0.1.0@conan/stable"]})
# Also avaiable parameters:
# new_settings, new_options, new_env_vars, new_build_requires, new_reference
# Also avaiable parameters:
# new_settings, new_options, new_env_vars, new_build_requires, new_reference


Or you can directly iterate the builds to do any change. EX: Remove the GCC 4.6 packages with build_type=Debug:

Expand All @@ -317,6 +317,25 @@ Or you can directly iterate the builds to do any change. EX: Remove the GCC 4.6
builder.run()


## Package Version based on Commit Checksum

Sometimes you want to use Conan as [in-source](https://docs.conan.io/en/latest/creating_packages/package_repo.html) but you do not need to specify a version in the recipe, it could be configured by your build environment. Usually you could use the branch name as the package version, but if you want to create unique packages for each new build, upload it and do not override on your remote, you will need to use a new version for each build. In this case, the branch name will not be enough, so a possible approach is to use your current commit checksum as version:


from cpt.packager import ConanMultiPackager
from cpt.ci_manager import CIManager
from cpt.printer import Printer


if __name__ == "__main__":
printer = Printer()
ci_manager = CIManager(printer)
builder = ConanMultiPackager(reference="mypackage/{}".format(ci_manager.get_commit_id()[:7]))
builder.add_common_builds()
builder.run()

As SHA-1 is 40 digits long, you could format the result to short size


## Using Docker

Expand Down Expand Up @@ -382,6 +401,15 @@ Also, it's possible to run some internal script, before to build the package:
builder.add_common_builds()
builder.run()

### Using with your own Docker images
The default location inside the Docker container is `/home/conan` on Linux and
`C:\Users\ContainerAdministrator` on Windows. This is fine if you use the conan
Docker images but if you are using your own image, these locations probably won't
exist.

To use a different location, you can use the option `docker_conan_home` or the
environment variable `CONAN_DOCKER_HOME`.

### Installing extra python packages before to build

Maybe you need to install some python packages using pip before to build your conan package. To solve this situation
Expand Down Expand Up @@ -980,6 +1008,7 @@ Using **CONAN_CLANG_VERSIONS** env variable in Travis ci or Appveyor:
- **mingw_configurations**: Configurations for MinGW
- **archs**: List containing specific architectures to build for. Default ["x86", "x86_64"]
- **use_docker**: Use docker for package creation in Linux systems.
- **docker_conan_home**: Location where package source files will be copied to inside the Docker container
- **docker_image_skip_update**: If defined, it will skip the initialization update of "conan package tools" and "conan" in the docker image. By default is False.
- **docker_image_skip_pull**: If defined, it will skip the "docker pull" command, enabling a local image to be used, and without being overwritten.
- **always_update_conan_in_docker**: If True, "conan package tools" and "conan" will be installed and upgraded in the docker image in every build execution.
Expand All @@ -990,8 +1019,9 @@ Using **CONAN_CLANG_VERSIONS** env variable in Travis ci or Appveyor:
- **curpage**: Current page of packages to create
- **total_pages**: Total number of pages
- **vs10_x86_64_enabled**: Flag indicating whether or not to build for VS10 64bits. Default [False]
- **upload_retry**: Num retries in upload in case of failure.
- **upload_retry**: Num retries in upload in case of failure.
- **upload_only_when_stable**: Will try to upload only if the channel is the stable channel. Default [False]
- **upload_only_when_tag**: Will try to upload only if the branch is a tag. Default [False]
- **build_types**: List containing specific build types. Default ["Release", "Debug"]
- **skip_check_credentials**: Conan will skip checking the user credentials before building the packages. And if no user/remote is specified, will try to upload with the
already stored credentiales in the local cache. Default [False]
Expand Down Expand Up @@ -1022,7 +1052,7 @@ Upload related parameters:
- **reference**: Reference of the package to upload. Ex: "zlib/1.2.8". If not specified it will be read from the `conanfile.py`.
- **remote**: Alternative remote name. Default "default"
- **stable_branch_pattern**: Regular expression, if current git branch matches this pattern, the packages will be uploaded to *stable* channel.
- **stable_branch_pattern**: Regular expression, if current git branch matches this pattern, the packages will be uploaded to *stable* channel.
By default it will check the following patterns: ``["master$", "release*", "stable*"]``
- **stable_channel**: Stable channel, default "stable".
- **channel**: Channel where your packages will be uploaded if previous parameter doesn't match
Expand Down Expand Up @@ -1091,6 +1121,7 @@ This is especially useful for CI integration.
- **CONAN_UPLOAD_RETRY**: If defined, in case of fail retries to upload again the specified times
- **CONAN_UPLOAD_ONLY_WHEN_STABLE**: If defined, will try to upload the packages only when the current channel is the stable one.
- **CONAN_UPLOAD_ONLY_WHEN_TAG**: If defined, will try to upload the packages only when the current branch is a tag.
- **CONAN_SKIP_CHECK_CREDENTIALS**: Conan will skip checking the user credentials before building the packages. And if no user/remote is specified, will try to upload with the
already stored credentiales in the local cache. Default [False]
Expand All @@ -1109,6 +1140,7 @@ This is especially useful for CI integration.
- **CONAN_CURRENT_PAGE**: Current page of packages to create
- **CONAN_TOTAL_PAGES**: Total number of pages
- **CONAN_DOCKER_IMAGE**: If defined and docker is being used, it will use this dockerimage instead of the default images, e.g. "conanio/gcc63"
- **CONAN_DOCKER_HOME**: Location where package source files will be copied to inside the Docker container
- **CONAN_DOCKER_IMAGE_SKIP_UPDATE**: If defined, it will skip the initialization update of "conan package tools" and "conan" in the docker image. By default is False.
- **CONAN_DOCKER_IMAGE_SKIP_PULL**: If defined, it will skip the "docker pull" command, enabling a local image to be used, and without being overwritten.
- **CONAN_ALWAYS_UPDATE_CONAN_DOCKER**: If defined, "conan package tools" and "conan" will be installed and upgraded in the docker image in every build execution
Expand Down
4 changes: 2 additions & 2 deletions cpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__version__ = '0.22.3'
NEWEST_CONAN_SUPPORTED = "1.11"
__version__ = '0.23.0'
NEWEST_CONAN_SUPPORTED = "1.12"
66 changes: 56 additions & 10 deletions cpt/ci_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def is_circle_ci():


class CIManager(object):

def __init__(self, printer):

self.manager = None
Expand Down Expand Up @@ -81,9 +80,14 @@ def get_commit_msg(self):
def is_pull_request(self):
return self.manager.is_pull_request()

def is_tag(self):
return self.manager.is_tag()

def get_commit_id(self):
return self.manager.get_commit_id()

class GenericManager(object):

class GenericManager(object):
def __init__(self, printer):
self.printer = printer

Expand All @@ -94,6 +98,13 @@ def get_commit_msg(self):
except Exception:
pass

def get_commit_id(self):
try:
msg = subprocess.check_output("git rev-parse HEAD", shell=True).decode().strip()
return msg
except Exception:
pass

def get_branch(self):
try:
for line in subprocess.check_output("git branch", shell=True).decode().splitlines():
Expand All @@ -109,25 +120,38 @@ def get_branch(self):
def is_pull_request(self):
return None

def is_tag(self):
try:
return True if \
subprocess.check_output("git tag -l --points-at HEAD",
shell=True).decode().splitlines() else False
except Exception:
pass
return False

class TravisManager(GenericManager):

class TravisManager(GenericManager):
def __init__(self, printer):
super(TravisManager, self).__init__(printer)
self.printer.print_message("- CI detected: Travis CI")

def get_commit_msg(self):
return os.getenv("TRAVIS_COMMIT_MESSAGE", None)

def get_commit_id(self):
return os.getenv("TRAVIS_COMMIT", None)

def get_branch(self):
return os.getenv("TRAVIS_BRANCH", None)

def is_pull_request(self):
return os.getenv("TRAVIS_PULL_REQUEST", "false") != "false"

def is_tag(self):
return os.getenv("TRAVIS_TAG", None)

class AppveyorManager(GenericManager):

class AppveyorManager(GenericManager):
def __init__(self, printer):
super(AppveyorManager, self).__init__(printer)
self.printer.print_message("- CI detected: Appveyor")
Expand All @@ -140,6 +164,9 @@ def get_commit_msg(self):
return commit + " " + extended
return commit

def get_commit_id(self):
return os.getenv("APPVEYOR_REPO_COMMIT", None)

def get_branch(self):
if self.is_pull_request():
return None
Expand All @@ -149,52 +176,71 @@ def get_branch(self):
def is_pull_request(self):
return os.getenv("APPVEYOR_PULL_REQUEST_NUMBER", None)

def is_tag(self):
return os.getenv("APPVEYOR_REPO_TAG", "false") != "false"

class BambooManager(GenericManager):

class BambooManager(GenericManager):
def __init__(self, printer):
super(BambooManager, self).__init__(printer)
self.printer.print_message("CI detected: Bamboo")

for var in list(os.environ.keys()):
result = re.match('\Abamboo_(CONAN.*)', var)
result = re.match('\A[bB][aA][mM][bB][oO][oO]_(CONAN.*)', var)
if result != None and os.getenv(result.group(1), None) == None:
self.printer.print_message("de-bambooized CONAN env var : %s " % result.group(1))
os.environ[result.group(1)] = os.environ[var]


def get_branch(self):
return os.getenv("bamboo_planRepository_branch", None)


class CircleCiManager(GenericManager):

def __init__(self, printer):
super(CircleCiManager, self).__init__(printer)
self.printer.print_message("CI detected: Circle CI")

def get_commit_id(self):
return os.getenv("CIRCLE_SHA1", None)

def get_branch(self):
return os.getenv("CIRCLE_BRANCH", None)

def is_pull_request(self):
return os.getenv("CIRCLE_PULL_REQUEST", None)

def is_tag(self):
return os.getenv("CIRCLE_TAG", None)

class GitlabManager(GenericManager):

class GitlabManager(GenericManager):
def __init__(self, printer):
super(GitlabManager, self).__init__(printer)
self.printer.print_message("CI detected: Gitlab")

def get_commit_msg(self):
return os.getenv("CI_COMMIT_TITLE", None)

def get_commit_id(self):
return os.getenv("CI_COMMIT_SHA", None)

def get_branch(self):
return os.getenv("CI_BUILD_REF_NAME", None)

def is_pull_request(self):
return os.getenv("CI_MERGE_REQUEST_ID", None)

def is_tag(self):
return os.getenv("CI_COMMIT_TAG", None)

class JenkinsManager(GenericManager):

class JenkinsManager(GenericManager):
def __init__(self, printer):
super(JenkinsManager, self).__init__(printer)
self.printer.print_message("CI detected: Jenkins")

def get_commit_id(self):
return os.getenv("GIT_COMMIT", None)

def get_branch(self):
return os.getenv("BRANCH_NAME", None)
Loading

0 comments on commit 06f959a

Please sign in to comment.