actions-tools 0.0.1__py3-none-any.whl → 0.0.2__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 Optional, Union
7
+
8
+
9
+ # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
4
10
 
5
11
 
6
12
  true = ["y", "yes", "true", "on"]
7
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 with_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,11 +125,15 @@ 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
 
134
+ # Inputs
135
+
136
+
85
137
  def get_input(name: str, req=False, low=False, strip=True, boolean=False, split="") -> Union[str, bool, list]:
86
138
  """
87
139
  Get Input by Name
@@ -93,7 +145,7 @@ def get_input(name: str, req=False, low=False, strip=True, boolean=False, split=
93
145
  :param split: str: To Split
94
146
  :return: Union[str, bool, list]
95
147
  """
96
- value = os.environ.get(f"INPUT_{name.upper()}", "")
148
+ value = os.getenv(f"INPUT_{name.upper()}", "")
97
149
  if boolean:
98
150
  value = value.strip().lower()
99
151
  if req and value not in true + false:
@@ -120,3 +172,25 @@ def _get_str_value(value, low=False, strip=True):
120
172
  if low:
121
173
  value = value.lower()
122
174
  return value
175
+
176
+
177
+ # Additional
178
+
179
+
180
+ def command(name: str, value: Optional[str] = ""):
181
+ print(f"::{name}::{value}")
182
+
183
+
184
+ def get_random(length: int = 16):
185
+ r = random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=length) # NOSONAR
186
+ return "".join(r)
187
+
188
+
189
+ def start_indent(spaces: int = 2):
190
+ global _indent
191
+ _indent = spaces
192
+
193
+
194
+ def end_indent():
195
+ global _indent
196
+ _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.2
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)
@@ -39,22 +39,35 @@ License-File: LICENSE
39
39
 
40
40
  - [Install](#Install)
41
41
  - [Usage](#Usage)
42
- - [Development](#Development)
42
+ - [Support](#Support)
43
43
  - [Contributing](#Contributing)
44
44
 
45
- GitHub Actions Tools for Python.
46
-
47
45
  > [!WARNING]
48
46
  > This project is in development and is NOT stable!
49
47
 
48
+ GitHub Actions Tools for Python.
49
+
50
50
  ## Install
51
51
 
52
+ From PyPI: https://pypi.org/p/actions-tools
53
+
54
+ ```shell
55
+ python -m pip install actions-tools
56
+ ```
57
+
58
+ From source:
59
+
52
60
  ```shell
53
- #python -m pip install actions-tools
54
61
  git clone https://github.com/cssnr/actions-tools
55
62
  python -m pip install -e actions-tools
56
63
  ```
57
64
 
65
+ Uninstall:
66
+
67
+ ```shell
68
+ python -m pip uninstall actions-tools
69
+ ```
70
+
58
71
  ## Usage
59
72
 
60
73
  Functionality from @actions/toolkit
@@ -63,25 +76,45 @@ Functionality from @actions/toolkit
63
76
  from actions import core
64
77
 
65
78
  # Input
66
- name = core.get_input('name')
79
+ myStr = core.get_input('myStr')
80
+ myLowerString = core.get_input('myLowerStr', low=1)
81
+ myRequiredStr = core.get_input('myRequiredStr', req=1)
82
+ myBoolean = core.get_input('myBoolean', boolean=1)
83
+ myList = core.get_input('myList', split="[,|\n]")
67
84
 
68
85
  # Logging
86
+ core.info("info") # alias for print
69
87
  core.debug("debug")
70
- core.info("info") # print
88
+
89
+ # Annotations
90
+ core.notice("notice")
71
91
  core.warn("warn")
72
92
  core.error("error")
73
93
 
74
94
  # Blocks
75
95
  core.start_group("Test")
76
- core.info('This folded.')
96
+ core.info('This is folded.')
77
97
  core.end_group()
78
98
 
99
+ with core.with_group("Test") as info:
100
+ info('This is folded.')
101
+ core.info('Also folded.')
102
+
79
103
  # Summary
80
104
  core.summary('## Test Action')
81
105
 
82
- # Output
83
- core.set_env('VAR', 'value')
84
- core.set_output('name', 'god')
106
+ # Environment
107
+ core.set_env('NAME', 'value')
108
+
109
+ # State
110
+ stateName = core.set_state('NAME', 'value')
111
+ stateValue = core.get_state('NAME')
112
+
113
+ # System Path
114
+ core.add_path('/dev/null')
115
+
116
+ # Outputs
117
+ core.set_output('name', 'cssnr')
85
118
 
86
119
  # Abort
87
120
  core.set_failed("Mayday!")
@@ -92,64 +125,40 @@ Functionality new in actions-tools
92
125
  ```python
93
126
  from actions import core
94
127
 
128
+ # Commands
129
+ core.command('warning', 'Warned!')
130
+
131
+ # Random
132
+ myRandom = core.get_random(32)
133
+
95
134
  # Indent
96
135
  core.start_indent(4)
97
- core.info('Indented') # only works with core.info
136
+ core.info('Indented') # only works with core.info
98
137
  core.end_indent()
99
138
  ```
100
139
 
101
- # Development
140
+ # Support
102
141
 
103
- ### Install
142
+ For general help or to request a feature, see:
104
143
 
105
- Install the package from source:
144
+ - Q&A Discussion: https://github.com/cssnr/actions-tools/discussions/categories/q-a
145
+ - Request a Feature: https://github.com/cssnr/actions-tools/discussions/categories/feature-requests
146
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
106
147
 
107
- ```shell
108
- python -m pip install -U pip
109
- python -m pip install -Ur requirements.txt
110
- python -m pip install -e .
111
- ```
148
+ If you are experiencing an issue/bug or getting unexpected results, you can:
112
149
 
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:
128
-
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
- ```
150
+ - Report an Issue: https://github.com/cssnr/actions-tools/issues
151
+ - Provide General Feedback: [https://cssnr.github.io/feedback/](https://cssnr.github.io/feedback/?app=actions-tools)
152
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
149
153
 
150
154
  # Contributing
151
155
 
152
- Currently, the best way to contribute to this project is to star this project on GitHub.
156
+ > [!TIP]
157
+ > See the [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on testing and building.
158
+
159
+ Currently, the best way to contribute to this project is to star this project on GitHub, open a
160
+ [feature request](https://github.com/cssnr/actions-tools/discussions/categories/feature-requests)
161
+ or report any [issues](https://github.com/cssnr/actions-tools/issues) you find.
153
162
 
154
163
  Additionally, you can support other GitHub Actions I have published:
155
164
 
@@ -0,0 +1,7 @@
1
+ actions/__init__.py,sha256=ZibxMd7km3HsR9w3bSQClEPt2dayYRNUGTOCf3oRHu0,273
2
+ actions/core.py,sha256=5LOSu8VW7yfsY2YHiTyhY3ITbBYLPyWGkbHsexJzN78,4535
3
+ actions_tools-0.0.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
4
+ actions_tools-0.0.2.dist-info/METADATA,sha256=OT37n-XIFX3x4pns9GCxXMOfDe4ZIo2xb-GumWan33I,7197
5
+ actions_tools-0.0.2.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
6
+ actions_tools-0.0.2.dist-info/top_level.txt,sha256=5apM5x80QlJcGbACn1v3fkmIuL1-XQCKcItJre7w7Tw,8
7
+ actions_tools-0.0.2.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,,