build.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import re
  5. from cpt.packager import ConanMultiPackager
  6. from cpt.ci_manager import CIManager
  7. from cpt.printer import Printer
  8. class BuilderSettings(object):
  9. @property
  10. def branch(self):
  11. """ Get branch name
  12. """
  13. printer = Printer(None)
  14. ci_manager = CIManager(printer)
  15. return ci_manager.get_branch()
  16. @property
  17. def username(self):
  18. """ Set civetweb as package's owner
  19. """
  20. return os.getenv("CONAN_USERNAME", "civetweb")
  21. @property
  22. def upload(self):
  23. """ Set civetweb repository to be used on upload.
  24. The upload server address could be customized by env var
  25. CONAN_UPLOAD. If not defined, the method will check the branch name.
  26. Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted.
  27. The master branch will be pushed to testing channel, because it does
  28. not match the stable pattern. Otherwise it will upload to stable
  29. channel.
  30. """
  31. if os.getenv("CONAN_UPLOAD", None) is not None:
  32. return os.getenv("CONAN_UPLOAD")
  33. prog = re.compile(self.stable_branch_pattern)
  34. if self.branch and prog.match(self.branch):
  35. return "https://api.bintray.com/conan/civetweb/conan"
  36. return None
  37. @property
  38. def upload_only_when_stable(self):
  39. """ Force to upload when match stable pattern branch
  40. """
  41. return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
  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+)")
  47. @property
  48. def version(self):
  49. regex = re.compile(self.stable_branch_pattern)
  50. match = regex.match(self.branch)
  51. if match:
  52. return match.group(1)
  53. return "latest"
  54. @property
  55. def reference(self):
  56. """ Read project version from branch name to create Conan referece
  57. """
  58. return os.getenv("CONAN_REFERENCE", "civetweb/{}".format(self.version))
  59. if __name__ == "__main__":
  60. settings = BuilderSettings()
  61. builder = ConanMultiPackager(
  62. reference=settings.reference,
  63. username=settings.username,
  64. upload=settings.upload,
  65. upload_only_when_stable=settings.upload_only_when_stable,
  66. stable_branch_pattern=settings.stable_branch_pattern,
  67. test_folder=os.path.join("conan", "test_package"))
  68. builder.add_common_builds(pure_c=False)
  69. builder.run()