actions-tools 0.0.1__tar.gz → 0.0.3__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.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
 
@@ -1,3 +1,4 @@
1
+ [![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)
1
2
  [![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)
2
3
  [![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)
3
4
  [![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)
@@ -5,8 +6,8 @@
5
6
  [![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)
6
7
  [![PyPI](https://img.shields.io/pypi/v/actions-tools?logo=python&logoColor=white&label=PyPI)](https://pypi.org/project/actions-tools/)
7
8
  [![GitHub Release Version](https://img.shields.io/github/v/release/cssnr/actions-tools?logo=github)](https://github.com/cssnr/actions-tools/releases/latest)
8
- [![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/actions-tools?logo=htmx&logoColor=white)](https://github.com/cssnr/actions-tools)
9
9
  [![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)
10
+ [![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/actions-tools?logo=htmx&logoColor=white)](https://github.com/cssnr/actions-tools)
10
11
  [![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)
11
12
  [![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)
12
13
  [![GitHub Org Stars](https://img.shields.io/github/stars/cssnr?style=flat&logo=github&logoColor=white&label=org%20stars)](https://cssnr.github.io/)
@@ -16,22 +17,35 @@
16
17
 
17
18
  - [Install](#Install)
18
19
  - [Usage](#Usage)
19
- - [Development](#Development)
20
+ - [Support](#Support)
20
21
  - [Contributing](#Contributing)
21
22
 
22
- GitHub Actions Tools for Python.
23
-
24
23
  > [!WARNING]
25
24
  > This project is in development and is NOT stable!
26
25
 
26
+ GitHub Actions Tools for Python.
27
+
27
28
  ## Install
28
29
 
30
+ From PyPI: https://pypi.org/p/actions-tools
31
+
32
+ ```shell
33
+ python -m pip install actions-tools
34
+ ```
35
+
36
+ From source:
37
+
29
38
  ```shell
30
- #python -m pip install actions-tools
31
39
  git clone https://github.com/cssnr/actions-tools
32
40
  python -m pip install -e actions-tools
33
41
  ```
34
42
 
43
+ Uninstall:
44
+
45
+ ```shell
46
+ python -m pip uninstall actions-tools
47
+ ```
48
+
35
49
  ## Usage
36
50
 
37
51
  Functionality from @actions/toolkit
@@ -40,25 +54,43 @@ Functionality from @actions/toolkit
40
54
  from actions import core
41
55
 
42
56
  # Input
43
- name = core.get_input('name')
57
+ my_str = core.get_input('string')
58
+ my_bool = core.get_bool('boolean')
59
+ my_list = core.get_list('list')
44
60
 
45
61
  # Logging
62
+ core.info("info") # alias for print
46
63
  core.debug("debug")
47
- core.info("info") # print
64
+
65
+ # Annotations
66
+ core.notice("notice")
48
67
  core.warn("warn")
49
68
  core.error("error")
50
69
 
51
70
  # Blocks
52
- core.start_group("Test")
53
- core.info('This folded.')
71
+ core.start_group("Title")
72
+ core.info('This is folded.')
54
73
  core.end_group()
55
74
 
75
+ with core.group("Title") as p:
76
+ p('This is folded.')
77
+ core.info('Also folded.')
78
+
56
79
  # Summary
57
80
  core.summary('## Test Action')
58
81
 
59
- # Output
60
- core.set_env('VAR', 'value')
61
- core.set_output('name', 'god')
82
+ # Environment
83
+ core.set_env('NAME', 'value')
84
+
85
+ # State
86
+ name = core.set_state('name', 'value')
87
+ value = core.get_state('name')
88
+
89
+ # System Path
90
+ core.add_path('/dev/null')
91
+
92
+ # Outputs
93
+ core.set_output('name', 'cssnr')
62
94
 
63
95
  # Abort
64
96
  core.set_failed("Mayday!")
@@ -69,64 +101,40 @@ Functionality new in actions-tools
69
101
  ```python
70
102
  from actions import core
71
103
 
104
+ # Commands
105
+ core.command('warning', 'Warned!')
106
+
107
+ # Random
108
+ rand = core.get_random(32)
109
+
72
110
  # Indent
73
111
  core.start_indent(4)
74
- core.info('Indented') # only works with core.info
112
+ core.info('Indented') # only works with core.info
75
113
  core.end_indent()
76
114
  ```
77
115
 
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
- ```
95
-
96
- To Uninstall:
97
-
98
- ```shell
99
- python -m pip uninstall actions-tools
100
- ```
101
-
102
- ### Test
103
-
104
- First [Install](#Install), then run:
105
-
106
- ```shell
107
- coverage run -m pytest
108
- coverage report -m
109
- ```
110
-
111
- ### Building
116
+ # Support
112
117
 
113
- Build the project locally:
118
+ For general help or to request a feature, see:
114
119
 
115
- ```shell
116
- python -m pip install -U pip
117
- python -m pip install -Ur requirements.txt
118
- python -m pip build
119
- ```
120
+ - Q&A Discussion: https://github.com/cssnr/actions-tools/discussions/categories/q-a
121
+ - Request a Feature: https://github.com/cssnr/actions-tools/discussions/categories/feature-requests
122
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
120
123
 
121
- Install the built package:
124
+ If you are experiencing an issue/bug or getting unexpected results, you can:
122
125
 
123
- ```shell
124
- python -m pip install dist/actions_tools-0.0.1-py3-none-any.whl
125
- ```
126
+ - Report an Issue: https://github.com/cssnr/actions-tools/issues
127
+ - Provide General Feedback: [https://cssnr.github.io/feedback/](https://cssnr.github.io/feedback/?app=actions-tools)
128
+ - Chat with us on Discord: https://discord.gg/wXy6m2X8wY
126
129
 
127
130
  # Contributing
128
131
 
129
- Currently, the best way to contribute to this project is to star this project on GitHub.
132
+ > [!TIP]
133
+ > See the [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on testing and building.
134
+
135
+ Currently, the best way to contribute to this project is to star this project on GitHub, open a
136
+ [feature request](https://github.com/cssnr/actions-tools/discussions/categories/feature-requests)
137
+ or report any [issues](https://github.com/cssnr/actions-tools/issues) you find.
130
138
 
131
139
  Additionally, you can support other GitHub Actions I have published:
132
140
 
@@ -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,215 @@
1
+ import os
2
+ import random
3
+ import re
4
+ import string
5
+ from contextlib import contextmanager
6
+ from typing import List, Optional
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 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) -> str:
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
+ :return: str
145
+ """
146
+ value = os.getenv(f"INPUT_{name.upper()}", "")
147
+ value = _get_str_value(value, strip, low)
148
+ if req and not value:
149
+ raise ValueError(f"Error Parsing Required Input: {name} -> {value}")
150
+ return value
151
+
152
+
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:
189
+ if strip:
190
+ value = value.strip()
191
+ if low:
192
+ value = value.lower()
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,69 @@
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.group("Title") 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_bool("test")
55
+ with pytest.raises(ValueError):
56
+ core.get_input("asdf", req=True)
57
+ with pytest.raises(ValueError):
58
+ core.get_bool("asdf", req=True)
59
+ with pytest.raises(ValueError):
60
+ core.get_list("asdf", req=True)
61
+ assert isinstance(core.get_list("test", split="\n"), list)
62
+ assert len(core.get_list("test", split="\n")) == 1
63
+ assert not core.get_bool("false")
64
+
65
+
66
+ def test_getters():
67
+ assert core.get_state("STATE_test") == "value"
68
+ assert len(core.get_random(20)) == 20
69
+ 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