apx-example 0.1.0__tar.gz → 0.3.0__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.
- {apx_example-0.1.0 → apx_example-0.3.0}/PKG-INFO +13 -5
- {apx_example-0.1.0 → apx_example-0.3.0}/README.md +11 -3
- apx_example-0.3.0/apx_example/abc.py +36 -0
- apx_example-0.3.0/apx_example/checks.py +23 -0
- apx_example-0.3.0/apx_example/cloud.py +37 -0
- apx_example-0.3.0/apx_example/overlays/cloud/example/DEPLOY.md +7 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/plugin.py +17 -4
- apx_example-0.3.0/apx_example/spec.py +31 -0
- apx_example-0.3.0/apx_example/target.py +94 -0
- apx_example-0.3.0/apx_example/tools.py +34 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example.egg-info/PKG-INFO +13 -5
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example.egg-info/SOURCES.txt +7 -1
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example.egg-info/entry_points.txt +3 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example.egg-info/requires.txt +1 -1
- {apx_example-0.1.0 → apx_example-0.3.0}/pyproject.toml +5 -2
- {apx_example-0.1.0 → apx_example-0.3.0}/tests/test_plugin.py +7 -1
- apx_example-0.3.0/tests/test_target.py +83 -0
- apx_example-0.1.0/apx_example/overlays/cloud/example/DEPLOY.md +0 -3
- apx_example-0.1.0/apx_example/tools.py +0 -21
- {apx_example-0.1.0 → apx_example-0.3.0}/LICENSE +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/__init__.py +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/cli.py +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/overlays/cloud/example/deploy/run.sh +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/overlays/index.json +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/release.py +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example/rules.py +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example.egg-info/dependency_links.txt +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/apx_example.egg-info/top_level.txt +0 -0
- {apx_example-0.1.0 → apx_example-0.3.0}/setup.cfg +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-example
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Template for an Action Platform plugin: tools, a CLI command, an overlay, a release strategy, a replaced slot, lifecycle hooks.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
7
|
Requires-Python: >=3.11
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
|
-
Requires-Dist: action-platform>=0.
|
|
10
|
+
Requires-Dist: action-platform>=0.32
|
|
11
11
|
Provides-Extra: dev
|
|
12
12
|
Requires-Dist: pytest>=8; extra == "dev"
|
|
13
13
|
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
@@ -20,17 +20,25 @@ Template for an [Action Platform](https://github.com/actionplatform/action-platf
|
|
|
20
20
|
|
|
21
21
|
| File | Extension point |
|
|
22
22
|
|---|---|
|
|
23
|
-
| `plugin.py` | the `Plugin`: slug, `needs`, `register`, `after_release`, `after_deploy` |
|
|
24
|
-
| `tools.py` |
|
|
23
|
+
| `plugin.py` | the `Plugin`: slug, `needs`, `options` (one with a setup button), `register`, `after_release`, `after_deploy` |
|
|
24
|
+
| `tools.py` | MCP tools `example_hello` and `example_remember`, with input and output schemas; `remember` writes the plugin's options store |
|
|
25
25
|
| `cli.py` | `action-platform example hello` |
|
|
26
26
|
| `rules.py` | a replaced core slot (`gitflow_rules`) — stricter branch kinds while the plugin is enabled |
|
|
27
27
|
| `release.py` | named providers: `[release] strategy = "calver"`, `[release] changelog = "plain"` |
|
|
28
|
+
| `target.py` | the `DeployTarget` for the `example` cloud — `preflight`, `readiness`, `deploy`, `verify`, `diagnose`, `delete` — composing the parts below through `parts(spec)` |
|
|
29
|
+
| `abc.py`, `spec.py` | one ABC per responsibility (`Cloud`, `Readiness`); a frozen `Spec` per call |
|
|
30
|
+
| `cloud.py`, `checks.py` | the implementations: the overlay's script (streams its output to the job log), the readiness checks |
|
|
31
|
+
| `tests/fake.py`, `tests/live/` | the cloud in memory for fast tests; a suite against the real destination, skipped without it |
|
|
28
32
|
| `overlays/` | a cloud overlay `example` — plain files, copied as they are by `action-platform cloud set example`; add a `cookiecutter.json` only when the files need rendering |
|
|
29
33
|
|
|
34
|
+
## For agents and editors
|
|
35
|
+
|
|
36
|
+
`SPEC.md` is the contract a plugin follows. `skills/create-plugin/SKILL.md` walks an agent through creating `apx-<slug>` from here — installable in Claude Code (`/plugin marketplace add actionplatform/apx-example`, then `/plugin install apx-example@apx-example`), read by Codex through `.codex-plugin/`, and mirrored for Cursor in `.cursor/rules/plugin.mdc`. `AGENTS.md` holds the repository rules every agent reads.
|
|
37
|
+
|
|
30
38
|
## Use this template
|
|
31
39
|
|
|
32
40
|
1. Create a repository from it, named `apx-<slug>`.
|
|
33
|
-
2. Rename `apx_example` → `apx_<slug>`, `example` → `<slug>` in `pyproject.toml` (package name, entry points), `plugin.py` (`slug`), `cli.py`, `overlays/index.json`.
|
|
41
|
+
2. Rename `apx_example` → `apx_<slug>`, `example` → `<slug>` in `pyproject.toml` (package name, entry points), `plugin.py` (`slug`), `target.py` (`name`), `cli.py`, `overlays/index.json`.
|
|
34
42
|
3. Delete what you do not need; a plugin with only `plugin.py` and one tool is fine.
|
|
35
43
|
4. `pip install -e ".[dev]"`, `pytest`, `action-platform plugin list` (shows `example` once installed).
|
|
36
44
|
5. Publish to PyPI; open a pull request to [plugins-index](https://github.com/actionplatform/plugins-index) with `<slug>.json`.
|
|
@@ -4,17 +4,25 @@ Template for an [Action Platform](https://github.com/actionplatform/action-platf
|
|
|
4
4
|
|
|
5
5
|
| File | Extension point |
|
|
6
6
|
|---|---|
|
|
7
|
-
| `plugin.py` | the `Plugin`: slug, `needs`, `register`, `after_release`, `after_deploy` |
|
|
8
|
-
| `tools.py` |
|
|
7
|
+
| `plugin.py` | the `Plugin`: slug, `needs`, `options` (one with a setup button), `register`, `after_release`, `after_deploy` |
|
|
8
|
+
| `tools.py` | MCP tools `example_hello` and `example_remember`, with input and output schemas; `remember` writes the plugin's options store |
|
|
9
9
|
| `cli.py` | `action-platform example hello` |
|
|
10
10
|
| `rules.py` | a replaced core slot (`gitflow_rules`) — stricter branch kinds while the plugin is enabled |
|
|
11
11
|
| `release.py` | named providers: `[release] strategy = "calver"`, `[release] changelog = "plain"` |
|
|
12
|
+
| `target.py` | the `DeployTarget` for the `example` cloud — `preflight`, `readiness`, `deploy`, `verify`, `diagnose`, `delete` — composing the parts below through `parts(spec)` |
|
|
13
|
+
| `abc.py`, `spec.py` | one ABC per responsibility (`Cloud`, `Readiness`); a frozen `Spec` per call |
|
|
14
|
+
| `cloud.py`, `checks.py` | the implementations: the overlay's script (streams its output to the job log), the readiness checks |
|
|
15
|
+
| `tests/fake.py`, `tests/live/` | the cloud in memory for fast tests; a suite against the real destination, skipped without it |
|
|
12
16
|
| `overlays/` | a cloud overlay `example` — plain files, copied as they are by `action-platform cloud set example`; add a `cookiecutter.json` only when the files need rendering |
|
|
13
17
|
|
|
18
|
+
## For agents and editors
|
|
19
|
+
|
|
20
|
+
`SPEC.md` is the contract a plugin follows. `skills/create-plugin/SKILL.md` walks an agent through creating `apx-<slug>` from here — installable in Claude Code (`/plugin marketplace add actionplatform/apx-example`, then `/plugin install apx-example@apx-example`), read by Codex through `.codex-plugin/`, and mirrored for Cursor in `.cursor/rules/plugin.mdc`. `AGENTS.md` holds the repository rules every agent reads.
|
|
21
|
+
|
|
14
22
|
## Use this template
|
|
15
23
|
|
|
16
24
|
1. Create a repository from it, named `apx-<slug>`.
|
|
17
|
-
2. Rename `apx_example` → `apx_<slug>`, `example` → `<slug>` in `pyproject.toml` (package name, entry points), `plugin.py` (`slug`), `cli.py`, `overlays/index.json`.
|
|
25
|
+
2. Rename `apx_example` → `apx_<slug>`, `example` → `<slug>` in `pyproject.toml` (package name, entry points), `plugin.py` (`slug`), `target.py` (`name`), `cli.py`, `overlays/index.json`.
|
|
18
26
|
3. Delete what you do not need; a plugin with only `plugin.py` and one tool is fine.
|
|
19
27
|
4. `pip install -e ".[dev]"`, `pytest`, `action-platform plugin list` (shows `example` once installed).
|
|
20
28
|
5. Publish to PyPI; open a pull request to [plugins-index](https://github.com/actionplatform/plugins-index) with `<slug>.json`.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""One contract per responsibility of the deploy target. A real plugin adds one ABC per thing it talks to (the API, the registry, the domains…); the target only composes them."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from action_platform.core.context import Check
|
|
10
|
+
|
|
11
|
+
from apx_example.spec import Spec
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Cloud(ABC):
|
|
15
|
+
"""The destination: what a deploy changes there, and what it holds now."""
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def ship(self, spec: Spec) -> str | None:
|
|
19
|
+
"""Put `spec.version` on `spec.stage`; the URL it answers on, if any. Raises `DeployError` with the reason when it fails."""
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def version(self, spec: Spec) -> str | None:
|
|
23
|
+
"""The version running on `spec.stage`, or None."""
|
|
24
|
+
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def remove(self, spec: Spec) -> None:
|
|
27
|
+
"""Tear `spec.stage` down; nothing to do is fine."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Readiness(ABC):
|
|
31
|
+
"""One check a deploy has to pass, run without building or changing anything."""
|
|
32
|
+
|
|
33
|
+
id: str
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def run(self, spec: Spec) -> Check: ...
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Readiness, one class per check. Add one per failure a user will really hit: credentials, permissions, the destination's state."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from action_platform.core.context import Check
|
|
6
|
+
|
|
7
|
+
from apx_example.abc import Readiness
|
|
8
|
+
from apx_example.spec import Spec
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class OverlayCheck(Readiness):
|
|
12
|
+
id = "example.overlay"
|
|
13
|
+
|
|
14
|
+
def run(self, spec: Spec) -> Check:
|
|
15
|
+
if spec.script.exists():
|
|
16
|
+
return Check(self.id, True, "deploy/run.sh is there")
|
|
17
|
+
|
|
18
|
+
return Check(
|
|
19
|
+
self.id,
|
|
20
|
+
False,
|
|
21
|
+
"deploy/run.sh not found",
|
|
22
|
+
fix="action-platform cloud set example",
|
|
23
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""The example cloud: the overlay's `deploy/run.sh`, and a file per scope that remembers what was shipped. Replace it with your cloud's API or CLI; keep the `Cloud` contract."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from action_platform.core.exception import DeployError
|
|
6
|
+
from action_platform.core.process import stream
|
|
7
|
+
|
|
8
|
+
from apx_example.abc import Cloud
|
|
9
|
+
from apx_example.spec import SCRIPT, Spec
|
|
10
|
+
|
|
11
|
+
STATE = ".example"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ScriptCloud(Cloud):
|
|
15
|
+
def ship(self, spec: Spec) -> str | None:
|
|
16
|
+
result = stream(
|
|
17
|
+
["sh", str(SCRIPT)],
|
|
18
|
+
cwd=spec.root,
|
|
19
|
+
env={**spec.env, "SCOPE": spec.stage, "VERSION": spec.version},
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if not result.ok:
|
|
23
|
+
raise DeployError(f"deploy/run.sh failed: {result.output.strip()[-500:]}")
|
|
24
|
+
|
|
25
|
+
state = spec.root / STATE
|
|
26
|
+
state.mkdir(exist_ok=True)
|
|
27
|
+
(state / spec.stage).write_text(spec.version)
|
|
28
|
+
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
def version(self, spec: Spec) -> str | None:
|
|
32
|
+
path = spec.root / STATE / spec.stage
|
|
33
|
+
|
|
34
|
+
return path.read_text().strip() if path.exists() else None
|
|
35
|
+
|
|
36
|
+
def remove(self, spec: Spec) -> None:
|
|
37
|
+
(spec.root / STATE / spec.stage).unlink(missing_ok=True)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Deploy — example
|
|
2
|
+
|
|
3
|
+
This project deploys to the `example` target. The files under `deploy/` came from the `example` plugin's overlay, copied as they are — no templating.
|
|
4
|
+
|
|
5
|
+
The contract a real cloud overlay follows: every web project **serves HTTP on `$PORT`**, and the overlay's build step is `ap-build package` (from [images-base](https://github.com/actionplatform/images-base)), which assembles the app, its dependencies and `run.sh` for any language. One `template.yaml` (or Dockerfile, or workflow) per cloud is enough — no files per language. See [apx-aws-lambda](https://github.com/actionplatform/apx-aws-lambda) for the real thing: `template.yaml` with the runtime chosen by language, a `Makefile` with one line, `requirements/` with the least-privilege policy.
|
|
6
|
+
|
|
7
|
+
The platform calls the target's `readiness(ctx)` after every release, for every scope of the app, and refuses a deploy the checks block. The scope's name arrives as `ctx.stage`.
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
|
|
7
|
-
from action_platform.abc import Plugin, Surface
|
|
7
|
+
from action_platform.abc import Option, Plugin, Surface
|
|
8
8
|
from action_platform.core.context import Context, DeployResult
|
|
9
9
|
from action_platform.logging import logger
|
|
10
10
|
|
|
@@ -15,17 +15,29 @@ from apx_example.tools import register_tools
|
|
|
15
15
|
|
|
16
16
|
class ExamplePlugin(Plugin):
|
|
17
17
|
slug = "example"
|
|
18
|
-
description = "Template plugin: a tool, a command, an overlay, a release strategy, stricter git-flow"
|
|
19
|
-
min_core = "0.
|
|
18
|
+
description = "Template plugin: a tool, a command, a deploy target with readiness, an overlay, a release strategy, stricter git-flow"
|
|
19
|
+
min_core = "0.32"
|
|
20
20
|
needs = ["nothing outside this machine"]
|
|
21
|
+
options = [
|
|
22
|
+
Option(
|
|
23
|
+
"greeting",
|
|
24
|
+
"Greeting",
|
|
25
|
+
"text",
|
|
26
|
+
help="The word example_hello says. The button opens where a value would come from.",
|
|
27
|
+
action_label="Open the docs",
|
|
28
|
+
action_url="https://github.com/actionplatform/apx-example?org={organization}",
|
|
29
|
+
),
|
|
30
|
+
]
|
|
21
31
|
|
|
22
32
|
@property
|
|
23
33
|
def overlays(self) -> Path:
|
|
24
34
|
return Path(__file__).parent / "overlays"
|
|
25
35
|
|
|
26
36
|
def register(self, surface: Surface) -> None:
|
|
37
|
+
self.options = surface.options
|
|
38
|
+
|
|
27
39
|
if surface.mcp is not None:
|
|
28
|
-
register_tools(surface.mcp)
|
|
40
|
+
register_tools(surface.mcp, surface.options)
|
|
29
41
|
|
|
30
42
|
if surface.cli is not None:
|
|
31
43
|
surface.cli.add_typer(cli.app, name="example")
|
|
@@ -33,6 +45,7 @@ class ExamplePlugin(Plugin):
|
|
|
33
45
|
surface.core.replace("gitflow_rules", StrictRules)
|
|
34
46
|
|
|
35
47
|
def after_release(self, ctx: Context) -> None:
|
|
48
|
+
self.options.set("last_release", ctx.next_version)
|
|
36
49
|
logger.info(f"example: released {ctx.next_version} from {ctx.branch}")
|
|
37
50
|
|
|
38
51
|
def after_deploy(self, results: list[DeployResult]) -> None:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""What one call is about, resolved once from the context — the target keeps nothing between calls."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from action_platform.core.context import Context
|
|
9
|
+
|
|
10
|
+
SCRIPT = Path("deploy") / "run.sh"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class Spec:
|
|
15
|
+
root: Path
|
|
16
|
+
stage: str
|
|
17
|
+
version: str
|
|
18
|
+
env: dict[str, str]
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def of(cls, ctx: Context) -> Spec:
|
|
22
|
+
return cls(
|
|
23
|
+
root=ctx.repo_root,
|
|
24
|
+
stage=ctx.stage or "dev",
|
|
25
|
+
version=ctx.next_version,
|
|
26
|
+
env=dict(ctx.env),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def script(self) -> Path:
|
|
31
|
+
return self.root / SCRIPT
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""The deploy target: the core's `DeployTarget` contract, composing one implementation per responsibility (`abc.py`). It decides nothing about the cloud itself — that lives in `cloud.py` and `checks.py`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from action_platform.abc import DeployTarget
|
|
9
|
+
from action_platform.core.context import Check, Context, DeployResult, Diagnosis
|
|
10
|
+
from action_platform.core.exception import DeployError
|
|
11
|
+
from action_platform.logging import logger
|
|
12
|
+
|
|
13
|
+
from apx_example.abc import Cloud, Readiness
|
|
14
|
+
from apx_example.checks import OverlayCheck
|
|
15
|
+
from apx_example.cloud import ScriptCloud
|
|
16
|
+
from apx_example.spec import Spec
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class Parts:
|
|
21
|
+
cloud: Cloud
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ExampleTarget(DeployTarget):
|
|
25
|
+
name = "example"
|
|
26
|
+
|
|
27
|
+
def __init__(self, **_: object) -> None:
|
|
28
|
+
self._last: Context | None = None
|
|
29
|
+
|
|
30
|
+
def spec(self, ctx: Context) -> Spec:
|
|
31
|
+
self._last = ctx
|
|
32
|
+
|
|
33
|
+
return Spec.of(ctx)
|
|
34
|
+
|
|
35
|
+
def parts(self, spec: Spec) -> Parts:
|
|
36
|
+
"""One implementation per responsibility; a test or a subclass swaps one here."""
|
|
37
|
+
return Parts(cloud=ScriptCloud())
|
|
38
|
+
|
|
39
|
+
def checks(self, spec: Spec) -> list[Readiness]:
|
|
40
|
+
return [OverlayCheck()]
|
|
41
|
+
|
|
42
|
+
def preflight(self, ctx: Context) -> None:
|
|
43
|
+
blocking = [c for c in self.readiness(ctx) if c.blocking]
|
|
44
|
+
|
|
45
|
+
if blocking:
|
|
46
|
+
raise DeployError("; ".join(f"{c.id}: {c.detail}" for c in blocking))
|
|
47
|
+
|
|
48
|
+
def readiness(self, ctx: Context) -> list[Check]:
|
|
49
|
+
spec = self.spec(ctx)
|
|
50
|
+
|
|
51
|
+
return [check.run(spec) for check in self.checks(spec)]
|
|
52
|
+
|
|
53
|
+
def deploy(self, ctx: Context) -> DeployResult:
|
|
54
|
+
spec = self.spec(ctx)
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
url = self.parts(spec).cloud.ship(spec)
|
|
58
|
+
except DeployError as e:
|
|
59
|
+
logger.info("example: %s failed on %s", spec.version, spec.stage)
|
|
60
|
+
|
|
61
|
+
return DeployResult(
|
|
62
|
+
ok=False, target=self.name, version=spec.version, error=str(e)
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
logger.info("example: deployed %s to %s", spec.version, spec.stage)
|
|
66
|
+
|
|
67
|
+
return DeployResult(ok=True, target=self.name, version=spec.version, url=url)
|
|
68
|
+
|
|
69
|
+
def verify(self, version: str, stage: str | None = None) -> bool:
|
|
70
|
+
spec = self._spec_for(stage)
|
|
71
|
+
|
|
72
|
+
return self.parts(spec).cloud.version(spec) == version
|
|
73
|
+
|
|
74
|
+
def diagnose(self, ctx: Context) -> Diagnosis:
|
|
75
|
+
spec = self.spec(ctx)
|
|
76
|
+
running = self.parts(spec).cloud.version(spec)
|
|
77
|
+
|
|
78
|
+
return Diagnosis(
|
|
79
|
+
ok=running is not None,
|
|
80
|
+
target=self.name,
|
|
81
|
+
status="running" if running else "missing",
|
|
82
|
+
version=running,
|
|
83
|
+
details={"scope": spec.stage},
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
def delete(self, ctx: Context) -> None:
|
|
87
|
+
spec = self.spec(ctx)
|
|
88
|
+
self.parts(spec).cloud.remove(spec)
|
|
89
|
+
|
|
90
|
+
def _spec_for(self, stage: str | None) -> Spec:
|
|
91
|
+
"""`verify` comes without a context: the last one this target saw, on the stage asked for."""
|
|
92
|
+
base = Spec.of(self._last or Context(repo_root=Path.cwd()))
|
|
93
|
+
|
|
94
|
+
return Spec(base.root, stage or base.stage, base.version, base.env)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""MCP tools. They come out as `example_<name>`; annotate inputs and return a model so the client gets schemas. `options` is the plugin's own store — a file on a machine, a table on the hosted platform."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Annotated, Any
|
|
6
|
+
|
|
7
|
+
from action_platform.mcp.annotations import READ_ONLY, WRITES_LOCAL
|
|
8
|
+
from action_platform.plugins import Options
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Greeting(BaseModel):
|
|
13
|
+
greeting: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Remembered(BaseModel):
|
|
17
|
+
key: str
|
|
18
|
+
value: Any
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def register_tools(mcp: Any, options: Options) -> None:
|
|
22
|
+
@mcp.tool(annotations=READ_ONLY)
|
|
23
|
+
def hello(
|
|
24
|
+
name: Annotated[str, Field(description="Who to greet")] = "world",
|
|
25
|
+
) -> Greeting:
|
|
26
|
+
"""Say hello — the smallest tool a plugin can add. The word comes from the plugin's options when set."""
|
|
27
|
+
return Greeting(greeting=f"{options.get('greeting', 'hello')} {name}")
|
|
28
|
+
|
|
29
|
+
@mcp.tool(annotations=WRITES_LOCAL)
|
|
30
|
+
def remember(key: str, value: str) -> Remembered:
|
|
31
|
+
"""Store a value in the plugin's options — the platform keeps it for the next call."""
|
|
32
|
+
options.set(key, value)
|
|
33
|
+
|
|
34
|
+
return Remembered(key=key, value=value)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-example
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Template for an Action Platform plugin: tools, a CLI command, an overlay, a release strategy, a replaced slot, lifecycle hooks.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
7
|
Requires-Python: >=3.11
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
|
-
Requires-Dist: action-platform>=0.
|
|
10
|
+
Requires-Dist: action-platform>=0.32
|
|
11
11
|
Provides-Extra: dev
|
|
12
12
|
Requires-Dist: pytest>=8; extra == "dev"
|
|
13
13
|
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
@@ -20,17 +20,25 @@ Template for an [Action Platform](https://github.com/actionplatform/action-platf
|
|
|
20
20
|
|
|
21
21
|
| File | Extension point |
|
|
22
22
|
|---|---|
|
|
23
|
-
| `plugin.py` | the `Plugin`: slug, `needs`, `register`, `after_release`, `after_deploy` |
|
|
24
|
-
| `tools.py` |
|
|
23
|
+
| `plugin.py` | the `Plugin`: slug, `needs`, `options` (one with a setup button), `register`, `after_release`, `after_deploy` |
|
|
24
|
+
| `tools.py` | MCP tools `example_hello` and `example_remember`, with input and output schemas; `remember` writes the plugin's options store |
|
|
25
25
|
| `cli.py` | `action-platform example hello` |
|
|
26
26
|
| `rules.py` | a replaced core slot (`gitflow_rules`) — stricter branch kinds while the plugin is enabled |
|
|
27
27
|
| `release.py` | named providers: `[release] strategy = "calver"`, `[release] changelog = "plain"` |
|
|
28
|
+
| `target.py` | the `DeployTarget` for the `example` cloud — `preflight`, `readiness`, `deploy`, `verify`, `diagnose`, `delete` — composing the parts below through `parts(spec)` |
|
|
29
|
+
| `abc.py`, `spec.py` | one ABC per responsibility (`Cloud`, `Readiness`); a frozen `Spec` per call |
|
|
30
|
+
| `cloud.py`, `checks.py` | the implementations: the overlay's script (streams its output to the job log), the readiness checks |
|
|
31
|
+
| `tests/fake.py`, `tests/live/` | the cloud in memory for fast tests; a suite against the real destination, skipped without it |
|
|
28
32
|
| `overlays/` | a cloud overlay `example` — plain files, copied as they are by `action-platform cloud set example`; add a `cookiecutter.json` only when the files need rendering |
|
|
29
33
|
|
|
34
|
+
## For agents and editors
|
|
35
|
+
|
|
36
|
+
`SPEC.md` is the contract a plugin follows. `skills/create-plugin/SKILL.md` walks an agent through creating `apx-<slug>` from here — installable in Claude Code (`/plugin marketplace add actionplatform/apx-example`, then `/plugin install apx-example@apx-example`), read by Codex through `.codex-plugin/`, and mirrored for Cursor in `.cursor/rules/plugin.mdc`. `AGENTS.md` holds the repository rules every agent reads.
|
|
37
|
+
|
|
30
38
|
## Use this template
|
|
31
39
|
|
|
32
40
|
1. Create a repository from it, named `apx-<slug>`.
|
|
33
|
-
2. Rename `apx_example` → `apx_<slug>`, `example` → `<slug>` in `pyproject.toml` (package name, entry points), `plugin.py` (`slug`), `cli.py`, `overlays/index.json`.
|
|
41
|
+
2. Rename `apx_example` → `apx_<slug>`, `example` → `<slug>` in `pyproject.toml` (package name, entry points), `plugin.py` (`slug`), `target.py` (`name`), `cli.py`, `overlays/index.json`.
|
|
34
42
|
3. Delete what you do not need; a plugin with only `plugin.py` and one tool is fine.
|
|
35
43
|
4. `pip install -e ".[dev]"`, `pytest`, `action-platform plugin list` (shows `example` once installed).
|
|
36
44
|
5. Publish to PyPI; open a pull request to [plugins-index](https://github.com/actionplatform/plugins-index) with `<slug>.json`.
|
|
@@ -2,10 +2,15 @@ LICENSE
|
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
4
|
apx_example/__init__.py
|
|
5
|
+
apx_example/abc.py
|
|
6
|
+
apx_example/checks.py
|
|
5
7
|
apx_example/cli.py
|
|
8
|
+
apx_example/cloud.py
|
|
6
9
|
apx_example/plugin.py
|
|
7
10
|
apx_example/release.py
|
|
8
11
|
apx_example/rules.py
|
|
12
|
+
apx_example/spec.py
|
|
13
|
+
apx_example/target.py
|
|
9
14
|
apx_example/tools.py
|
|
10
15
|
apx_example.egg-info/PKG-INFO
|
|
11
16
|
apx_example.egg-info/SOURCES.txt
|
|
@@ -16,4 +21,5 @@ apx_example.egg-info/top_level.txt
|
|
|
16
21
|
apx_example/overlays/index.json
|
|
17
22
|
apx_example/overlays/cloud/example/DEPLOY.md
|
|
18
23
|
apx_example/overlays/cloud/example/deploy/run.sh
|
|
19
|
-
tests/test_plugin.py
|
|
24
|
+
tests/test_plugin.py
|
|
25
|
+
tests/test_target.py
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "apx-example"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Template for an Action Platform plugin: tools, a CLI command, an overlay, a release strategy, a replaced slot, lifecycle hooks."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
7
7
|
requires-python = ">=3.11"
|
|
8
8
|
authors = [{ name = "Action Platform", email = "cloud@actionplatform.io" }]
|
|
9
|
-
dependencies = ["action-platform>=0.
|
|
9
|
+
dependencies = ["action-platform>=0.32"]
|
|
10
10
|
|
|
11
11
|
[project.optional-dependencies]
|
|
12
12
|
dev = ["pytest>=8", "ruff>=0.6", "action-platform[mcp]"]
|
|
@@ -14,6 +14,9 @@ dev = ["pytest>=8", "ruff>=0.6", "action-platform[mcp]"]
|
|
|
14
14
|
[project.entry-points."action_platform.plugins"]
|
|
15
15
|
example = "apx_example:ExamplePlugin"
|
|
16
16
|
|
|
17
|
+
[project.entry-points."action_platform.deploy_target"]
|
|
18
|
+
example = "apx_example.target:ExampleTarget"
|
|
19
|
+
|
|
17
20
|
[project.entry-points."action_platform.release_strategy"]
|
|
18
21
|
calver = "apx_example.release:Calver"
|
|
19
22
|
|
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
from tempfile import TemporaryDirectory
|
|
8
8
|
|
|
9
9
|
from action_platform.core.flow import gitflow
|
|
10
|
-
from action_platform.core.scaffold.
|
|
10
|
+
from action_platform.core.scaffold.catalog import Matrix, with_plugin_clouds
|
|
11
11
|
from action_platform.core.wiring import wired
|
|
12
12
|
from action_platform.plugins import Loaded, Plugins, PluginState, registry
|
|
13
13
|
|
|
@@ -54,6 +54,12 @@ class ExamplePluginTest(unittest.TestCase):
|
|
|
54
54
|
self.assertEqual([c.name for c in merged.clouds], ["example"])
|
|
55
55
|
self.assertEqual(merged.cloud("example").source, "example")
|
|
56
56
|
|
|
57
|
+
def test_an_option_can_carry_a_setup_button(self):
|
|
58
|
+
greeting = next(o for o in ExamplePlugin.options if o.key == "greeting")
|
|
59
|
+
|
|
60
|
+
self.assertEqual(greeting.as_dict()["action_label"], "Open the docs")
|
|
61
|
+
self.assertIn("{organization}", greeting.action_url)
|
|
62
|
+
|
|
57
63
|
def test_release_providers(self):
|
|
58
64
|
self.assertTrue(Calver().next("1.0.0", "patch", False, []).count(".") == 2)
|
|
59
65
|
self.assertIn("- feat: x", Plain().render("1.0.0", ["feat: x"]))
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from tempfile import TemporaryDirectory
|
|
4
|
+
|
|
5
|
+
from action_platform.core.context import Context
|
|
6
|
+
|
|
7
|
+
from apx_example.target import ExampleTarget, Parts
|
|
8
|
+
from tests.fake import FakeCloud
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FakeTarget(ExampleTarget):
|
|
12
|
+
def __init__(self, cloud: FakeCloud) -> None:
|
|
13
|
+
super().__init__()
|
|
14
|
+
self.cloud = cloud
|
|
15
|
+
|
|
16
|
+
def parts(self, spec):
|
|
17
|
+
return Parts(cloud=self.cloud)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TargetTest(unittest.TestCase):
|
|
21
|
+
def setUp(self):
|
|
22
|
+
self.tmp = TemporaryDirectory()
|
|
23
|
+
self.addCleanup(self.tmp.cleanup)
|
|
24
|
+
self.root = Path(self.tmp.name)
|
|
25
|
+
|
|
26
|
+
def ctx(self, stage="dev", version="1.0.0"):
|
|
27
|
+
return Context(repo_root=self.root, stage=stage, next_version=version)
|
|
28
|
+
|
|
29
|
+
def test_deploy_ships_the_version_to_the_scope_and_verify_sees_it(self):
|
|
30
|
+
cloud = FakeCloud()
|
|
31
|
+
target = FakeTarget(cloud)
|
|
32
|
+
|
|
33
|
+
result = target.deploy(self.ctx(version="1.2.0"))
|
|
34
|
+
|
|
35
|
+
self.assertTrue(result.ok)
|
|
36
|
+
self.assertEqual(result.url, "https://dev.example.test")
|
|
37
|
+
self.assertTrue(target.verify("1.2.0", "dev"))
|
|
38
|
+
self.assertFalse(target.verify("1.2.0", "prod"))
|
|
39
|
+
|
|
40
|
+
def test_a_failed_ship_is_a_failed_result_with_the_reason(self):
|
|
41
|
+
result = FakeTarget(FakeCloud(fails="quota exceeded")).deploy(self.ctx())
|
|
42
|
+
|
|
43
|
+
self.assertFalse(result.ok)
|
|
44
|
+
self.assertIn("quota exceeded", result.error)
|
|
45
|
+
|
|
46
|
+
def test_diagnose_and_delete(self):
|
|
47
|
+
target = FakeTarget(FakeCloud())
|
|
48
|
+
target.deploy(self.ctx())
|
|
49
|
+
|
|
50
|
+
self.assertEqual(target.diagnose(self.ctx()).version, "1.0.0")
|
|
51
|
+
|
|
52
|
+
target.delete(self.ctx())
|
|
53
|
+
|
|
54
|
+
self.assertEqual(target.diagnose(self.ctx()).status, "missing")
|
|
55
|
+
|
|
56
|
+
def test_readiness_names_the_overlay(self):
|
|
57
|
+
missing = ExampleTarget().readiness(self.ctx())
|
|
58
|
+
(self.root / "deploy").mkdir()
|
|
59
|
+
(self.root / "deploy" / "run.sh").write_text("#!/bin/sh\necho ok\n")
|
|
60
|
+
present = ExampleTarget().readiness(self.ctx())
|
|
61
|
+
|
|
62
|
+
self.assertFalse(missing[0].ok)
|
|
63
|
+
self.assertEqual(missing[0].fix, "action-platform cloud set example")
|
|
64
|
+
self.assertTrue(present[0].ok)
|
|
65
|
+
|
|
66
|
+
def test_the_script_cloud_runs_the_overlay_and_remembers_the_version(self):
|
|
67
|
+
(self.root / "deploy").mkdir()
|
|
68
|
+
(self.root / "deploy" / "run.sh").write_text(
|
|
69
|
+
'#!/bin/sh\necho "$SCOPE $VERSION"\n'
|
|
70
|
+
)
|
|
71
|
+
target = ExampleTarget()
|
|
72
|
+
|
|
73
|
+
self.assertTrue(target.deploy(self.ctx(version="2.0.0")).ok)
|
|
74
|
+
self.assertTrue(target.verify("2.0.0", "dev"))
|
|
75
|
+
|
|
76
|
+
def test_a_failing_script_fails_the_deploy(self):
|
|
77
|
+
(self.root / "deploy").mkdir()
|
|
78
|
+
(self.root / "deploy" / "run.sh").write_text("#!/bin/sh\necho broken; exit 3\n")
|
|
79
|
+
|
|
80
|
+
result = ExampleTarget().deploy(self.ctx())
|
|
81
|
+
|
|
82
|
+
self.assertFalse(result.ok)
|
|
83
|
+
self.assertIn("broken", result.error)
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
# Deploy — example
|
|
2
|
-
|
|
3
|
-
This project deploys to the example target. The files under `deploy/` came from the `example` plugin's overlay, copied as they are — no templating. Replace them with what your target needs (a `template.yaml`, a `Dockerfile`, a workflow) and ship the matching `DeployTarget` under the `action_platform.deploy_target` entry-point group.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"""MCP tools. They come out as `example_<name>`; annotate inputs and return a model or a typed dict so the client gets schemas."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from typing import Annotated, Any
|
|
6
|
-
|
|
7
|
-
from action_platform.mcp.annotations import READ_ONLY
|
|
8
|
-
from pydantic import BaseModel, Field
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Greeting(BaseModel):
|
|
12
|
-
greeting: str
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def register_tools(mcp: Any) -> None:
|
|
16
|
-
@mcp.tool(annotations=READ_ONLY)
|
|
17
|
-
def hello(
|
|
18
|
-
name: Annotated[str, Field(description="Who to greet")] = "world",
|
|
19
|
-
) -> Greeting:
|
|
20
|
-
"""Say hello — the smallest tool a plugin can add."""
|
|
21
|
-
return Greeting(greeting=f"hello {name}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|