When running in a Github Action or in Gitlab CI, we automatically
forward the .gitconfig into the kas environment (both for kas repo
cloning, as well as for bitbake). By that, we keep the same semantics
both for Github Actions, as well as for the Gitlab CI.
Signed-off-by: Felix Moessbauer <
felix.mo...@siemens.com>
---
docs/command-line/environment-variables.inc | 7 ++++---
docs/userguide/credentials.rst | 6 ++++--
kas/libcmds.py | 20 +++++++++++++++++---
3 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/docs/command-line/environment-variables.inc b/docs/command-line/environment-variables.inc
index 13255c9af..8b8d4a024 100644
--- a/docs/command-line/environment-variables.inc
+++ b/docs/command-line/environment-variables.inc
@@ -135,9 +135,10 @@ Variables Glossary
| | first one. The job url is added to the |
| | provenance attestation (if enabled). |
+--------------------------+--------------------------------------------------+
-| ``GITHUB_ACTIONS`` | Environment variables from github actions. If |
-| (K) | set to `true`, `.gitconfig` is automatically |
-| | imported. For details, see ``GITCONFIG_FILE``. |
+| ``GITHUB_ACTIONS`` | Environment variables from github actions or |
+| ``GITLAB_CI`` | Gitlab CI. If set to `true`, `.gitconfig` is |
+| (K) | automatically imported. |
+| | For details, see ``GITCONFIG_FILE``. |
+--------------------------+--------------------------------------------------+
| ``BB_NUMBER_THREADS`` | Environment variables to control the concurrency.|
| ``PARALLEL_MAKE`` | |
diff --git a/docs/userguide/credentials.rst b/docs/userguide/credentials.rst
index 42cc1f810..9faad67fe 100644
--- a/docs/userguide/credentials.rst
+++ b/docs/userguide/credentials.rst
@@ -34,11 +34,13 @@ an existing one. In addition, credential helpers can be used by
setting the corresponding environment variables. These are added to the
``.gitconfig`` file as well.
+When running in a Github Actions or Gitlab CI job, the ``.gitconfig`` file
+is automatically injected.
+
Github Actions
~~~~~~~~~~~~~~
-When running in a Github Action, the ``.gitconfig`` file is automatically
-injected. In combination with the
+In combination with the
`webfactory/ssh-agent <
https://github.com/webfactory/ssh-agent>`_ action,
this automatically makes the required credentials available to kas and
bitbake.
diff --git a/kas/libcmds.py b/kas/libcmds.py
index c3d4cdca9..9cd739a00 100644
--- a/kas/libcmds.py
+++ b/kas/libcmds.py
@@ -180,6 +180,18 @@ class SetupHome(Command):
def __str__(self):
return 'setup_home'
+ @staticmethod
+ def _on_ci():
+ """
+ Detects if we are running on a CI system.
+ Returns the name of the CI system or None.
+ """
+ if os.environ.get('GITHUB_ACTIONS', False) == 'true':
+ return 'Github Actions'
+ elif os.environ.get('GITLAB_CI', False) == 'true':
+ return 'Gitlab CI'
+ return None
+
def _setup_netrc(self):
if os.environ.get('NETRC_FILE', False):
shutil.copy(os.environ['NETRC_FILE'],
@@ -222,9 +234,8 @@ class SetupHome(Command):
gitconfig_host = os.environ.get('GITCONFIG_FILE', False)
gitconfig_kas = self.tmpdirname + '/.gitconfig'
- # when running in the github ci, always try to read the gitconfig
- if not gitconfig_host and \
- os.environ.get('GITHUB_ACTIONS', False) == 'true':
+ # on supported CI systems, always try to read the gitconfig
+ if not gitconfig_host and self._on_ci():
gitconfig_host = os.path.expanduser('~/.gitconfig')
if gitconfig_host and os.path.exists(gitconfig_host):
@@ -246,6 +257,9 @@ class SetupHome(Command):
config.write()
def execute(self, ctx):
+ ci = self._on_ci()
+ if ci:
+
logging.info(f'Running on {ci}')
def_umask = os.umask(0o077)
self._setup_netrc()
self._setup_gitconfig()
--
2.39.2