| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import os |
| 5 |
import re |
| 6 |
from cpt.packager import ConanMultiPackager |
| 7 |
from cpt.ci_manager import CIManager |
| 8 |
from cpt.printer import Printer |
| 9 |
|
| 10 |
|
| 11 |
class BuilderSettings(object): |
| 12 |
@property |
| 13 |
def username(self): |
| 14 |
""" Set catchorg as package's owner |
| 15 |
""" |
| 16 |
return os.getenv("CONAN_USERNAME", "catchorg") |
| 17 |
|
| 18 |
@property |
| 19 |
def login_username(self): |
| 20 |
""" Set Bintray login username |
| 21 |
""" |
| 22 |
return os.getenv("CONAN_LOGIN_USERNAME", "horenmar") |
| 23 |
|
| 24 |
@property |
| 25 |
def upload(self): |
| 26 |
""" Set Catch2 repository to be used on upload. |
| 27 |
The upload server address could be customized by env var |
| 28 |
CONAN_UPLOAD. If not defined, the method will check the branch name. |
| 29 |
Only devel or CONAN_STABLE_BRANCH_PATTERN will be accepted. |
| 30 |
The devel branch will be pushed to testing channel, because it does |
| 31 |
not match the stable pattern. Otherwise it will upload to stable |
| 32 |
channel. |
| 33 |
""" |
| 34 |
return os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/catchorg/catch2") |
| 35 |
|
| 36 |
@property |
| 37 |
def upload_only_when_stable(self): |
| 38 |
""" Force to upload when running over tag branch |
| 39 |
""" |
| 40 |
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "True").lower() in ["true", "1", "yes"] |
| 41 |
|
| 42 |
@property |
| 43 |
def stable_branch_pattern(self): |
| 44 |
""" Only upload the package the branch name is like a tag |
| 45 |
""" |
| 46 |
return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+") |
| 47 |
|
| 48 |
@property |
| 49 |
def reference(self): |
| 50 |
""" Read project version from branch create Conan reference |
| 51 |
""" |
| 52 |
return os.getenv("CONAN_REFERENCE", "catch2/{}".format(self._version)) |
| 53 |
|
| 54 |
@property |
| 55 |
def channel(self): |
| 56 |
""" Default Conan package channel when not stable |
| 57 |
""" |
| 58 |
return os.getenv("CONAN_CHANNEL", "testing") |
| 59 |
|
| 60 |
@property |
| 61 |
def _version(self): |
| 62 |
""" Get version name from cmake file |
| 63 |
""" |
| 64 |
pattern = re.compile(r"project\(Catch2 LANGUAGES CXX VERSION (\d+\.\d+\.\d+)\)") |
| 65 |
version = "latest" |
| 66 |
with open("CMakeLists.txt") as file: |
| 67 |
for line in file: |
| 68 |
result = pattern.search(line) |
| 69 |
if result: |
| 70 |
version = result.group(1) |
| 71 |
return version |
| 72 |
|
| 73 |
@property |
| 74 |
def _branch(self): |
| 75 |
""" Get branch name from CI manager |
| 76 |
""" |
| 77 |
printer = Printer(None) |
| 78 |
ci_manager = CIManager(printer) |
| 79 |
return ci_manager.get_branch() |
| 80 |
|
| 81 |
|
| 82 |
if __name__ == "__main__": |
| 83 |
settings = BuilderSettings() |
| 84 |
builder = ConanMultiPackager( |
| 85 |
reference=settings.reference, |
| 86 |
channel=settings.channel, |
| 87 |
upload=settings.upload, |
| 88 |
upload_only_when_stable=False, |
| 89 |
stable_branch_pattern=settings.stable_branch_pattern, |
| 90 |
login_username=settings.login_username, |
| 91 |
username=settings.username, |
| 92 |
test_folder=os.path.join(".conan", "test_package")) |
| 93 |
builder.add() |
| 94 |
builder.run() |