Skip to content

Commit

Permalink
improved solution
Browse files Browse the repository at this point in the history
  • Loading branch information
bubriks committed Apr 16, 2021
1 parent 26833e1 commit 8468d79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v2

- name: Check content
uses: bubriks/[email protected].1
uses: bubriks/[email protected].2
with:
expression: ^contributions/(.+)/(.+)/
strings: contributions/1/2/ contributions/1/2/
Expand All @@ -42,3 +42,4 @@ jobs:
| Output | Description |
|------------------------------------------------------|-----------------------------------------------|
| `groups` | The matching groups (based on regex) |
| `result` | Result of the matching |
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ inputs:
outputs:
groups:
description: "The matching groups (based on regex)"
result:
description: "Result of the matching"
runs:
using: "docker"
image: "Dockerfile"
22 changes: 13 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
import sys
import re


def main():
expression = os.environ["INPUT_EXPRESSION"]
strings = os.environ["INPUT_STRINGS"]

groups = None
match = None
for i in strings.split(" "):
m = re.match(expression, i)
if m:
match = re.match(expression, i)
if match:
if groups is None:
groups = m.groups
elif groups != m.groups:
groups = match.groups()
elif groups != match.groups():
sys.exit("Groups dont match" +
"\nGroup 1: " + str(groups()) +
"\nGroup 2: " + str(m.groups()))
"\nGroup 1: " + str(groups) +
"\nGroup 2: " + str(match.groups()))
else:
sys.exit("String doesnt match the pattern" +
"\nString: " + i)
print(f"::set-output name=groups::{groups}")

print(f"::set-output name=groups::{match.groups()}")
print(f"::set-output name=result::{match.group(0)}")


if __name__ == "__main__":
main()

0 comments on commit 8468d79

Please sign in to comment.