Skip to content

Commit

Permalink
Add: Improve documentation of pontos.github.actions
Browse files Browse the repository at this point in the history
Include ActionOutput to public API and therefore include it in the docs
too. Add more docstrings and examples.
  • Loading branch information
bjoernricks committed Feb 5, 2024
1 parent a182dd1 commit 86bea78
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pontos/github/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#

from .core import ActionIO, Console
from .core import ActionIO, ActionOutput, Console
from .env import GitHubEnvironment
from .errors import GitHubActionsError
from .event import (
Expand All @@ -18,6 +18,7 @@
__all__ = (
"GitHubActionsError",
"ActionIO",
"ActionOutput",
"Console",
"GitHubEnvironment",
"GitHubEvent",
Expand Down
45 changes: 43 additions & 2 deletions pontos/github/actions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from pathlib import Path
from typing import Generator, Optional

from pontos.github.actions.errors import GitHubActionsError
from pontos.typing import SupportsStr

from .errors import GitHubActionsError


def _to_options(
name: Optional[str] = None,
Expand Down Expand Up @@ -55,6 +56,7 @@ def _message(
class Console:
"""
Class for printing messages to the action console
"""

@classmethod
Expand All @@ -63,6 +65,14 @@ def group(cls, title: str):
"""
ContextManager to display a foldable group
.. code-block:: python
from pontos.github.actions import Console
console = Console()
with console.group("my-group"):
console.log("some message)
Args:
title: Title of the group
"""
Expand Down Expand Up @@ -190,6 +200,10 @@ def debug(message: str):


class ActionOutput:
"""
A GitHub Action output
"""

def __init__(self, file: TextIOWrapper) -> None:
self._file = file

Expand All @@ -207,6 +221,10 @@ def write(self, name: str, value: SupportsStr):


class ActionIO:
"""
Class with static methods for handling GitHub Action IO
"""

@staticmethod
def has_output() -> bool:
"""
Expand All @@ -218,9 +236,18 @@ def has_output() -> bool:
@contextmanager
def out() -> Generator[ActionOutput, None, None]:
"""
Create action output
Create an action output to write several output values
An action output can be consumed by another job
Example:
.. code-block:: python
from pontos.github.actions import ActionIO
with ActionIO.out() as out:
out.write("foo", "bar")
out.write("lorem", "ipsum")
"""
output_filename = os.environ.get("GITHUB_OUTPUT")
if not output_filename:
Expand All @@ -239,6 +266,13 @@ def output(name: str, value: SupportsStr):
An action output can be consumed by another job
Example:
.. code-block:: python
from pontos.github.actions import ActionIO
ActionIO.output("foo", "bar")
Args:
name: Name of the output variable
value: Value of the output variable
Expand All @@ -258,6 +292,13 @@ def input(name: str, default: Optional[str] = None) -> Optional[str]:
"""
Get the value of an action input
Example:
.. code-block:: python
from pontos.github.actions import ActionIO
value = ActionIO.input("foo", "bar")
Args:
name: Name of the input variable
default: Use as default if the is no value for the variable
Expand Down

0 comments on commit 86bea78

Please sign in to comment.