actionskit 0.0.1__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.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: actionskit
3
+ Version: 0.0.1
4
+ Summary: Add your description here
5
+ Author: William Woodruff
6
+ Author-email: William Woodruff <william@yossarian.net>
7
+ Requires-Python: >=3.14
8
+ Description-Content-Type: text/markdown
9
+
10
+ # actionskit
11
+
12
+ _actionskit_ is a Python package that provides
13
+ convenient Python APIs for various GitHub Actions
14
+ features.
15
+
16
+ ## Usage
17
+
18
+ ```shell
19
+ uv add actionskit
20
+ ```
@@ -0,0 +1,11 @@
1
+ # actionskit
2
+
3
+ _actionskit_ is a Python package that provides
4
+ convenient Python APIs for various GitHub Actions
5
+ features.
6
+
7
+ ## Usage
8
+
9
+ ```shell
10
+ uv add actionskit
11
+ ```
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "actionskit"
3
+ version = "0.0.1"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ dependencies = []
8
+
9
+ [[project.authors]]
10
+ name = "William Woodruff"
11
+ email = "william@yossarian.net"
12
+
13
+ [dependency-groups]
14
+ dev = [
15
+ "inline-snapshot>=0.37.0",
16
+ "pytest>=9.2.0",
17
+ "ruff>=0.17.6",
18
+ "ty>=0.0.112",
19
+ ]
20
+
21
+ [build-system]
22
+ requires = ["uv_build>=0.13.10,<0.14.0"]
23
+ build-backend = "uv_build"
24
+
25
+ [tool.inline-snapshot]
26
+ format-command = "ruff format --stdin-filename {filename}"
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "actionskit"
3
+ version = "0.0.1"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ authors = [{ name = "William Woodruff", email = "william@yossarian.net" }]
8
+ dependencies = []
9
+
10
+ [dependency-groups]
11
+ dev = [
12
+ "inline-snapshot>=0.37.0",
13
+ "pytest>=9.2.0",
14
+ "ruff>=0.17.6",
15
+ "ty>=0.0.112",
16
+ ]
17
+
18
+ [build-system]
19
+ requires = ["uv_build>=0.13.10,<0.14.0"]
20
+ build-backend = "uv_build"
21
+
22
+ [tool.inline-snapshot]
23
+ format-command = "ruff format --stdin-filename {filename}"
@@ -0,0 +1,3 @@
1
+ from ._global import GLOBAL
2
+
3
+ __all__ = ["GLOBAL"]
@@ -0,0 +1,58 @@
1
+ """
2
+ Global runner state.
3
+ """
4
+
5
+ import functools
6
+ import os
7
+ from collections.abc import Callable
8
+ from pathlib import Path
9
+
10
+
11
+ def _file_path(candidate: str) -> Path:
12
+ """
13
+ Create a `Path` and assert that it points to a real, normal file.
14
+ """
15
+
16
+ path = Path(candidate)
17
+ if not path.is_file():
18
+ raise RuntimeError(f"required normal file is missing: {path!r}")
19
+
20
+ return path
21
+
22
+
23
+ def _env[T](name: str, dest: Callable[..., T]) -> T:
24
+ """
25
+ Get `name` from the environment or raise a runtime error.
26
+
27
+ This is appropriate for early initialization, i.e. our global state.
28
+ """
29
+
30
+ value = os.getenv(name)
31
+ if value is None:
32
+ raise RuntimeError(f"required Action state is missing: {name!r}")
33
+
34
+ return dest(value)
35
+
36
+
37
+ class _Global:
38
+ def __init__(self):
39
+ gha = os.getenv("GITHUB_ACTIONS")
40
+ if gha != "true":
41
+ raise RuntimeError("actionskit can only be used on GitHub Actions")
42
+
43
+ self.github_api_url = _env("GITHUB_API_URL", str)
44
+ self.github_env = _env("GITHUB_ENV", _file_path)
45
+ self.github_path = _env("GITHUB_PATH", _file_path)
46
+ self.github_output = _env("GITHUB_OUTPUT", _file_path)
47
+
48
+ # TODO: Consider exposing more here.
49
+
50
+
51
+ @functools.lru_cache(1)
52
+ def GLOBAL() -> _Global:
53
+ """
54
+ Returns our global singleton.
55
+
56
+ Most users should not need to interact with this.
57
+ """
58
+ return _Global()
@@ -0,0 +1,17 @@
1
+ """
2
+ Common internal functionality.
3
+ """
4
+
5
+
6
+ def frame(name: str, value: str, delim: str) -> str:
7
+ """
8
+ Frame a special file write, e.g. to `GITHUB_ENV` or `GITHUB_OUTPUT`.
9
+
10
+ This assumes that `value` can contain multiple lines.
11
+ """
12
+
13
+ return f"""\
14
+ {name}<<{delim}
15
+ {value}
16
+ {delim}
17
+ """
@@ -0,0 +1,31 @@
1
+ """
2
+ Setting environment variables via `GITHUB_ENV`.
3
+
4
+ See: <https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#setting-an-environment-variable>
5
+ """
6
+
7
+ import re
8
+ import uuid
9
+
10
+ from actionskit import GLOBAL, _utils
11
+
12
+ _NAME_PATTERN = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")
13
+ """
14
+ Roughly mirrors bash's valid identifier pattern.
15
+ """
16
+
17
+
18
+ def set(name: str, value: str) -> None:
19
+ """
20
+ Set an environment variable via `GITHUB_ENV`.
21
+
22
+ Affects subsequent steps in the same job.
23
+ """
24
+
25
+ if not _NAME_PATTERN.fullmatch(name):
26
+ raise RuntimeError(f"invalid variable: {name!r}")
27
+
28
+ framed = _utils.frame(name, value, str(uuid.uuid4()))
29
+
30
+ with GLOBAL().github_env.open(mode="a") as io:
31
+ print(framed, file=io)
@@ -0,0 +1,32 @@
1
+ """
2
+ Setting output variables via `GITHUB_OUTPUT`.
3
+
4
+ See: <https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#setting-an-output-parameter>
5
+ """
6
+
7
+ import re
8
+ import uuid
9
+
10
+ from actionskit import GLOBAL, _utils
11
+
12
+ _NAME_PATTERN = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_-]*$")
13
+ """
14
+ Almost the same as valid environment variable names, except we
15
+ also allow `-`.
16
+
17
+ This is much more restrictive than what GitHub actually allows
18
+ for output names.
19
+ """
20
+
21
+
22
+ def set(name: str, value: str) -> None:
23
+ """
24
+ Set an output variable via `GITHUB_OUTPUT`.
25
+
26
+ Affects subsequent steps in the same job.
27
+ """
28
+
29
+ framed = _utils.frame(name, value, str(uuid.uuid4()))
30
+
31
+ with GLOBAL().github_output.open(mode="a") as io:
32
+ print(framed, file=io)
File without changes