actions-tools 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl

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 actions-tools might be problematic. Click here for more details.

actions/core.py CHANGED
@@ -1,36 +1,46 @@
1
1
  import os
2
+ import random
2
3
  import re
3
- from typing import Union
4
+ import string
5
+ from contextlib import contextmanager
6
+ from typing import List, Optional
4
7
 
5
8
 
6
- true = ["y", "yes", "true", "on"]
7
- false = ["n", "no", "false", "off"]
9
+ # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
10
+
11
+
12
+ _true = ["y", "yes", "true", "on"]
13
+ _false = ["n", "no", "false", "off"]
8
14
 
9
15
  _indent = 0
16
+ _endtoken = ""
10
17
 
11
18
 
12
- def debug(message: str):
13
- print(f"::debug::{message}")
19
+ # Core
14
20
 
15
21
 
16
- def info(message: str, **kwargs):
17
- print(" " * _indent + message, **kwargs)
22
+ def debug(message: str, *args, **kwargs):
23
+ print(f"::debug::{message}", *args, **kwargs)
18
24
 
19
25
 
20
- def notice(message: str):
21
- print(f"::notice::{message}")
26
+ def info(message: str, *args, **kwargs):
27
+ print(" " * _indent + message, *args, **kwargs)
22
28
 
23
29
 
24
- def warn(message: str):
25
- print(f"::warning::{message}")
30
+ def notice(message: str, *args, **kwargs):
31
+ print(f"::notice::{message}", *args, **kwargs)
26
32
 
27
33
 
28
- def error(message: str):
29
- """
30
- TODO: Add error options
31
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-error-message
32
- """
33
- print(f"::error::{message}")
34
+ def warn(message: str, *args, **kwargs):
35
+ print(f"::warning::{message}", *args, **kwargs)
36
+
37
+
38
+ def error(message: str, *args, **kwargs):
39
+ print(f"::error::{message}", *args, **kwargs)
40
+
41
+
42
+ def is_debug() -> bool:
43
+ return bool(os.getenv("RUNNER_DEBUG"))
34
44
 
35
45
 
36
46
  def set_failed(message: str):
@@ -50,24 +60,62 @@ def end_group():
50
60
  print("::endgroup::")
51
61
 
52
62
 
53
- def start_indent(spaces: int):
54
- global _indent
55
- _indent = spaces
63
+ @contextmanager
64
+ def group(title: str):
65
+ print(f"::group::{title}")
66
+ try:
67
+ yield info
68
+ finally:
69
+ print("::endgroup::")
56
70
 
57
71
 
58
- def end_indent():
59
- global _indent
60
- _indent = 0
72
+ def stop_commands(endtoken: str = ""):
73
+ global _endtoken
74
+ if not endtoken:
75
+ r = random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=16) # NOSONAR
76
+ endtoken = "".join(r)
77
+ _endtoken = endtoken
78
+ print(f"::stop-commands::{_endtoken}")
79
+
80
+
81
+ def start_commands(endtoken: str = ""):
82
+ global _endtoken
83
+ if not endtoken:
84
+ endtoken = _endtoken
85
+ print(f"::{endtoken}::")
61
86
 
62
87
 
63
88
  def set_output(output: str, value: str):
64
89
  with open(os.environ["GITHUB_OUTPUT"], "a") as f:
90
+ # noinspection PyTypeChecker
65
91
  print(f"{output}={value}", file=f)
66
92
 
67
93
 
68
- def set_env(var: str, value: str):
94
+ def set_env(name: str, value: str):
69
95
  with open(os.environ["GITHUB_ENV"], "a") as f:
70
- print(f"{var}={value}", file=f)
96
+ # noinspection PyTypeChecker
97
+ print(f"{name}={value}", file=f)
98
+
99
+
100
+ def add_path(path: str):
101
+ with open(os.environ["GITHUB_PATH"], "a") as f:
102
+ # noinspection PyTypeChecker
103
+ print(path, file=f)
104
+
105
+
106
+ def set_state(name: str, value: str) -> str:
107
+ if name.startswith("STATE_"):
108
+ name = name[6:]
109
+ with open(os.environ["GITHUB_STATE"], "a") as f:
110
+ # noinspection PyTypeChecker
111
+ print(f"{name}={value}", file=f)
112
+ return f"STATE_{name}"
113
+
114
+
115
+ def get_state(name: str) -> str:
116
+ if name.startswith("STATE_"):
117
+ name = name[6:]
118
+ return os.getenv(f"STATE_{name}", "")
71
119
 
72
120
 
73
121
  def summary(text: str, nlc=1):
@@ -77,46 +125,91 @@ def summary(text: str, nlc=1):
77
125
  :param nlc:int: New Line Count
78
126
  :return:
79
127
  """
80
- new_lines = "\n" * nlc
128
+ new_lines = os.linesep * nlc
81
129
  with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
130
+ # noinspection PyTypeChecker
82
131
  print(f"{text}{new_lines}", file=f)
83
132
 
84
133
 
85
- def get_input(name: str, req=False, low=False, strip=True, boolean=False, split="") -> Union[str, bool, list]:
134
+ # Inputs
135
+
136
+
137
+ def get_input(name: str, req=False, low=False, strip=True) -> str:
86
138
  """
87
139
  Get Input by Name
88
140
  :param name: str: Input Name
89
141
  :param req: bool: If Required
90
142
  :param low: bool: To Lower
91
143
  :param strip: bool: To Strip
92
- :param boolean: bool: If Boolean
93
- :param split: str: To Split
94
- :return: Union[str, bool, list]
144
+ :return: str
95
145
  """
96
- value = os.environ.get(f"INPUT_{name.upper()}", "")
97
- if boolean:
98
- value = value.strip().lower()
99
- if req and value not in true + false:
100
- raise ValueError(f"Error Validating a Required Boolean Input: {name}")
101
- if value in ["y", "yes", "true", "on"]:
102
- return True
103
- return False
104
-
105
- if split:
106
- result = []
107
- for x in re.split(split, value):
108
- result.append(_get_str_value(x, low, strip))
109
- return result
110
-
111
- value = _get_str_value(value, low, strip)
146
+ value = os.getenv(f"INPUT_{name.upper()}", "")
147
+ value = _get_str_value(value, strip, low)
112
148
  if req and not value:
113
- raise ValueError(f"Error Parsing a Required Input: {name}")
149
+ raise ValueError(f"Error Parsing Required Input: {name} -> {value}")
114
150
  return value
115
151
 
116
152
 
117
- def _get_str_value(value, low=False, strip=True):
153
+ def get_list(name: str, split: str = "[,|\n]", req=False, low=False, strip=True) -> List[str]:
154
+ """
155
+ Get Input by Name
156
+ :param name: str: Input Name
157
+ :param split: str: Split Regex
158
+ :param req: bool: If Required
159
+ :param strip: bool: To Strip
160
+ :param low: bool: To Lowercase
161
+ :return: list
162
+ """
163
+ value = os.getenv(f"INPUT_{name.upper()}", "")
164
+ value = _get_str_value(value, strip, low)
165
+ if req and not value.strip():
166
+ raise ValueError(f"Error Parsing Required Input: {name} -> {value}")
167
+ results = []
168
+ for x in re.split(split, value):
169
+ results.append(_get_str_value(x, strip, low))
170
+ return results
171
+
172
+
173
+ def get_bool(name: str, req=False) -> bool:
174
+ """
175
+ Get Boolean Input by Name
176
+ :param name: str: Input Name
177
+ :param req: bool: If Required
178
+ :return: bool
179
+ """
180
+ value = os.getenv(f"INPUT_{name.upper()}", "").strip().lower()
181
+ if req and value not in _true + _false:
182
+ raise ValueError(f"Error Parsing Required Input: {name} -> {value}")
183
+ if value in _true:
184
+ return True
185
+ return False
186
+
187
+
188
+ def _get_str_value(value, strip=True, low=False) -> str:
118
189
  if strip:
119
190
  value = value.strip()
120
191
  if low:
121
192
  value = value.lower()
122
193
  return value
194
+
195
+
196
+ # Additional
197
+
198
+
199
+ def command(name: str, value: Optional[str] = ""):
200
+ print(f"::{name}::{value}")
201
+
202
+
203
+ def get_random(length: int = 16) -> str:
204
+ r = random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=length) # NOSONAR
205
+ return "".join(r)
206
+
207
+
208
+ def start_indent(spaces: int = 2):
209
+ global _indent
210
+ _indent = spaces
211
+
212
+
213
+ def end_indent():
214
+ global _indent
215
+ _indent = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: actions-tools
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: GitHub Actions Tools for Python
5
5
  Author: Shane
6
6
  License: GPL-3.0
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3 :: Only
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Operating System :: OS Independent
18
18
  Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
@@ -21,6 +21,7 @@ Requires-Python: >=3.10
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
23
 
24
+ [![Publish](https://img.shields.io/github/actions/workflow/status/cssnr/actions-tools/publish.yaml?logo=python&logoColor=white&label=publish)](https://github.com/cssnr/actions-tools/actions/workflows/publish.yaml)
24
25
  [![Release](https://img.shields.io/github/actions/workflow/status/cssnr/actions-tools/release.yaml?logo=github&logoColor=white&label=release)](https://github.com/cssnr/actions-tools/actions/workflows/release.yaml)
25
26
  [![Test](https://img.shields.io/github/actions/workflow/status/cssnr/actions-tools/test.yaml?logo=github&logoColor=white&label=test)](https://github.com/cssnr/actions-tools/actions/workflows/test.yaml)
26
27
  [![Lint](https://img.shields.io/github/actions/workflow/status/cssnr/actions-tools/lint.yaml?logo=github&logoColor=white&label=lint)](https://github.com/cssnr/actions-tools/actions/workflows/lint.yaml)
@@ -28,8 +29,8 @@ License-File: LICENSE
28
29
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cssnr_actions-tools&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cssnr_actions-tools)
29
30
  [![PyPI](https://img.shields.io/pypi/v/actions-tools?logo=python&logoColor=white&label=PyPI)](https://pypi.org/project/actions-tools/)
30
31
  [![GitHub Release Version](https://img.shields.io/github/v/release/cssnr/actions-tools?logo=github)](https://github.com/cssnr/actions-tools/releases/latest)
31
- [![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/actions-tools?logo=htmx&logoColor=white)](https://github.com/cssnr/actions-tools)
32
32
  [![TOML Python Version](https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcssnr%2Factions-tools%2Frefs%2Fheads%2Fmaster%2Fpyproject.toml&query=%24.project.requires-python&logo=python&logoColor=white&label=version)](https://github.com/cssnr/actions-tools)
33
+ [![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/actions-tools?logo=htmx&logoColor=white)](https://github.com/cssnr/actions-tools)
33
34
  [![GitHub Last Commit](https://img.shields.io/github/last-commit/cssnr/actions-tools?logo=github&logoColor=white&label=updated)](https://github.com/cssnr/actions-tools/graphs/commit-activity)
34
35
  [![GitHub Repo Stars](https://img.shields.io/github/stars/cssnr/actions-tools?style=flat&logo=github&logoColor=white)](https://github.com/cssnr/actions-tools/stargazers)
35
36
  [![GitHub Org Stars](https://img.shields.io/github/stars/cssnr?style=flat&logo=github&logoColor=white&label=org%20stars)](https://cssnr.github.io/)
@@ -39,22 +40,35 @@ License-File: LICENSE
39
40
 
40
41
  - [Install](#Install)
41
42
  - [Usage](#Usage)
42
- - [Development](#Development)
43
+ - [Support](#Support)
43
44
  - [Contributing](#Contributing)
44
45
 
45
- GitHub Actions Tools for Python.
46
-
47
46
  > [!WARNING]
48
47
  > This project is in development and is NOT stable!
49
48
 
49
+ GitHub Actions Tools for Python.
50
+
50
51
  ## Install
51
52
 
53
+ From PyPI: https://pypi.org/p/actions-tools
54
+
55
+ ```shell
56
+ python -m pip install actions-tools
57
+ ```
58
+
59
+ From source:
60
+
52
61
  ```shell
53
- #python -m pip install actions-tools
54
62
  git clone https://github.com/cssnr/actions-tools
55
63
  python -m pip install -e actions-tools
56
64
  ```
57
65
 
66
+ Uninstall:
67
+
68
+ ```shell
69
+ python -m pip uninstall actions-tools
70
+ ```
71
+
58
72
  ## Usage
59
73
 
60
74
  Functionality from @actions/toolkit
@@ -63,25 +77,43 @@ Functionality from @actions/toolkit
63
77
  from actions import core
64
78
 
65
79
  # Input
66
- name = core.get_input('name')
80
+ my_str = core.get_input('string')
81
+ my_bool = core.get_bool('boolean')
82
+ my_list = core.get_list('list')
67
83
 
68
84
  # Logging
85
+ core.info("info") # alias for print
69
86
  core.debug("debug")
70
- core.info("info") # print
87
+
88
+ # Annotations
89
+ core.notice("notice")
71
90
  core.warn("warn")
72
91
  core.error("error")
73
92
 
74
93
  # Blocks
75
- core.start_group("Test")
76
- core.info('This folded.')
94
+ core.start_group("Title")
95
+ core.info('This is folded.')
77
96
  core.end_group()
78
97
 
98
+ with core.group("Title") as p:
99
+ p('This is folded.')
100
+ core.info('Also folded.')
101
+
79
102
  # Summary
80
103
  core.summary('## Test Action')
81
104
 
82
- # Output
83
- core.set_env('VAR', 'value')
84
- core.set_output('name', 'god')
105
+ # Environment
106
+ core.set_env('NAME', 'value')
107
+
108
+ # State
109
+ name = core.set_state('name', 'value')
110
+ value = core.get_state('name')
111
+
112
+ # System Path
113
+ core.add_path('/dev/null')
114
+
115
+ # Outputs
116
+ core.set_output('name', 'cssnr')
85
117
 
86
118
  # Abort
87
119
  core.set_failed("Mayday!")
@@ -92,64 +124,40 @@ Functionality new in actions-tools
92
124
  ```python
93
125
  from actions import core
94
126
 
127
+ # Commands
128
+ core.command('warning', 'Warned!')
129
+
130
+ # Random
131
+ rand = core.get_random(32)
132
+
95
133
  # Indent
96
134
  core.start_indent(4)
97
- core.info('Indented') # only works with core.info
135
+ core.info('Indented') # only works with core.info
98
136
  core.end_indent()
99
137
  ```
100
138
 
101
- # Development
139
+ # Support
102
140
 
103
- ### Install
141
+ For general help or to request a feature, see:
104
142
 
105
- Install the package from source:
143
+ - Q&A Discussion: https://github.com/cssnr/actions-tools/discussions/categories/q-a
144
+ - Request a Feature: https://github.com/cssnr/actions-tools/discussions/categories/feature-requests
145
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
106
146
 
107
- ```shell
108
- python -m pip install -U pip
109
- python -m pip install -Ur requirements.txt
110
- python -m pip install -e .
111
- ```
112
-
113
- Prettier is used to format yaml, json and md.
114
-
115
- ```shell
116
- npm install -g prettier
117
- ```
118
-
119
- To Uninstall:
120
-
121
- ```shell
122
- python -m pip uninstall actions-tools
123
- ```
124
-
125
- ### Test
126
-
127
- First [Install](#Install), then run:
147
+ If you are experiencing an issue/bug or getting unexpected results, you can:
128
148
 
129
- ```shell
130
- coverage run -m pytest
131
- coverage report -m
132
- ```
133
-
134
- ### Building
135
-
136
- Build the project locally:
137
-
138
- ```shell
139
- python -m pip install -U pip
140
- python -m pip install -Ur requirements.txt
141
- python -m pip build
142
- ```
143
-
144
- Install the built package:
145
-
146
- ```shell
147
- python -m pip install dist/actions_tools-0.0.1-py3-none-any.whl
148
- ```
149
+ - Report an Issue: https://github.com/cssnr/actions-tools/issues
150
+ - Provide General Feedback: [https://cssnr.github.io/feedback/](https://cssnr.github.io/feedback/?app=actions-tools)
151
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
149
152
 
150
153
  # Contributing
151
154
 
152
- Currently, the best way to contribute to this project is to star this project on GitHub.
155
+ > [!TIP]
156
+ > See the [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on testing and building.
157
+
158
+ Currently, the best way to contribute to this project is to star this project on GitHub, open a
159
+ [feature request](https://github.com/cssnr/actions-tools/discussions/categories/feature-requests)
160
+ or report any [issues](https://github.com/cssnr/actions-tools/issues) you find.
153
161
 
154
162
  Additionally, you can support other GitHub Actions I have published:
155
163
 
@@ -0,0 +1,7 @@
1
+ actions/__init__.py,sha256=ZibxMd7km3HsR9w3bSQClEPt2dayYRNUGTOCf3oRHu0,273
2
+ actions/core.py,sha256=w-gSEc8b9kPRA0DxQzNWzmLn3Td-OLMAfNpAwgfgG0E,5073
3
+ actions_tools-0.0.3.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
4
+ actions_tools-0.0.3.dist-info/METADATA,sha256=JDjPV_77Rz2ruysPJL8XqNQw2CFu5tVtPiSICells-E,7249
5
+ actions_tools-0.0.3.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
6
+ actions_tools-0.0.3.dist-info/top_level.txt,sha256=5apM5x80QlJcGbACn1v3fkmIuL1-XQCKcItJre7w7Tw,8
7
+ actions_tools-0.0.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- actions/__init__.py,sha256=ZibxMd7km3HsR9w3bSQClEPt2dayYRNUGTOCf3oRHu0,273
2
- actions/core.py,sha256=C0ERbAGnIk9gGuCVZI5KHOfQQUp5yGH-DB8d5nNDfXU,2767
3
- actions_tools-0.0.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
4
- actions_tools-0.0.1.dist-info/METADATA,sha256=81Ngkerc2f55fF0qfr8yCgQPyxYcAYqZPi7o9cuF1Lo,6256
5
- actions_tools-0.0.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
- actions_tools-0.0.1.dist-info/top_level.txt,sha256=5apM5x80QlJcGbACn1v3fkmIuL1-XQCKcItJre7w7Tw,8
7
- actions_tools-0.0.1.dist-info/RECORD,,