rn-forge-devops 0.3.1.dev0__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.
Potentially problematic release.
This version of rn-forge-devops might be problematic. Click here for more details.
- rn_forge_devops-0.3.1.dev0/LICENSE +21 -0
- rn_forge_devops-0.3.1.dev0/PKG-INFO +74 -0
- rn_forge_devops-0.3.1.dev0/README.md +51 -0
- rn_forge_devops-0.3.1.dev0/pyproject.toml +60 -0
- rn_forge_devops-0.3.1.dev0/pyproject.toml.orig +57 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/__init__.py +31 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/ci.py +291 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/cli.py +190 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/github.py +44 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/index.py +74 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/notes.py +109 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/py.typed +0 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/releases.py +67 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/requirements.py +91 -0
- rn_forge_devops-0.3.1.dev0/src/rn_forge/devops/uv.py +280 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rohit Narayanan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rn-forge-devops
|
|
3
|
+
Version: 0.3.1.dev0
|
|
4
|
+
Summary: CI and release automation for rn-forge repositories in any language, run with uv
|
|
5
|
+
Author: Rohit Narayanan
|
|
6
|
+
Author-email: Rohit Narayanan <rohit.nn@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Dist: packaging>=24
|
|
17
|
+
Requires-Python: >=3.14
|
|
18
|
+
Project-URL: Documentation, https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/
|
|
19
|
+
Project-URL: Source, https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-devops
|
|
20
|
+
Project-URL: Changelog, https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-devops/CHANGELOG.md
|
|
21
|
+
Project-URL: Issues, https://github.com/rn-forge/pykit/issues
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# rn-forge-devops
|
|
25
|
+
|
|
26
|
+
[Documentation](https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/)
|
|
27
|
+
·
|
|
28
|
+
[Changelog](https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-devops/CHANGELOG.md)
|
|
29
|
+
· [Source](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-devops)
|
|
30
|
+
· [All pykit packages](https://rn-forge.github.io/pykit/)
|
|
31
|
+
|
|
32
|
+
CI and release automation for rn-forge repositories in any language, run with
|
|
33
|
+
uv. The `rn-forge-devops` command reads a repository's workspace manifests,
|
|
34
|
+
selects the packages a change affects, prints every CI job's matrix, and gates
|
|
35
|
+
each package's release on its checks. Workflow files call it instead of carrying
|
|
36
|
+
that logic.
|
|
37
|
+
|
|
38
|
+
It depends on `packaging` and on no other rn-forge package. It is a CI tool, not
|
|
39
|
+
a library an application depends on.
|
|
40
|
+
|
|
41
|
+
- `rn_forge.devops.ci` — the core: the member graph, change selection, check
|
|
42
|
+
matrices and release gating. It knows neither the CI platform nor the stack.
|
|
43
|
+
- `rn_forge.devops.requirements` — the `requirements` check: every requirement
|
|
44
|
+
between workspace members is a version range that admits the member's
|
|
45
|
+
current version and has a ceiling.
|
|
46
|
+
- `rn_forge.devops.uv` — the uv workspace adapter: it reads
|
|
47
|
+
`[tool.uv.workspace]` members, their internal requirements and their
|
|
48
|
+
`[tool.workspace-ci]` tables, and runs `smoke`.
|
|
49
|
+
- `rn_forge.devops.github` — the GitHub Actions adapter: `$GITHUB_OUTPUT` lines
|
|
50
|
+
and the event context.
|
|
51
|
+
- `rn_forge.devops.index` and `rn_forge.devops.releases` — the `index`
|
|
52
|
+
subcommand: a PEP 503 simple index rendered from a repository's GitHub
|
|
53
|
+
Release files, and the adapter that reads them with `gh`.
|
|
54
|
+
- `rn_forge.devops.notes` — the `notes` and `umbrella` subcommands: a changelog
|
|
55
|
+
version's section, and the umbrella release for the newest shipped release
|
|
56
|
+
page.
|
|
57
|
+
- `rn_forge.devops.cli` — the `rn-forge-devops` console script.
|
|
58
|
+
|
|
59
|
+
The package facade re-exports the planner core only. The core never imports an
|
|
60
|
+
adapter, and the package never imports another `rn_forge` package;
|
|
61
|
+
`.importlinter` proves both.
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
Run it from inside a uv workspace; the workspace root is the nearest directory
|
|
66
|
+
at or above the current one whose `pyproject.toml` declares
|
|
67
|
+
`[tool.uv.workspace]`.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uvx --from "rn-forge-devops>=0.3,<0.4" rn-forge-devops plan
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The subcommands and the `[tool.workspace-ci]` tables are described in the
|
|
74
|
+
[subcommand reference](https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/reference/subcommands.html).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# rn-forge-devops
|
|
2
|
+
|
|
3
|
+
[Documentation](https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/)
|
|
4
|
+
·
|
|
5
|
+
[Changelog](https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-devops/CHANGELOG.md)
|
|
6
|
+
· [Source](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-devops)
|
|
7
|
+
· [All pykit packages](https://rn-forge.github.io/pykit/)
|
|
8
|
+
|
|
9
|
+
CI and release automation for rn-forge repositories in any language, run with
|
|
10
|
+
uv. The `rn-forge-devops` command reads a repository's workspace manifests,
|
|
11
|
+
selects the packages a change affects, prints every CI job's matrix, and gates
|
|
12
|
+
each package's release on its checks. Workflow files call it instead of carrying
|
|
13
|
+
that logic.
|
|
14
|
+
|
|
15
|
+
It depends on `packaging` and on no other rn-forge package. It is a CI tool, not
|
|
16
|
+
a library an application depends on.
|
|
17
|
+
|
|
18
|
+
- `rn_forge.devops.ci` — the core: the member graph, change selection, check
|
|
19
|
+
matrices and release gating. It knows neither the CI platform nor the stack.
|
|
20
|
+
- `rn_forge.devops.requirements` — the `requirements` check: every requirement
|
|
21
|
+
between workspace members is a version range that admits the member's
|
|
22
|
+
current version and has a ceiling.
|
|
23
|
+
- `rn_forge.devops.uv` — the uv workspace adapter: it reads
|
|
24
|
+
`[tool.uv.workspace]` members, their internal requirements and their
|
|
25
|
+
`[tool.workspace-ci]` tables, and runs `smoke`.
|
|
26
|
+
- `rn_forge.devops.github` — the GitHub Actions adapter: `$GITHUB_OUTPUT` lines
|
|
27
|
+
and the event context.
|
|
28
|
+
- `rn_forge.devops.index` and `rn_forge.devops.releases` — the `index`
|
|
29
|
+
subcommand: a PEP 503 simple index rendered from a repository's GitHub
|
|
30
|
+
Release files, and the adapter that reads them with `gh`.
|
|
31
|
+
- `rn_forge.devops.notes` — the `notes` and `umbrella` subcommands: a changelog
|
|
32
|
+
version's section, and the umbrella release for the newest shipped release
|
|
33
|
+
page.
|
|
34
|
+
- `rn_forge.devops.cli` — the `rn-forge-devops` console script.
|
|
35
|
+
|
|
36
|
+
The package facade re-exports the planner core only. The core never imports an
|
|
37
|
+
adapter, and the package never imports another `rn_forge` package;
|
|
38
|
+
`.importlinter` proves both.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Run it from inside a uv workspace; the workspace root is the nearest directory
|
|
43
|
+
at or above the current one whose `pyproject.toml` declares
|
|
44
|
+
`[tool.uv.workspace]`.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
uvx --from "rn-forge-devops>=0.3,<0.4" rn-forge-devops plan
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The subcommands and the `[tool.workspace-ci]` tables are described in the
|
|
51
|
+
[subcommand reference](https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/reference/subcommands.html).
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rn-forge-devops"
|
|
3
|
+
version = "0.3.1.dev0"
|
|
4
|
+
description = "CI and release automation for rn-forge repositories in any language, run with uv"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Development Status :: 3 - Alpha",
|
|
10
|
+
"Intended Audience :: Developers",
|
|
11
|
+
"Operating System :: OS Independent",
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
14
|
+
"Programming Language :: Python :: 3.14",
|
|
15
|
+
"Typing :: Typed",
|
|
16
|
+
]
|
|
17
|
+
requires-python = ">=3.14"
|
|
18
|
+
dependencies = ["packaging>=24"]
|
|
19
|
+
|
|
20
|
+
[[project.authors]]
|
|
21
|
+
name = "Rohit Narayanan"
|
|
22
|
+
email = "rohit.nn@gmail.com"
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
rn-forge-devops = "rn_forge.devops.cli:main"
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Documentation = "https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/"
|
|
29
|
+
Source = "https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-devops"
|
|
30
|
+
Changelog = "https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-devops/CHANGELOG.md"
|
|
31
|
+
Issues = "https://github.com/rn-forge/pykit/issues"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["uv_build>=0.11.28,<0.12.0"]
|
|
35
|
+
build-backend = "uv_build"
|
|
36
|
+
|
|
37
|
+
[tool.uv.build-backend]
|
|
38
|
+
module-name = "rn_forge.devops"
|
|
39
|
+
|
|
40
|
+
[tool.uv.sources.rn-forge-devops]
|
|
41
|
+
workspace = true
|
|
42
|
+
|
|
43
|
+
[tool.pytest.ini_options]
|
|
44
|
+
addopts = "-ra --import-mode=importlib"
|
|
45
|
+
|
|
46
|
+
[dependency-groups]
|
|
47
|
+
dev = [
|
|
48
|
+
"pyright>=1.1.411",
|
|
49
|
+
"pytest>=9.1.1",
|
|
50
|
+
"pytest-cov>=7.1.0",
|
|
51
|
+
"pytest-randomly>=4.1.0",
|
|
52
|
+
"rn-forge-devops",
|
|
53
|
+
"ruff>=0.15.21",
|
|
54
|
+
]
|
|
55
|
+
docs = [
|
|
56
|
+
"mkdocs>=1.6.1",
|
|
57
|
+
"mkdocs-material>=9.7.6",
|
|
58
|
+
"mkdocstrings[python]>=1.0.6",
|
|
59
|
+
"rn-forge-devops",
|
|
60
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rn-forge-devops"
|
|
3
|
+
version = "0.3.1.dev0"
|
|
4
|
+
description = "CI and release automation for rn-forge repositories in any language, run with uv"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
"Typing :: Typed",
|
|
17
|
+
]
|
|
18
|
+
requires-python = ">=3.14"
|
|
19
|
+
dependencies = ["packaging>=24"]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
rn-forge-devops = "rn_forge.devops.cli:main"
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Documentation = "https://rn-forge.github.io/pykit/packages/rn-forge-devops/latest/"
|
|
26
|
+
Source = "https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-devops"
|
|
27
|
+
Changelog = "https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-devops/CHANGELOG.md"
|
|
28
|
+
Issues = "https://github.com/rn-forge/pykit/issues"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.11.28,<0.12.0"]
|
|
32
|
+
build-backend = "uv_build"
|
|
33
|
+
|
|
34
|
+
[tool.uv.build-backend]
|
|
35
|
+
module-name = "rn_forge.devops"
|
|
36
|
+
|
|
37
|
+
[tool.uv.sources]
|
|
38
|
+
rn-forge-devops = { workspace = true }
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
addopts = "-ra --import-mode=importlib"
|
|
42
|
+
|
|
43
|
+
[dependency-groups]
|
|
44
|
+
dev = [
|
|
45
|
+
"pyright>=1.1.411",
|
|
46
|
+
"pytest>=9.1.1",
|
|
47
|
+
"pytest-cov>=7.1.0",
|
|
48
|
+
"pytest-randomly>=4.1.0",
|
|
49
|
+
"rn-forge-devops",
|
|
50
|
+
"ruff>=0.15.21",
|
|
51
|
+
]
|
|
52
|
+
docs = [
|
|
53
|
+
"mkdocs>=1.6.1",
|
|
54
|
+
"mkdocs-material>=9.7.6",
|
|
55
|
+
"mkdocstrings[python]>=1.0.6",
|
|
56
|
+
"rn-forge-devops",
|
|
57
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""CI and release automation: the platform- and stack-neutral core."""
|
|
2
|
+
|
|
3
|
+
from rn_forge.devops.ci import (
|
|
4
|
+
UNSCOPED,
|
|
5
|
+
Package,
|
|
6
|
+
Smoke,
|
|
7
|
+
Workspace,
|
|
8
|
+
changed_files,
|
|
9
|
+
normalize,
|
|
10
|
+
plan,
|
|
11
|
+
releasable,
|
|
12
|
+
release_order,
|
|
13
|
+
released,
|
|
14
|
+
requirement_name,
|
|
15
|
+
select,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"UNSCOPED",
|
|
20
|
+
"Package",
|
|
21
|
+
"Smoke",
|
|
22
|
+
"Workspace",
|
|
23
|
+
"changed_files",
|
|
24
|
+
"normalize",
|
|
25
|
+
"plan",
|
|
26
|
+
"releasable",
|
|
27
|
+
"release_order",
|
|
28
|
+
"released",
|
|
29
|
+
"requirement_name",
|
|
30
|
+
"select",
|
|
31
|
+
]
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"""The CI core: the member graph, change selection, check matrices and release gating.
|
|
2
|
+
|
|
3
|
+
The core knows neither a CI platform nor a package manager. An adapter fills a
|
|
4
|
+
`Workspace` from the repository's own manifests and formats the `plan` outputs
|
|
5
|
+
for its platform.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
import shlex
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
# Changes under these paths select no package.
|
|
18
|
+
UNSCOPED = ("docs/",)
|
|
19
|
+
|
|
20
|
+
# A revision name never starts with `-`, so it cannot be read as a git option.
|
|
21
|
+
REVISION = r"[A-Za-z0-9_][A-Za-z0-9_./@-]*"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def normalize(name: str) -> str:
|
|
25
|
+
"""Return `name` in its canonical form: lowercase, runs of `-_.` as one `-`."""
|
|
26
|
+
return re.sub(r"[-_.]+", "-", name).lower()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def requirement_name(requirement: str) -> str:
|
|
30
|
+
"""Return the normalized package name of a requirement string."""
|
|
31
|
+
return normalize(re.split(r"[\s\[<>=!~;@]", requirement.strip(), maxsplit=1)[0])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class Smoke:
|
|
36
|
+
"""A package's smoke-test declaration.
|
|
37
|
+
|
|
38
|
+
Attributes:
|
|
39
|
+
modules: Modules imported in every smoke run.
|
|
40
|
+
extras: Modules imported for each extra, keyed by extra name.
|
|
41
|
+
setup: A script, relative to the package directory, run before the imports.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
modules: list[str] = field(default_factory=list[str])
|
|
45
|
+
extras: dict[str, list[str]] = field(default_factory=dict[str, list[str]])
|
|
46
|
+
setup: str = ""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class Package:
|
|
51
|
+
"""A workspace member.
|
|
52
|
+
|
|
53
|
+
Attributes:
|
|
54
|
+
name: Normalized project name.
|
|
55
|
+
dir: Directory relative to the repository root, with `/` separators.
|
|
56
|
+
module: Import name of the package.
|
|
57
|
+
requires: Names of the workspace members this package requires, through
|
|
58
|
+
dependencies, optional dependencies or dependency groups.
|
|
59
|
+
release_requires: Names of the workspace members this package requires
|
|
60
|
+
through dependencies or optional dependencies only. Release order and
|
|
61
|
+
release gating follow these.
|
|
62
|
+
postgres_env: Variable that receives a PostgreSQL DSN, or `None` when the
|
|
63
|
+
package needs no database run.
|
|
64
|
+
redis_env: Variable that receives a Redis URL, or `None` when the package
|
|
65
|
+
needs no Redis run.
|
|
66
|
+
smoke: The smoke-test declaration, or `None` when the package declares none.
|
|
67
|
+
adapters: Names of the package's adapters, or `None` when it declares none.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
name: str
|
|
71
|
+
dir: str
|
|
72
|
+
module: str
|
|
73
|
+
requires: set[str] = field(default_factory=lambda: set[str]())
|
|
74
|
+
release_requires: set[str] = field(default_factory=lambda: set[str]())
|
|
75
|
+
postgres_env: str | None = None
|
|
76
|
+
redis_env: str | None = None
|
|
77
|
+
smoke: Smoke | None = None
|
|
78
|
+
adapters: list[str] | None = None
|
|
79
|
+
|
|
80
|
+
def checks(self) -> list[dict[str, str]]:
|
|
81
|
+
"""Every check that must pass before this package may be released.
|
|
82
|
+
|
|
83
|
+
The empty-extra smoke check is listed whether or not `smoke` is set.
|
|
84
|
+
"""
|
|
85
|
+
checks = [{"kind": "verify", "marker": f"{self.name}.verify"}]
|
|
86
|
+
if self.postgres_env is not None:
|
|
87
|
+
checks.append({"kind": "postgres", "marker": f"{self.name}.postgres"})
|
|
88
|
+
if self.redis_env is not None:
|
|
89
|
+
checks.append({"kind": "redis", "marker": f"{self.name}.redis"})
|
|
90
|
+
checks.append({"kind": "smoke", "extra": "", "marker": f"{self.name}.smoke"})
|
|
91
|
+
if self.smoke is not None:
|
|
92
|
+
checks += [
|
|
93
|
+
{
|
|
94
|
+
"kind": "smoke",
|
|
95
|
+
"extra": extra,
|
|
96
|
+
"marker": f"{self.name}.smoke-{extra}",
|
|
97
|
+
}
|
|
98
|
+
for extra in self.smoke.extras
|
|
99
|
+
]
|
|
100
|
+
return checks
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass
|
|
104
|
+
class Workspace:
|
|
105
|
+
"""A repository root, its members and its workspace-wide CI settings.
|
|
106
|
+
|
|
107
|
+
Attributes:
|
|
108
|
+
root: The repository root.
|
|
109
|
+
packages: The members, keyed by normalized name.
|
|
110
|
+
pytest_args: Arguments added to every package's pytest run.
|
|
111
|
+
suites: Workspace-wide pytest runs, keyed by suite name.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
root: Path
|
|
115
|
+
packages: dict[str, Package]
|
|
116
|
+
pytest_args: list[str] = field(default_factory=list[str])
|
|
117
|
+
suites: dict[str, list[str]] = field(default_factory=dict[str, list[str]])
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def release_order(packages: dict[str, Package], names: set[str]) -> list[str]:
|
|
121
|
+
"""Return `names` with every package after its release requirements.
|
|
122
|
+
|
|
123
|
+
Raises:
|
|
124
|
+
ValueError: When the release requirements of `names` form a cycle.
|
|
125
|
+
"""
|
|
126
|
+
order: list[str] = []
|
|
127
|
+
pending = sorted(names)
|
|
128
|
+
while pending:
|
|
129
|
+
ready = [
|
|
130
|
+
n
|
|
131
|
+
for n in pending
|
|
132
|
+
if not (packages[n].release_requires & names) - set(order)
|
|
133
|
+
]
|
|
134
|
+
if not ready:
|
|
135
|
+
raise ValueError(f"release requirements form a cycle among {pending}")
|
|
136
|
+
order += ready
|
|
137
|
+
pending = [n for n in pending if n not in ready]
|
|
138
|
+
return order
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def changed_files(root: Path, base: str) -> list[str]:
|
|
142
|
+
"""Return the paths changed between `base` and `HEAD`.
|
|
143
|
+
|
|
144
|
+
Raises:
|
|
145
|
+
ValueError: When `base` is not a plain revision name.
|
|
146
|
+
"""
|
|
147
|
+
if not re.fullmatch(REVISION, base):
|
|
148
|
+
raise ValueError(f"invalid base {base!r}")
|
|
149
|
+
out = subprocess.run( # noqa: S603 # fixed argv, no shell
|
|
150
|
+
["git", "diff", "--name-only", "--end-of-options", f"{base}...HEAD"], # noqa: S607 # tool resolved from PATH
|
|
151
|
+
cwd=root,
|
|
152
|
+
check=True,
|
|
153
|
+
capture_output=True,
|
|
154
|
+
text=True,
|
|
155
|
+
).stdout
|
|
156
|
+
return out.splitlines()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def select(workspace: Workspace, base: str) -> set[str]:
|
|
160
|
+
"""Return the packages with changed files, plus every package that depends on one.
|
|
161
|
+
|
|
162
|
+
An empty, invalid or non-ancestor base, or a change outside every package and
|
|
163
|
+
`UNSCOPED`, selects all. A base is invalid unless it matches `REVISION`.
|
|
164
|
+
"""
|
|
165
|
+
packages, root = workspace.packages, workspace.root
|
|
166
|
+
if not base:
|
|
167
|
+
return set(packages)
|
|
168
|
+
if not re.fullmatch(REVISION, base) or (
|
|
169
|
+
subprocess.run( # noqa: S603 # fixed argv, no shell
|
|
170
|
+
["git", "cat-file", "-e", "--end-of-options", f"{base}^{{commit}}"], # noqa: S607 # tool resolved from PATH
|
|
171
|
+
check=False,
|
|
172
|
+
cwd=root,
|
|
173
|
+
stdout=subprocess.DEVNULL,
|
|
174
|
+
stderr=subprocess.DEVNULL,
|
|
175
|
+
).returncode
|
|
176
|
+
or subprocess.run( # noqa: S603 # fixed argv, no shell
|
|
177
|
+
["git", "merge-base", "--is-ancestor", "--end-of-options", base, "HEAD"], # noqa: S607 # tool resolved from PATH
|
|
178
|
+
check=False,
|
|
179
|
+
cwd=root,
|
|
180
|
+
stdout=subprocess.DEVNULL,
|
|
181
|
+
stderr=subprocess.DEVNULL,
|
|
182
|
+
).returncode
|
|
183
|
+
):
|
|
184
|
+
print(
|
|
185
|
+
f"base {base} is not a commit or an ancestor of HEAD; selecting all packages",
|
|
186
|
+
file=sys.stderr,
|
|
187
|
+
)
|
|
188
|
+
return set(packages)
|
|
189
|
+
selected: set[str] = set()
|
|
190
|
+
for file in changed_files(root, base):
|
|
191
|
+
owner = next(
|
|
192
|
+
(p.name for p in packages.values() if file.startswith(f"{p.dir}/")), None
|
|
193
|
+
)
|
|
194
|
+
if owner:
|
|
195
|
+
selected.add(owner)
|
|
196
|
+
elif not file.startswith(UNSCOPED):
|
|
197
|
+
return set(packages)
|
|
198
|
+
grew = True
|
|
199
|
+
while grew:
|
|
200
|
+
grew = False
|
|
201
|
+
for package in packages.values():
|
|
202
|
+
if package.name not in selected and package.requires & selected:
|
|
203
|
+
selected.add(package.name)
|
|
204
|
+
grew = True
|
|
205
|
+
return selected
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def plan(workspace: Workspace, base: str) -> dict[str, object]:
|
|
209
|
+
"""Return every job's matrix and package list for a run against `base`.
|
|
210
|
+
|
|
211
|
+
Command-line values are shell-quoted strings. The keys are `release-order`,
|
|
212
|
+
`packages`, `postgres`, `redis`, `smoke`, `suites`, `pytest-args`, `cov-args`,
|
|
213
|
+
`test-paths`, `sonar-sources`, `sonar-tests`, `sonar` and `docs`.
|
|
214
|
+
"""
|
|
215
|
+
packages, root = workspace.packages, workspace.root
|
|
216
|
+
order = release_order(packages, select(workspace, base))
|
|
217
|
+
chosen = [packages[n] for n in order]
|
|
218
|
+
everything = [packages[n] for n in release_order(packages, set(packages))]
|
|
219
|
+
return {
|
|
220
|
+
"release-order": order,
|
|
221
|
+
"packages": [{"name": p.name, "dir": p.dir} for p in chosen],
|
|
222
|
+
"postgres": [
|
|
223
|
+
{"name": p.name, "dir": p.dir, "env": p.postgres_env}
|
|
224
|
+
for p in chosen
|
|
225
|
+
if p.postgres_env is not None
|
|
226
|
+
],
|
|
227
|
+
"redis": [
|
|
228
|
+
{"name": p.name, "dir": p.dir, "env": p.redis_env}
|
|
229
|
+
for p in chosen
|
|
230
|
+
if p.redis_env is not None
|
|
231
|
+
],
|
|
232
|
+
"smoke": [
|
|
233
|
+
{"name": p.name, "extra": c["extra"], "marker": c["marker"]}
|
|
234
|
+
for p in chosen
|
|
235
|
+
for c in p.checks()
|
|
236
|
+
if c["kind"] == "smoke"
|
|
237
|
+
],
|
|
238
|
+
"suites": [
|
|
239
|
+
{"name": name, "args": shlex.join(args)}
|
|
240
|
+
for name, args in workspace.suites.items()
|
|
241
|
+
],
|
|
242
|
+
"pytest-args": shlex.join(workspace.pytest_args),
|
|
243
|
+
"cov-args": shlex.join(f"--cov={p.module}" for p in everything),
|
|
244
|
+
"test-paths": shlex.join(p.dir for p in everything),
|
|
245
|
+
"sonar-sources": ",".join(f"{p.dir}/src" for p in everything),
|
|
246
|
+
"sonar-tests": ",".join(
|
|
247
|
+
f"{p.dir}/tests" for p in everything if (root / p.dir / "tests").is_dir()
|
|
248
|
+
),
|
|
249
|
+
"sonar": (root / "sonar-project.properties").is_file(),
|
|
250
|
+
"docs": (root / "mkdocs.yml").is_file(),
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def releasable(
|
|
255
|
+
packages: dict[str, Package], ok_dir: Path, names: list[str]
|
|
256
|
+
) -> tuple[list[str], list[str]]:
|
|
257
|
+
"""Return the packages of `names` that may be released, then those that may not.
|
|
258
|
+
|
|
259
|
+
A package may be released when every check of it left a marker file in
|
|
260
|
+
`ok_dir` and its release requirements among `names` may be released too. Both lists
|
|
261
|
+
are in release order.
|
|
262
|
+
"""
|
|
263
|
+
selected = {normalize(n) for n in names}
|
|
264
|
+
passed: set[str] = set()
|
|
265
|
+
blocked: list[str] = []
|
|
266
|
+
for name in release_order(packages, selected):
|
|
267
|
+
package = packages[name]
|
|
268
|
+
checks_ok = all((ok_dir / c["marker"]).exists() for c in package.checks())
|
|
269
|
+
if checks_ok and (package.release_requires & selected) <= passed:
|
|
270
|
+
passed.add(name)
|
|
271
|
+
else:
|
|
272
|
+
blocked.append(name)
|
|
273
|
+
return [n for n in release_order(packages, selected) if n in passed], blocked
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def released(workspace: Workspace) -> list[tuple[str, str, str, str]]:
|
|
277
|
+
"""Return `(name, dir, module, version)` for each `<name>-v<version>` tag at `HEAD`."""
|
|
278
|
+
tags = subprocess.run(
|
|
279
|
+
["git", "tag", "--points-at", "HEAD"], # noqa: S607 # tool resolved from PATH
|
|
280
|
+
cwd=workspace.root,
|
|
281
|
+
check=True,
|
|
282
|
+
capture_output=True,
|
|
283
|
+
text=True,
|
|
284
|
+
).stdout.split()
|
|
285
|
+
found: list[tuple[str, str, str, str]] = []
|
|
286
|
+
for tag in tags:
|
|
287
|
+
name, _, version = tag.rpartition("-v")
|
|
288
|
+
if name in workspace.packages:
|
|
289
|
+
package = workspace.packages[name]
|
|
290
|
+
found.append((name, package.dir, package.module, version))
|
|
291
|
+
return found
|