cikit 0.0.3__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cikit-0.0.3 → cikit-0.0.4}/PKG-INFO +1 -1
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/pylint.py +1 -1
- cikit-0.0.4/docs/build_reports/tests.rst +8 -0
- {cikit-0.0.3 → cikit-0.0.4}/pyproject.toml +1 -1
- cikit-0.0.4/src/cikit/ci/README.md +101 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/api.py +39 -24
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/errors.py +5 -1
- cikit-0.0.4/src/cikit/macros/README.md +266 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/cmake.py +7 -2
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/common.py +21 -1
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/coverage.py +20 -11
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/pylint.py +13 -7
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/pytest.py +2 -1
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/ruff.py +13 -6
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/test_report.py +16 -25
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit.egg-info/PKG-INFO +1 -1
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_env/test_api.py +28 -1
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_errors.py +11 -1
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_cmake.py +15 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_coverage.py +7 -5
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_pylint.py +3 -2
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_ruff.py +2 -1
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_test_report.py +29 -15
- {cikit-0.0.3 → cikit-0.0.4}/uv.lock +1 -1
- cikit-0.0.3/docs/build_reports/tests.rst +0 -8
- cikit-0.0.3/src/cikit/ci/README.md +0 -180
- cikit-0.0.3/src/cikit/macros/README.md +0 -223
- {cikit-0.0.3 → cikit-0.0.4}/.gitignore +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/.gitlab-ci.yml +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/.project +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/.pydevproject +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/.pylintrc +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/.repomixignore +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/LICENSE +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/README.md +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/all_.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/coverage.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/init.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/ruff.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/sphinx.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/ci_commands/test.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/Makefile +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/_static/logo/cikit-logo-192.png +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/_static/logo/cikit-logo.png +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/_static/logo/favicon.ico +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/build_reports/index.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/build_reports/lint.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/concepts/artifacts.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/concepts/environment.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/concepts/index.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/concepts/jobdata.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/concepts/metadata.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/concepts/providers.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/conf.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/getting_started.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/guides/ci_commands.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/guides/gitlab_ci.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/guides/index.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/guides/local_pipeline.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/guides/sphinx_build.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/docs/index.rst +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/setup.cfg +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/badge.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/ci/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/ci/loader.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/ci/main.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/ci/runner.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/command.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/README.md +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/cli.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/common.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/env_vars.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/env/provider.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/factory.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/jobdata/README.md +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/jobdata/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/jobdata/api.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/jobdata/cli.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/jobdata/client.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/jobdata/common.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/lint_to_rst.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/logging_utils.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/macros/sphinx.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/project_meta.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/.htaccess +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/README.md +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/config.php +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/config.php.example +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/jobdata_common.php +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/jobdata_create.php +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/jobdata_latest.php +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/jobdata_timeline.php +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/php/jobdata/jobdata_update.php +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/sql/jobdata/README.md +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/sql/jobdata/db_init.sql +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/resources/sql/jobdata/db_reset.sql +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/rst_tools.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/status.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/systemtest/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/systemtest/fixtures.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/timeline.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit/xml_tools.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit.egg-info/SOURCES.txt +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit.egg-info/dependency_links.txt +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit.egg-info/entry_points.txt +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit.egg-info/requires.txt +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/src/cikit.egg-info/top_level.txt +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/systemtests/conftest.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/systemtests/test_ci_cli.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/systemtests/test_env_cli.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/systemtests/test_jobdata_cli.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_ci_commands/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_ci_commands/test_all.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_badge.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_command.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_env/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_env/test_common.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_env/test_env_vars.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_env/test_provider.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_factory.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_jobdata/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_jobdata/test_api.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_jobdata/test_cli.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_jobdata/test_client.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_jobdata/test_common.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_lint_to_rst.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_logging_utils.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/__init__.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_common.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_pytest.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_macros/test_sphinx.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_project_meta.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_rst_tools.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_status.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_timeline.py +0 -0
- {cikit-0.0.3 → cikit-0.0.4}/tests/unittests/test_cikit/test_xml_tools.py +0 -0
|
@@ -44,7 +44,7 @@ def run(env, status, args: argparse.Namespace):
|
|
|
44
44
|
pylint.write_rst(env)
|
|
45
45
|
|
|
46
46
|
with CiSection("Generating todo rst from pylint", status=status):
|
|
47
|
-
pylint.write_rst(env,
|
|
47
|
+
pylint.write_rst(env, "todo", report_title="Todo Report", filter_code="fixme")
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
def command(args: argparse.Namespace) -> int:
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# cikit CI
|
|
2
|
+
|
|
3
|
+
Command framework for project-specific CI workflows based on **cikit**.
|
|
4
|
+
|
|
5
|
+
The package provides the reusable command infrastructure for local and CI
|
|
6
|
+
automation. Project-specific commands are implemented in a root-level
|
|
7
|
+
`ci_commands` package and are discovered automatically by the `cikit` console
|
|
8
|
+
command.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
* Automatic command discovery
|
|
13
|
+
* Shared logging and status handling
|
|
14
|
+
* CI environment initialization
|
|
15
|
+
* Jobdata integration
|
|
16
|
+
* Unified command execution
|
|
17
|
+
* Reusable cikit macros
|
|
18
|
+
* GitLab CI support
|
|
19
|
+
|
|
20
|
+
## Package Structure
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
src/cikit/ci/
|
|
24
|
+
├── __init__.py
|
|
25
|
+
├── main.py
|
|
26
|
+
├── loader.py
|
|
27
|
+
├── runner.py
|
|
28
|
+
└── README.md
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Console Entry Point
|
|
32
|
+
|
|
33
|
+
The package exposes the `cikit` console command:
|
|
34
|
+
|
|
35
|
+
```toml
|
|
36
|
+
[project.scripts]
|
|
37
|
+
cikit = "cikit.ci.main:main"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The command line parser is built dynamically from modules located in the
|
|
41
|
+
project-specific `ci_commands` package.
|
|
42
|
+
|
|
43
|
+
## Command Discovery
|
|
44
|
+
|
|
45
|
+
Command modules are discovered automatically from the root-level
|
|
46
|
+
`ci_commands` package.
|
|
47
|
+
|
|
48
|
+
Each command module must provide:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
def register(subparsers):
|
|
52
|
+
...
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The register function adds the command-specific parser and assigns the command
|
|
56
|
+
entry point.
|
|
57
|
+
|
|
58
|
+
## Command Architecture
|
|
59
|
+
|
|
60
|
+
The cikit framework provides:
|
|
61
|
+
|
|
62
|
+
1. Command discovery
|
|
63
|
+
2. Argument parsing
|
|
64
|
+
3. Logging setup
|
|
65
|
+
4. Environment initialization
|
|
66
|
+
5. Status handling
|
|
67
|
+
6. Error handling
|
|
68
|
+
7. Jobdata reporting
|
|
69
|
+
|
|
70
|
+
Projects provide the actual workflow implementation through command modules.
|
|
71
|
+
|
|
72
|
+
## Public API
|
|
73
|
+
|
|
74
|
+
Command modules typically use:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from cikit.ci import run_ci_script
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
def command(args):
|
|
84
|
+
return run_ci_script(
|
|
85
|
+
"example",
|
|
86
|
+
lambda env, status: run(env, status, args),
|
|
87
|
+
args=args,
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
Detailed documentation is available in the project documentation:
|
|
94
|
+
|
|
95
|
+
* Getting Started
|
|
96
|
+
* CI Commands
|
|
97
|
+
* Local Pipeline
|
|
98
|
+
* GitLab CI
|
|
99
|
+
* Sphinx Integration
|
|
100
|
+
|
|
101
|
+
See the `docs/` directory for details.
|
|
@@ -20,7 +20,7 @@ from pathlib import Path
|
|
|
20
20
|
from typing import Any, Dict, Iterable
|
|
21
21
|
from string import Template
|
|
22
22
|
|
|
23
|
-
from cikit.errors import CiToolsError
|
|
23
|
+
from cikit.errors import CiToolsError, ResolvePathError
|
|
24
24
|
from cikit.factory import build_job_context_from_env
|
|
25
25
|
from cikit.jobdata import ArtifactType, RefKey
|
|
26
26
|
|
|
@@ -28,9 +28,10 @@ from .provider import detect_provider, BaseProvider
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
LOGGER = logging.getLogger()
|
|
31
|
-
CLEANUP_DIR_KEYS = ("PUBLIC_DIR", )
|
|
32
|
-
CREATE_DIR_KEYS = ("PUBLIC_DIR", "BADGES_DIR", "ARTIFACTS_DIR", "JOBDATA_DIR", "RST_DIR")
|
|
33
31
|
MASKED = "***"
|
|
32
|
+
CLEANUP_DIRS = ("${PUBLIC_DIR}",)
|
|
33
|
+
CREATE_DIRS = ("${PUBLIC_DIR}", "${BADGES_DIR}", "${ARTIFACTS_DIR}", "${JOBDATA_DIR}",
|
|
34
|
+
"${RST_DIR}",)
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
def write_file(output_file: Path, data: str):
|
|
@@ -278,26 +279,28 @@ class CiEnvironment:
|
|
|
278
279
|
return argv
|
|
279
280
|
|
|
280
281
|
def resolve_path(self, path) -> Path:
|
|
281
|
-
"""Resolve
|
|
282
|
-
|
|
283
|
-
If the given path is absolute, it is returned unchanged.
|
|
284
|
-
If it is relative, it is interpreted relative to the
|
|
285
|
-
``PROJECT_ROOT`` environment variable. If ``PROJECT_ROOT``
|
|
286
|
-
is not defined, an empty string is used, effectively leaving
|
|
287
|
-
the path unchanged.
|
|
282
|
+
"""Resolve an environment-expanded path relative to PROJECT_ROOT.
|
|
288
283
|
|
|
289
284
|
Args:
|
|
290
|
-
path:
|
|
285
|
+
path: Absolute path, relative path, or path template.
|
|
291
286
|
|
|
292
287
|
Returns:
|
|
293
|
-
|
|
294
|
-
|
|
288
|
+
Resolved absolute path.
|
|
289
|
+
|
|
290
|
+
Raises:
|
|
291
|
+
CiToolsError: If a referenced environment variable is unknown.
|
|
295
292
|
"""
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
293
|
+
try:
|
|
294
|
+
resolved = Template(str(path)).substitute(self.as_str_map(secrets=True))
|
|
295
|
+
except KeyError as exp:
|
|
296
|
+
raise ResolvePathError(f"Unresolved path template variable: {exp}") from exp
|
|
297
|
+
|
|
298
|
+
resolved_path = Path(resolved)
|
|
299
|
+
|
|
300
|
+
if resolved_path.is_absolute():
|
|
301
|
+
return resolved_path
|
|
302
|
+
|
|
303
|
+
return self["PROJECT_ROOT"] / resolved_path
|
|
301
304
|
|
|
302
305
|
@property
|
|
303
306
|
def pipeline_id(self) -> str:
|
|
@@ -486,17 +489,29 @@ class CiJobEnvironment(CiEnvironment):
|
|
|
486
489
|
|
|
487
490
|
|
|
488
491
|
def prepare_dirs(env: CiEnvironment):
|
|
489
|
-
"""Create required output directories
|
|
492
|
+
"""Create required output directories and clean selected directories.
|
|
490
493
|
|
|
491
494
|
Args:
|
|
492
495
|
env: Resolved CI environment.
|
|
496
|
+
|
|
493
497
|
"""
|
|
494
|
-
for
|
|
495
|
-
|
|
496
|
-
|
|
498
|
+
for directory in CLEANUP_DIRS:
|
|
499
|
+
try:
|
|
500
|
+
path = env.resolve_path(directory)
|
|
501
|
+
except ResolvePathError as exp:
|
|
502
|
+
LOGGER.warning("Skipping cleanup directory: %s", exp)
|
|
503
|
+
continue
|
|
504
|
+
if path.exists():
|
|
505
|
+
LOGGER.info("Removing dir '%s'", path)
|
|
506
|
+
shutil.rmtree(path)
|
|
497
507
|
|
|
498
|
-
for
|
|
499
|
-
|
|
508
|
+
for directory in CREATE_DIRS:
|
|
509
|
+
try:
|
|
510
|
+
path = env.resolve_path(directory)
|
|
511
|
+
except ResolvePathError as exp:
|
|
512
|
+
LOGGER.warning("Skipping create directory: %s", exp)
|
|
513
|
+
continue
|
|
514
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
500
515
|
|
|
501
516
|
|
|
502
517
|
def shell_export_lines(env: CiEnvironment, secrets: bool = False) -> Iterable[str]:
|
|
@@ -27,8 +27,12 @@ class CiToolsError(Exception):
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class JobDataSyncError(CiToolsError):
|
|
30
|
-
"""Jobdata synchronization with the remote backend failed.
|
|
30
|
+
"""Jobdata synchronization with the remote backend failed.
|
|
31
|
+
"""
|
|
31
32
|
|
|
33
|
+
class ResolvePathError(CiToolsError):
|
|
34
|
+
"""Error due to resolving a path.
|
|
35
|
+
"""
|
|
32
36
|
|
|
33
37
|
class CiRecoverableError(CiToolsError):
|
|
34
38
|
"""Exception raised for non-fatal cikit errors.
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# cikit.macros
|
|
2
|
+
|
|
3
|
+
The `cikit.macros` package contains reusable building blocks for CI pipelines.
|
|
4
|
+
|
|
5
|
+
Macros encapsulate common CI tasks such as linting, testing, coverage generation,
|
|
6
|
+
documentation builds and report generation. They operate on a
|
|
7
|
+
`CiJobEnvironment` and are designed to be used by command modules in
|
|
8
|
+
`cikit.ci_commands`.
|
|
9
|
+
|
|
10
|
+
## Design Goals
|
|
11
|
+
|
|
12
|
+
The macros package provides:
|
|
13
|
+
|
|
14
|
+
* Reusable CI functionality independent of a specific CI provider
|
|
15
|
+
* Consistent artifact and jobdata handling
|
|
16
|
+
* Standardized badge and report generation
|
|
17
|
+
* Shared support for local execution and GitLab CI
|
|
18
|
+
* Small, composable functions suitable for custom command modules
|
|
19
|
+
|
|
20
|
+
## Available Modules
|
|
21
|
+
|
|
22
|
+
### common
|
|
23
|
+
|
|
24
|
+
Shared helpers used by other macros.
|
|
25
|
+
|
|
26
|
+
Features:
|
|
27
|
+
|
|
28
|
+
* Environment initialization
|
|
29
|
+
* Jobdata preparation
|
|
30
|
+
* Timeline chart generation
|
|
31
|
+
* Standard badges
|
|
32
|
+
* Directory comparison helpers
|
|
33
|
+
|
|
34
|
+
Typical usage:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from cikit.macros.common import init_env
|
|
38
|
+
|
|
39
|
+
env = init_env(jobname="ruff")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### ruff
|
|
43
|
+
|
|
44
|
+
Run Ruff and generate reports.
|
|
45
|
+
|
|
46
|
+
Features:
|
|
47
|
+
|
|
48
|
+
* JSON report generation
|
|
49
|
+
* GitLab Code Quality output
|
|
50
|
+
* Badge generation
|
|
51
|
+
* RST report generation
|
|
52
|
+
* Timeline charts
|
|
53
|
+
|
|
54
|
+
Typical usage:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from cikit.macros import ruff
|
|
58
|
+
|
|
59
|
+
ruff.ruff(env, ["src", "tests"])
|
|
60
|
+
ruff.badge(env)
|
|
61
|
+
ruff.write_rst(env)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### pylint
|
|
65
|
+
|
|
66
|
+
Run Pylint and generate reports.
|
|
67
|
+
|
|
68
|
+
Features:
|
|
69
|
+
|
|
70
|
+
* JSON report generation
|
|
71
|
+
* GitLab Code Quality output
|
|
72
|
+
* Badge generation
|
|
73
|
+
* RST report generation
|
|
74
|
+
* Timeline charts
|
|
75
|
+
* Rule specific reports
|
|
76
|
+
|
|
77
|
+
Typical usage:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from pathlib import Path
|
|
81
|
+
|
|
82
|
+
from cikit.macros import pylint
|
|
83
|
+
|
|
84
|
+
pylint.pylint(env, ["src", "tests"], rcfile=Path(".pylintrc"))
|
|
85
|
+
pylint.badge(env)
|
|
86
|
+
pylint.write_rst(env)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### pytest
|
|
90
|
+
|
|
91
|
+
Run Python test suites.
|
|
92
|
+
|
|
93
|
+
Features:
|
|
94
|
+
|
|
95
|
+
* JUnit XML generation
|
|
96
|
+
* Coverage integration
|
|
97
|
+
* Jobdata updates
|
|
98
|
+
* Artifact registration
|
|
99
|
+
|
|
100
|
+
Typical usage:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from pathlib import Path
|
|
104
|
+
|
|
105
|
+
from cikit.macros import pytest
|
|
106
|
+
|
|
107
|
+
pytest.pytest(
|
|
108
|
+
env,
|
|
109
|
+
Path("tests/unittests"),
|
|
110
|
+
test_alias="unittests",
|
|
111
|
+
)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### test_report
|
|
115
|
+
|
|
116
|
+
Generate badges and RST reports from test results.
|
|
117
|
+
|
|
118
|
+
Features:
|
|
119
|
+
|
|
120
|
+
* Test result badges
|
|
121
|
+
* Test summary reports
|
|
122
|
+
* Timeline integration
|
|
123
|
+
|
|
124
|
+
Typical usage:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from cikit.macros import test_report
|
|
128
|
+
|
|
129
|
+
test_report.badge(env)
|
|
130
|
+
test_report.write_rst(env)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### coverage
|
|
134
|
+
|
|
135
|
+
Generate coverage reports.
|
|
136
|
+
|
|
137
|
+
Features:
|
|
138
|
+
|
|
139
|
+
* Python coverage support
|
|
140
|
+
* gcovr support
|
|
141
|
+
* Cobertura XML generation
|
|
142
|
+
* HTML coverage reports
|
|
143
|
+
* Coverage badges
|
|
144
|
+
* Coverage RST pages
|
|
145
|
+
|
|
146
|
+
Typical usage:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from cikit.macros import coverage
|
|
150
|
+
|
|
151
|
+
coverage.pycoverage(env, alias="python")
|
|
152
|
+
coverage.badge(env)
|
|
153
|
+
coverage.write_rst(env)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
For C/C++ projects:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from pathlib import Path
|
|
160
|
+
|
|
161
|
+
from cikit.macros import coverage
|
|
162
|
+
|
|
163
|
+
coverage.ccoverage(
|
|
164
|
+
env,
|
|
165
|
+
build_dir=Path("build"),
|
|
166
|
+
alias="native",
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### cmake
|
|
171
|
+
|
|
172
|
+
Support for CMake and CTest based projects.
|
|
173
|
+
|
|
174
|
+
Features:
|
|
175
|
+
|
|
176
|
+
* CMake configuration
|
|
177
|
+
* CMake build execution
|
|
178
|
+
* CTest execution
|
|
179
|
+
* Parallel execution support
|
|
180
|
+
* JUnit XML output
|
|
181
|
+
|
|
182
|
+
Typical usage:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from pathlib import Path
|
|
186
|
+
|
|
187
|
+
from cikit.macros import cmake
|
|
188
|
+
|
|
189
|
+
build_dir = cmake.get_build_dir(env)
|
|
190
|
+
|
|
191
|
+
cmake.cmake_configure(
|
|
192
|
+
env,
|
|
193
|
+
source_dir=Path("."),
|
|
194
|
+
build_dir=build_dir,
|
|
195
|
+
generator="Ninja",
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
cmake.cmake_build(
|
|
199
|
+
env,
|
|
200
|
+
build_dir,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
cmake.ctest(
|
|
204
|
+
env,
|
|
205
|
+
build_dir,
|
|
206
|
+
test_alias="ctest",
|
|
207
|
+
)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### sphinx
|
|
211
|
+
|
|
212
|
+
Build Sphinx documentation and publish generated artifacts.
|
|
213
|
+
|
|
214
|
+
Features:
|
|
215
|
+
|
|
216
|
+
* Generated report integration
|
|
217
|
+
* Artifact publishing
|
|
218
|
+
* Badge publishing
|
|
219
|
+
* HTML documentation build
|
|
220
|
+
* GitLab Pages support
|
|
221
|
+
|
|
222
|
+
Typical usage:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from cikit.macros import sphinx
|
|
226
|
+
|
|
227
|
+
sphinx.prepare(env)
|
|
228
|
+
sphinx.sphinx(env)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Artifacts and Jobdata
|
|
232
|
+
|
|
233
|
+
Most macros update the current jobdata and register generated artifacts.
|
|
234
|
+
|
|
235
|
+
Typical artifact types include:
|
|
236
|
+
|
|
237
|
+
* Badges
|
|
238
|
+
* RST reports
|
|
239
|
+
* JUnit XML files
|
|
240
|
+
* Coverage reports
|
|
241
|
+
* HTML report folders
|
|
242
|
+
* Timeline charts
|
|
243
|
+
|
|
244
|
+
These artifacts are later consumed by the Sphinx build step and become part
|
|
245
|
+
of the generated project documentation.
|
|
246
|
+
|
|
247
|
+
## Creating Custom Commands
|
|
248
|
+
|
|
249
|
+
Macros are intended to be orchestrated from command modules located in the
|
|
250
|
+
`cikit.ci_commands` package.
|
|
251
|
+
|
|
252
|
+
Example:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from cikit.macros import common
|
|
256
|
+
from cikit.macros import pylint
|
|
257
|
+
|
|
258
|
+
env = common.init_env(jobname="pylint")
|
|
259
|
+
|
|
260
|
+
pylint.pylint(env, ["src", "tests"])
|
|
261
|
+
pylint.badge(env)
|
|
262
|
+
pylint.write_rst(env)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
This separation keeps command-line handling inside `cikit.ci_commands`
|
|
266
|
+
while the reusable implementation lives in `cikit.macros`.
|
|
@@ -52,7 +52,8 @@ def get_build_dir(env, name: str = "ctest") -> Path:
|
|
|
52
52
|
return env["ARTIFACTS_DIR"] / name
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
def cmake_configure(env, source_dir: Path, build_dir: Path, defines: list[str] = None
|
|
55
|
+
def cmake_configure(env, source_dir: Path, build_dir: Path, defines: list[str] = None,
|
|
56
|
+
generator: str = None):
|
|
56
57
|
"""Configure a CMake project.
|
|
57
58
|
|
|
58
59
|
Args:
|
|
@@ -60,8 +61,12 @@ def cmake_configure(env, source_dir: Path, build_dir: Path, defines: list[str] =
|
|
|
60
61
|
source_dir: CMake source directory.
|
|
61
62
|
build_dir: CMake build directory.
|
|
62
63
|
defines: Additional CMake definitions, for example ``-DFOO=ON``.
|
|
64
|
+
generator: Optional CMake generator, for example ``Ninja``.
|
|
63
65
|
"""
|
|
64
|
-
args = [
|
|
66
|
+
args = []
|
|
67
|
+
if generator:
|
|
68
|
+
args.extend(["-G", generator])
|
|
69
|
+
args.extend(["-S", str(source_dir), "-B", str(build_dir), *(defines or [])])
|
|
65
70
|
cmd = Command("cmake", common_args=args)
|
|
66
71
|
|
|
67
72
|
run_command(env.argv(cmd), live_output=True, cwd=env["PROJECT_ROOT"])
|
|
@@ -13,7 +13,7 @@ Date:
|
|
|
13
13
|
import logging
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
|
|
16
|
-
from cikit.env import
|
|
16
|
+
from cikit.env import get_env_vars, CiEnvironment, CiJobEnvironment
|
|
17
17
|
from cikit.jobdata import RefKey
|
|
18
18
|
from cikit.factory import build_jobdata_from_env
|
|
19
19
|
from cikit.badge import write_badge
|
|
@@ -41,6 +41,7 @@ def init_env(jobname: str = None, env_vars = None):
|
|
|
41
41
|
env_vars = get_env_vars()
|
|
42
42
|
|
|
43
43
|
if jobname is not None:
|
|
44
|
+
LOGGER.info("Preparing '%s' job...", jobname)
|
|
44
45
|
env = CiJobEnvironment(env_vars, jobname=jobname)
|
|
45
46
|
else:
|
|
46
47
|
env = CiEnvironment(env_vars)
|
|
@@ -123,3 +124,22 @@ def compare_dirs(expected_dir: Path, actual_dir: Path) -> str:
|
|
|
123
124
|
result = run_command(args, live_output=False)
|
|
124
125
|
|
|
125
126
|
return result.stdout
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def resolve_name_label(env, name: str = None, label: str = None) -> tuple:
|
|
130
|
+
"""Resolve default name and label from the job name.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
env: Resolved CI job environment.
|
|
134
|
+
name: Optional output or badge name.
|
|
135
|
+
label: Optional display label.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
Resolved name and label.
|
|
139
|
+
"""
|
|
140
|
+
if name is None:
|
|
141
|
+
name = env.job.jobname
|
|
142
|
+
if label is None:
|
|
143
|
+
label = env.job.jobname
|
|
144
|
+
|
|
145
|
+
return name, label
|
|
@@ -21,6 +21,7 @@ from cikit.env import write_file
|
|
|
21
21
|
from cikit.rst_tools import RstDocument, RstBlock, timeline_artifacts_block
|
|
22
22
|
|
|
23
23
|
from .sphinx import get_sphinx_paths
|
|
24
|
+
from .common import resolve_name_label
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
def _register_coverage_outputs(env, xml_file: Path, html_dir: Path):
|
|
@@ -135,30 +136,33 @@ def ccoverage(env, build_dir: Path, alias: str = "coverage"):
|
|
|
135
136
|
_register_coverage_outputs(env, xml_file, html_dir)
|
|
136
137
|
|
|
137
138
|
|
|
138
|
-
def badge(env,
|
|
139
|
+
def badge(env, name: str = None, label: str = None):
|
|
139
140
|
"""Generate the coverage badge.
|
|
140
141
|
|
|
141
142
|
Args:
|
|
142
143
|
env: Resolved CI job environment.
|
|
143
|
-
|
|
144
|
+
name: Basename of the badge file, jobname if None.
|
|
145
|
+
label: Label of the badge (left side), jobname if None.
|
|
144
146
|
"""
|
|
147
|
+
name, label = resolve_name_label(env, name, label)
|
|
148
|
+
|
|
145
149
|
coverage_value = env.jobdata.get("coverage", 0)
|
|
146
|
-
write_badge(env
|
|
150
|
+
write_badge(env, name=name, label=label, value=f"{coverage_value}%",
|
|
147
151
|
thresholds={50: "red", 70: "orange", 85: "yellow", 95: "green"})
|
|
148
152
|
|
|
149
153
|
|
|
150
|
-
def write_rst(env,
|
|
154
|
+
def write_rst(env, name: str = None, report_title: str = None) -> Path:
|
|
151
155
|
"""Create an RST page for a coverage report.
|
|
152
156
|
|
|
153
157
|
The generated page contains a summary of the collected coverage metrics
|
|
154
158
|
and a link to the corresponding HTML coverage report. The report name,
|
|
155
|
-
artifact paths and output filename
|
|
156
|
-
|
|
159
|
+
artifact paths and output filename can be customized, allowing the same
|
|
160
|
+
helper to be used for different coverage tools.
|
|
157
161
|
|
|
158
162
|
Args:
|
|
159
163
|
env: Resolved CI job environment.
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
name: Output file basename without extension, derived from the job name if None.
|
|
165
|
+
report_title: Title of the RST page, 'Coverage Report' if None.
|
|
162
166
|
|
|
163
167
|
Returns:
|
|
164
168
|
Path to the written RST file.
|
|
@@ -166,12 +170,17 @@ def write_rst(env, alias: str = "coverage", title: str = "Coverage Report") -> P
|
|
|
166
170
|
Raises:
|
|
167
171
|
CiToolsError: If the RST file cannot be written.
|
|
168
172
|
"""
|
|
169
|
-
|
|
173
|
+
if name is None:
|
|
174
|
+
name = env.job.jobname
|
|
175
|
+
if report_title is None:
|
|
176
|
+
report_title = "Coverage Report"
|
|
177
|
+
|
|
178
|
+
output_file = env["RST_DIR"] / f"{name}.rst"
|
|
170
179
|
paths = get_sphinx_paths()
|
|
171
|
-
html_dir = get_coverage_html_dir(env,
|
|
180
|
+
html_dir = get_coverage_html_dir(env, name)
|
|
172
181
|
html_rel = html_dir.relative_to(env["ARTIFACTS_DIR"])
|
|
173
182
|
|
|
174
|
-
document = RstDocument(
|
|
183
|
+
document = RstDocument(report_title)
|
|
175
184
|
document.add_block(timeline_artifacts_block(env.job.get_artifacts(ArtifactType.TIMELINE)))
|
|
176
185
|
|
|
177
186
|
summary = RstBlock("Summary")
|