actions-tools 0.0.1__tar.gz → 0.0.2__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.

Potentially problematic release.


This version of actions-tools might be problematic. Click here for more details.

@@ -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
 
@@ -16,22 +16,35 @@
16
16
 
17
17
  - [Install](#Install)
18
18
  - [Usage](#Usage)
19
- - [Development](#Development)
19
+ - [Support](#Support)
20
20
  - [Contributing](#Contributing)
21
21
 
22
- GitHub Actions Tools for Python.
23
-
24
22
  > [!WARNING]
25
23
  > This project is in development and is NOT stable!
26
24
 
25
+ GitHub Actions Tools for Python.
26
+
27
27
  ## Install
28
28
 
29
+ From PyPI: https://pypi.org/p/actions-tools
30
+
31
+ ```shell
32
+ python -m pip install actions-tools
33
+ ```
34
+
35
+ From source:
36
+
29
37
  ```shell
30
- #python -m pip install actions-tools
31
38
  git clone https://github.com/cssnr/actions-tools
32
39
  python -m pip install -e actions-tools
33
40
  ```
34
41
 
42
+ Uninstall:
43
+
44
+ ```shell
45
+ python -m pip uninstall actions-tools
46
+ ```
47
+
35
48
  ## Usage
36
49
 
37
50
  Functionality from @actions/toolkit
@@ -40,25 +53,45 @@ Functionality from @actions/toolkit
40
53
  from actions import core
41
54
 
42
55
  # Input
43
- name = core.get_input('name')
56
+ myStr = core.get_input('myStr')
57
+ myLowerString = core.get_input('myLowerStr', low=1)
58
+ myRequiredStr = core.get_input('myRequiredStr', req=1)
59
+ myBoolean = core.get_input('myBoolean', boolean=1)
60
+ myList = core.get_input('myList', split="[,|\n]")
44
61
 
45
62
  # Logging
63
+ core.info("info") # alias for print
46
64
  core.debug("debug")
47
- core.info("info") # print
65
+
66
+ # Annotations
67
+ core.notice("notice")
48
68
  core.warn("warn")
49
69
  core.error("error")
50
70
 
51
71
  # Blocks
52
72
  core.start_group("Test")
53
- core.info('This folded.')
73
+ core.info('This is folded.')
54
74
  core.end_group()
55
75
 
76
+ with core.with_group("Test") as info:
77
+ info('This is folded.')
78
+ core.info('Also folded.')
79
+
56
80
  # Summary
57
81
  core.summary('## Test Action')
58
82
 
59
- # Output
60
- core.set_env('VAR', 'value')
61
- core.set_output('name', 'god')
83
+ # Environment
84
+ core.set_env('NAME', 'value')
85
+
86
+ # State
87
+ stateName = core.set_state('NAME', 'value')
88
+ stateValue = core.get_state('NAME')
89
+
90
+ # System Path
91
+ core.add_path('/dev/null')
92
+
93
+ # Outputs
94
+ core.set_output('name', 'cssnr')
62
95
 
63
96
  # Abort
64
97
  core.set_failed("Mayday!")
@@ -69,64 +102,40 @@ Functionality new in actions-tools
69
102
  ```python
70
103
  from actions import core
71
104
 
105
+ # Commands
106
+ core.command('warning', 'Warned!')
107
+
108
+ # Random
109
+ myRandom = core.get_random(32)
110
+
72
111
  # Indent
73
112
  core.start_indent(4)
74
- core.info('Indented') # only works with core.info
113
+ core.info('Indented') # only works with core.info
75
114
  core.end_indent()
76
115
  ```
77
116
 
78
- # Development
79
-
80
- ### Install
81
-
82
- Install the package from source:
83
-
84
- ```shell
85
- python -m pip install -U pip
86
- python -m pip install -Ur requirements.txt
87
- python -m pip install -e .
88
- ```
89
-
90
- Prettier is used to format yaml, json and md.
91
-
92
- ```shell
93
- npm install -g prettier
94
- ```
117
+ # Support
95
118
 
96
- To Uninstall:
119
+ For general help or to request a feature, see:
97
120
 
98
- ```shell
99
- python -m pip uninstall actions-tools
100
- ```
121
+ - Q&A Discussion: https://github.com/cssnr/actions-tools/discussions/categories/q-a
122
+ - Request a Feature: https://github.com/cssnr/actions-tools/discussions/categories/feature-requests
123
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
101
124
 
102
- ### Test
125
+ If you are experiencing an issue/bug or getting unexpected results, you can:
103
126
 
104
- First [Install](#Install), then run:
105
-
106
- ```shell
107
- coverage run -m pytest
108
- coverage report -m
109
- ```
110
-
111
- ### Building
112
-
113
- Build the project locally:
114
-
115
- ```shell
116
- python -m pip install -U pip
117
- python -m pip install -Ur requirements.txt
118
- python -m pip build
119
- ```
120
-
121
- Install the built package:
122
-
123
- ```shell
124
- python -m pip install dist/actions_tools-0.0.1-py3-none-any.whl
125
- ```
127
+ - Report an Issue: https://github.com/cssnr/actions-tools/issues
128
+ - Provide General Feedback: [https://cssnr.github.io/feedback/](https://cssnr.github.io/feedback/?app=actions-tools)
129
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
126
130
 
127
131
  # Contributing
128
132
 
129
- Currently, the best way to contribute to this project is to star this project on GitHub.
133
+ > [!TIP]
134
+ > See the [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on testing and building.
135
+
136
+ Currently, the best way to contribute to this project is to star this project on GitHub, open a
137
+ [feature request](https://github.com/cssnr/actions-tools/discussions/categories/feature-requests)
138
+ or report any [issues](https://github.com/cssnr/actions-tools/issues) you find.
130
139
 
131
140
  Additionally, you can support other GitHub Actions I have published:
132
141
 
@@ -13,7 +13,7 @@ classifiers = [
13
13
  "Programming Language :: Python :: 3 :: Only",
14
14
  "Programming Language :: Python :: 3.10",
15
15
  "Programming Language :: Python :: 3.11",
16
- "Programming Language :: Python :: 3.13",
16
+ "Programming Language :: Python :: 3.12",
17
17
  "Programming Language :: Python :: 3.13",
18
18
  "Operating System :: OS Independent",
19
19
  "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
@@ -29,23 +29,27 @@ Issues = "https://github.com/cssnr/actions-tools/issues"
29
29
 
30
30
  # Setup Tools
31
31
 
32
+ [tool.setuptools.dynamic]
33
+ version = { attr = "actions.__version__" }
34
+
35
+ # Build System
36
+
32
37
  [build-system]
33
38
  requires = ["setuptools>=61.0"]
34
39
  build-backend = "setuptools.build_meta"
35
40
 
36
- [tool.setuptools.dynamic]
37
- version = { attr = "actions.__version__" }
38
-
39
41
  # Black
40
42
 
41
43
  [tool.black]
42
44
  line-length = 119
45
+ extend-exclude = '(\.github)'
43
46
 
44
47
  # Ruff
45
48
 
46
49
  [tool.ruff]
47
50
  line-length = 119
48
51
  target-version = "py313"
52
+ exclude = [".github"]
49
53
 
50
54
  [tool.ruff.lint]
51
55
  select = ["E4", "E7", "E9", "F", "B", "Q"]
@@ -53,7 +57,7 @@ select = ["E4", "E7", "E9", "F", "B", "Q"]
53
57
  # Coverage
54
58
 
55
59
  [tool.coverage.run]
56
- omit = ["*/*.egg-info/*"]
60
+ omit = ["*.egg-info/*", ".github/*"]
57
61
  source = ["src"]
58
62
 
59
63
  # Isort
@@ -62,3 +66,4 @@ source = ["src"]
62
66
  profile = "black"
63
67
  lines_after_imports = 2
64
68
  src_paths = ["src", "test"]
69
+ skip = [".github"]
@@ -0,0 +1,196 @@
1
+ import os
2
+ import random
3
+ import re
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
10
+
11
+
12
+ true = ["y", "yes", "true", "on"]
13
+ false = ["n", "no", "false", "off"]
14
+
15
+ _indent = 0
16
+ _endtoken = ""
17
+
18
+
19
+ # Core
20
+
21
+
22
+ def debug(message: str, *args, **kwargs):
23
+ print(f"::debug::{message}", *args, **kwargs)
24
+
25
+
26
+ def info(message: str, *args, **kwargs):
27
+ print(" " * _indent + message, *args, **kwargs)
28
+
29
+
30
+ def notice(message: str, *args, **kwargs):
31
+ print(f"::notice::{message}", *args, **kwargs)
32
+
33
+
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"))
44
+
45
+
46
+ def set_failed(message: str):
47
+ error(message)
48
+ raise SystemExit
49
+
50
+
51
+ def mask(message: str):
52
+ print(f"::add-mask::{message}")
53
+
54
+
55
+ def start_group(title: str):
56
+ print(f"::group::{title}")
57
+
58
+
59
+ def end_group():
60
+ print("::endgroup::")
61
+
62
+
63
+ @contextmanager
64
+ def with_group(title: str):
65
+ print(f"::group::{title}")
66
+ try:
67
+ yield info
68
+ finally:
69
+ print("::endgroup::")
70
+
71
+
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}::")
86
+
87
+
88
+ def set_output(output: str, value: str):
89
+ with open(os.environ["GITHUB_OUTPUT"], "a") as f:
90
+ # noinspection PyTypeChecker
91
+ print(f"{output}={value}", file=f)
92
+
93
+
94
+ def set_env(name: str, value: str):
95
+ with open(os.environ["GITHUB_ENV"], "a") as 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}", "")
119
+
120
+
121
+ def summary(text: str, nlc=1):
122
+ """
123
+ TODO: Make this its own module
124
+ :param text:str: Raw Text
125
+ :param nlc:int: New Line Count
126
+ :return:
127
+ """
128
+ new_lines = os.linesep * nlc
129
+ with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
130
+ # noinspection PyTypeChecker
131
+ print(f"{text}{new_lines}", file=f)
132
+
133
+
134
+ # Inputs
135
+
136
+
137
+ def get_input(name: str, req=False, low=False, strip=True, boolean=False, split="") -> Union[str, bool, list]:
138
+ """
139
+ Get Input by Name
140
+ :param name: str: Input Name
141
+ :param req: bool: If Required
142
+ :param low: bool: To Lower
143
+ :param strip: bool: To Strip
144
+ :param boolean: bool: If Boolean
145
+ :param split: str: To Split
146
+ :return: Union[str, bool, list]
147
+ """
148
+ value = os.getenv(f"INPUT_{name.upper()}", "")
149
+ if boolean:
150
+ value = value.strip().lower()
151
+ if req and value not in true + false:
152
+ raise ValueError(f"Error Validating a Required Boolean Input: {name}")
153
+ if value in ["y", "yes", "true", "on"]:
154
+ return True
155
+ return False
156
+
157
+ if split:
158
+ result = []
159
+ for x in re.split(split, value):
160
+ result.append(_get_str_value(x, low, strip))
161
+ return result
162
+
163
+ value = _get_str_value(value, low, strip)
164
+ if req and not value:
165
+ raise ValueError(f"Error Parsing a Required Input: {name}")
166
+ return value
167
+
168
+
169
+ def _get_str_value(value, low=False, strip=True):
170
+ if strip:
171
+ value = value.strip()
172
+ if low:
173
+ value = value.lower()
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,67 @@
1
+ import os
2
+
3
+ import pytest
4
+
5
+ from actions import core
6
+
7
+
8
+ os.environ["INPUT_TEST"] = " TRUE "
9
+ os.environ["INPUT_FALSE"] = " untrue "
10
+ os.environ["GITHUB_OUTPUT"] = os.environ.get("GITHUB_OUTPUT") or "output.txt"
11
+ os.environ["GITHUB_ENV"] = os.environ.get("GITHUB_ENV") or "output.txt"
12
+ os.environ["GITHUB_PATH"] = os.environ.get("GITHUB_PATH") or "output.txt"
13
+ os.environ["GITHUB_STATE"] = os.environ.get("GITHUB_STATE") or "output.txt"
14
+ os.environ["GITHUB_STEP_SUMMARY"] = os.environ.get("GITHUB_STEP_SUMMARY") or "output.txt"
15
+
16
+
17
+ def test_print():
18
+ core.debug("debug")
19
+ core.info("info")
20
+ core.notice("notice")
21
+ core.warn("warn")
22
+ with pytest.raises(SystemExit):
23
+ core.set_failed("test")
24
+ core.mask("test")
25
+ core.start_group("test")
26
+ core.end_group()
27
+ core.start_indent()
28
+ core.info("indent")
29
+ core.end_indent()
30
+ core.info("dedent")
31
+ core.stop_commands()
32
+ core.info("::warning::Just kidding")
33
+ core.start_commands()
34
+ with core.with_group("With Group") as p:
35
+ core.info("with group")
36
+ p("core.info")
37
+ core.info("no group")
38
+ core.command("debug", "test")
39
+
40
+
41
+ def test_outputs():
42
+ core.set_output("test", "value")
43
+ core.set_env("test", "value")
44
+ core.summary("test")
45
+ core.add_path("/dev/null")
46
+ core.set_state("STATE_test", "value")
47
+ os.environ["STATE_test"] = "value"
48
+
49
+
50
+ def test_inputs():
51
+ assert core.get_input("test") == os.environ["INPUT_TEST"].strip()
52
+ assert core.get_input("test", low=True) == os.environ["INPUT_TEST"].strip().lower()
53
+ assert core.get_input("test", strip=False) == os.environ["INPUT_TEST"]
54
+ assert core.get_input("test", boolean=True)
55
+ with pytest.raises(ValueError):
56
+ core.get_input("asdf", boolean=True, req=True)
57
+ with pytest.raises(ValueError):
58
+ core.get_input("asdf", req=True)
59
+ assert isinstance(core.get_input("test", split="\n"), list)
60
+ assert len(core.get_input("test", split="\n")) == 1
61
+ assert not core.get_input("false", boolean=True)
62
+
63
+
64
+ def test_getters():
65
+ assert core.get_state("STATE_test") == "value"
66
+ assert len(core.get_random(20)) == 20
67
+ assert not core.is_debug()
@@ -1,122 +0,0 @@
1
- import os
2
- import re
3
- from typing import Union
4
-
5
-
6
- true = ["y", "yes", "true", "on"]
7
- false = ["n", "no", "false", "off"]
8
-
9
- _indent = 0
10
-
11
-
12
- def debug(message: str):
13
- print(f"::debug::{message}")
14
-
15
-
16
- def info(message: str, **kwargs):
17
- print(" " * _indent + message, **kwargs)
18
-
19
-
20
- def notice(message: str):
21
- print(f"::notice::{message}")
22
-
23
-
24
- def warn(message: str):
25
- print(f"::warning::{message}")
26
-
27
-
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
-
35
-
36
- def set_failed(message: str):
37
- error(message)
38
- raise SystemExit
39
-
40
-
41
- def mask(message: str):
42
- print(f"::add-mask::{message}")
43
-
44
-
45
- def start_group(title: str):
46
- print(f"::group::{title}")
47
-
48
-
49
- def end_group():
50
- print("::endgroup::")
51
-
52
-
53
- def start_indent(spaces: int):
54
- global _indent
55
- _indent = spaces
56
-
57
-
58
- def end_indent():
59
- global _indent
60
- _indent = 0
61
-
62
-
63
- def set_output(output: str, value: str):
64
- with open(os.environ["GITHUB_OUTPUT"], "a") as f:
65
- print(f"{output}={value}", file=f)
66
-
67
-
68
- def set_env(var: str, value: str):
69
- with open(os.environ["GITHUB_ENV"], "a") as f:
70
- print(f"{var}={value}", file=f)
71
-
72
-
73
- def summary(text: str, nlc=1):
74
- """
75
- TODO: Make this its own module
76
- :param text:str: Raw Text
77
- :param nlc:int: New Line Count
78
- :return:
79
- """
80
- new_lines = "\n" * nlc
81
- with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
82
- print(f"{text}{new_lines}", file=f)
83
-
84
-
85
- def get_input(name: str, req=False, low=False, strip=True, boolean=False, split="") -> Union[str, bool, list]:
86
- """
87
- Get Input by Name
88
- :param name: str: Input Name
89
- :param req: bool: If Required
90
- :param low: bool: To Lower
91
- :param strip: bool: To Strip
92
- :param boolean: bool: If Boolean
93
- :param split: str: To Split
94
- :return: Union[str, bool, list]
95
- """
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)
112
- if req and not value:
113
- raise ValueError(f"Error Parsing a Required Input: {name}")
114
- return value
115
-
116
-
117
- def _get_str_value(value, low=False, strip=True):
118
- if strip:
119
- value = value.strip()
120
- if low:
121
- value = value.lower()
122
- return value
@@ -1,45 +0,0 @@
1
- import os
2
-
3
- import pytest
4
-
5
- from actions import core
6
-
7
-
8
- os.environ["INPUT_TEST"] = " TRUE "
9
-
10
-
11
- def test_print():
12
- core.debug("debug")
13
- core.info("info")
14
- core.notice("notice")
15
- core.warn("warn")
16
- with pytest.raises(SystemExit):
17
- core.set_failed("test")
18
- core.mask("test")
19
- core.start_group("test")
20
- core.end_group()
21
- core.start_indent(5)
22
- core.info("indent")
23
- core.end_indent()
24
- core.info("dedent")
25
-
26
-
27
- def test_outputs():
28
- if not os.environ.get("GITHUB_OUTPUT"):
29
- os.environ["GITHUB_OUTPUT"] = "output.txt"
30
- core.set_output("test", "value")
31
- if not os.environ.get("GITHUB_ENV"):
32
- os.environ["GITHUB_ENV"] = "output.txt"
33
- core.set_env("test", "value")
34
- if not os.environ.get("GITHUB_STEP_SUMMARY"):
35
- os.environ["GITHUB_STEP_SUMMARY"] = "output.txt"
36
- core.summary("test")
37
-
38
-
39
- def test_inputs():
40
- assert core.get_input("test") == os.environ["INPUT_TEST"].strip()
41
- assert core.get_input("test", low=True) == os.environ["INPUT_TEST"].strip().lower()
42
- assert core.get_input("test", strip=False) == os.environ["INPUT_TEST"]
43
- assert core.get_input("test", boolean=True)
44
- assert isinstance(core.get_input("test", split="\n"), list)
45
- assert len(core.get_input("test", split="\n")) == 1
File without changes
File without changes