Skip to content

Commit 8468d79

Browse files
committed
improved solution
1 parent 26833e1 commit 8468d79

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v2
1919

2020
- name: Check content
21-
uses: bubriks/[email protected].1
21+
uses: bubriks/[email protected].2
2222
with:
2323
expression: ^contributions/(.+)/(.+)/
2424
strings: contributions/1/2/ contributions/1/2/
@@ -42,3 +42,4 @@ jobs:
4242
| Output | Description |
4343
|------------------------------------------------------|-----------------------------------------------|
4444
| `groups` | The matching groups (based on regex) |
45+
| `result` | Result of the matching |

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ inputs:
1111
outputs:
1212
groups:
1313
description: "The matching groups (based on regex)"
14+
result:
15+
description: "Result of the matching"
1416
runs:
1517
using: "docker"
1618
image: "Dockerfile"

main.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22
import sys
33
import re
44

5+
56
def main():
67
expression = os.environ["INPUT_EXPRESSION"]
78
strings = os.environ["INPUT_STRINGS"]
8-
9+
910
groups = None
11+
match = None
1012
for i in strings.split(" "):
11-
m = re.match(expression, i)
12-
if m:
13+
match = re.match(expression, i)
14+
if match:
1315
if groups is None:
14-
groups = m.groups
15-
elif groups != m.groups:
16+
groups = match.groups()
17+
elif groups != match.groups():
1618
sys.exit("Groups dont match" +
17-
"\nGroup 1: " + str(groups()) +
18-
"\nGroup 2: " + str(m.groups()))
19+
"\nGroup 1: " + str(groups) +
20+
"\nGroup 2: " + str(match.groups()))
1921
else:
2022
sys.exit("String doesnt match the pattern" +
2123
"\nString: " + i)
22-
print(f"::set-output name=groups::{groups}")
23-
24+
print(f"::set-output name=groups::{match.groups()}")
25+
print(f"::set-output name=result::{match.group(0)}")
26+
27+
2428
if __name__ == "__main__":
2529
main()

0 commit comments

Comments
 (0)