aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/ci/dirs.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-01-25 01:19:44 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-01-25 01:27:18 +0300
commit2e6ab77866bbdef6abcc149ddc430b1d9481b4f7 (patch)
treea259154cfc51dfe983516ad6c76ecd78ecb7a7c0 /project/ci/dirs.py
parentbye-bye, Travis & AppVeyor! (diff)
downloadcmake-common-2e6ab77866bbdef6abcc149ddc430b1d9481b4f7.tar.gz
cmake-common-2e6ab77866bbdef6abcc149ddc430b1d9481b4f7.zip
project.ci: auto-detect CI system
Diffstat (limited to '')
-rw-r--r--project/ci/dirs.py60
1 files changed, 54 insertions, 6 deletions
diff --git a/project/ci/dirs.py b/project/ci/dirs.py
index 6c6de65..bda4360 100644
--- a/project/ci/dirs.py
+++ b/project/ci/dirs.py
@@ -4,6 +4,7 @@
# Distributed under the MIT License.
import abc
+import os
import os.path
from project.boost.version import Version
@@ -14,9 +15,28 @@ from project.utils import env
class Dirs(abc.ABC):
+ @staticmethod
+ def detect():
+ matching = [ci for ci in _ALL_CI_LIST if ci.this_one()]
+ if len(matching) == 0:
+ raise RuntimeError('no CI system was detected')
+ if len(matching) > 1:
+ names = ', '.join(ci.get_name() for ci in matching)
+ raise RuntimeError(f"can't select a single CI system out of these: {names}")
+ return matching[0]
+
def __init__(self):
pass
+ @staticmethod
+ @abc.abstractmethod
+ def get_name():
+ pass
+
+ @abc.abstractmethod
+ def this_one(self):
+ pass
+
@abc.abstractmethod
def get_platform(self):
pass
@@ -49,26 +69,37 @@ class Dirs(abc.ABC):
def get_cmake_args(self):
pass
- def get_boost_help(self):
- return f'''Download & build Boost on Travis/AppVeyor.
+ @staticmethod
+ def get_boost_help():
+ names = ', '.join(ci.get_name() for ci in _ALL_CI_LIST)
+ return f'''Download & build Boost during a CI run.
This is similar to running both project.boost.download & project.boost.build,
but auto-fills some parameters from environment variables.
-Boost is built in {self.get_boost_dir()}.
+The supported CI systems are: {names}.
'''
- def get_cmake_help(self):
- return f'''Build a CMake project on Travis/AppVeyor.
+ @staticmethod
+ def get_cmake_help():
+ names = ', '.join(ci.get_name() for ci in _ALL_CI_LIST)
+ return f'''Build a CMake project during a CI run.
This is similar to running project.cmake.build, but auto-fills some parameters
from environment variables.
-The project is built in {self.get_cmake_dir()} and installed to {self.get_install_dir()}.
+The supported CI systems are: {names}.
'''
class Travis(Dirs):
+ @staticmethod
+ def get_name():
+ return 'Travis'
+
+ def this_one(self):
+ return 'TRAVIS' in os.environ
+
def get_platform(self):
return Platform.parse(env('platform'))
@@ -86,6 +117,13 @@ class Travis(Dirs):
class AppVeyor(Dirs):
+ @staticmethod
+ def get_name():
+ return 'AppVeyor'
+
+ def this_one(self):
+ return 'APPVEYOR' in os.environ
+
def get_platform(self):
return Platform.parse(env('PLATFORM'))
@@ -103,6 +141,13 @@ class AppVeyor(Dirs):
class GitHub(Dirs):
+ @staticmethod
+ def get_name():
+ return 'GitHub Actions'
+
+ def this_one(self):
+ return 'GITHUB_ACTIONS' in os.environ
+
def get_platform(self):
return Platform.parse(env('platform'))
@@ -117,3 +162,6 @@ class GitHub(Dirs):
def get_cmake_args(self):
return []
+
+
+_ALL_CI_LIST = (Travis(), AppVeyor(), GitHub())