Skip to content

Commit 26833e1

Browse files
committed
Init
1 parent 39b5f2a commit 26833e1

File tree

5 files changed

+52
-98
lines changed

5 files changed

+52
-98
lines changed

.github/workflows/integration.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ FROM python:3-slim AS builder
22
ADD . /app
33
WORKDIR /app
44

5-
# We are installing a dependency here directly into our app source dir
6-
RUN pip install --target=/app requests
7-
85
# A distroless container image with Python and some basics like SSL certificates
96
# https://github.com/GoogleContainerTools/distroless
107
FROM gcr.io/distroless/python3-debian10
118
COPY --from=builder /app /app
129
WORKDIR /app
1310
ENV PYTHONPATH /app
14-
CMD ["/app/main.py"]
11+
CMD ["/app/main.py"]

README.md

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
# Python Container Action Template
1+
# File content checker
22

3-
[![Action Template](https://img.shields.io/badge/Action%20Template-Python%20Container%20Action-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/jacobtomlinson/python-container-action)
4-
[![Actions Status](https://github.com/jacobtomlinson/python-container-action/workflows/Lint/badge.svg)](https://github.com/jacobtomlinson/python-container-action/actions)
5-
[![Actions Status](https://github.com/jacobtomlinson/python-container-action/workflows/Integration%20Test/badge.svg)](https://github.com/jacobtomlinson/python-container-action/actions)
6-
7-
This is a template for creating GitHub actions and contains a small Python application which will be built into a minimal [Container Action](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-a-docker-container-action). Our final container from this template is ~50MB, yours may be a little bigger once you add some code. If you want something smaller check out my [go-container-action template](https://github.com/jacobtomlinson/go-container-action/actions).
8-
9-
In `main.py` you will find a small example of accessing Action inputs and returning Action outputs. For more information on communicating with the workflow see the [development tools for GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions).
10-
11-
> 🏁 To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/).
3+
This action will validate that the provided string are following regex expression and matching on groups.
124

135
## Usage
146

15-
Describe how to use your action here.
7+
The verification is done using regex and in case of match the group tuple is returned.
168

17-
### Example workflow
9+
### Example Usage
1810

1911
```yaml
2012
name: My Workflow
@@ -23,63 +15,30 @@ jobs:
2315
build:
2416
runs-on: ubuntu-latest
2517
steps:
26-
- uses: actions/checkout@master
27-
- name: Run action
18+
- uses: actions/checkout@v2
2819

29-
# Put your action repo here
30-
uses: me/myaction@master
31-
32-
# Put an example of your mandatory inputs here
20+
- name: Check content
21+
uses: bubriks/[email protected]
3322
with:
34-
myInput: world
23+
expression: ^contributions/(.+)/(.+)/
24+
strings: contributions/1/2/ contributions/1/2/
25+
```
26+
27+
#### Result from example
28+
29+
```
30+
('1', '2')
3531
```
3632

3733
### Inputs
3834

3935
| Input | Description |
4036
|------------------------------------------------------|-----------------------------------------------|
41-
| `myInput` | An example mandatory input |
42-
| `anotherInput` _(optional)_ | An example optional input |
37+
| `expression` | Regex string for string verification |
38+
| `strings` | List of strings to verify |
4339

4440
### Outputs
4541

4642
| Output | Description |
4743
|------------------------------------------------------|-----------------------------------------------|
48-
| `myOutput` | An example output (returns 'Hello world') |
49-
50-
## Examples
51-
52-
> NOTE: People ❤️ cut and paste examples. Be generous with them!
53-
54-
### Using the optional input
55-
56-
This is how to use the optional input.
57-
58-
```yaml
59-
with:
60-
myInput: world
61-
anotherInput: optional
62-
```
63-
64-
### Using outputs
65-
66-
Show people how to use your outputs in another action.
67-
68-
```yaml
69-
steps:
70-
- uses: actions/checkout@master
71-
- name: Run action
72-
id: myaction
73-
74-
# Put your action name here
75-
uses: me/myaction@master
76-
77-
# Put an example of your mandatory arguments here
78-
with:
79-
myInput: world
80-
81-
# Put an example of using your outputs here
82-
- name: Check outputs
83-
run: |
84-
echo "Outputs - ${{ steps.myaction.outputs.myOutput }}"
85-
```
44+
| `groups` | The matching groups (based on regex) |

action.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
name: "Python Container Action Template"
2-
description: "Get started with Python Container actions"
3-
author: "Jacob Tomlinson"
1+
name: "String verifier"
2+
description: "Verify that strings follow the regex pattern and match groups"
3+
author: "Ralfs Zangis"
44
inputs:
5-
myInput:
6-
description: "Input to use"
7-
default: "world"
5+
expression:
6+
description: "Regex string for string verification"
7+
required: true
8+
strings:
9+
description: "List of strings to verify"
10+
required: true
811
outputs:
9-
myOutput:
10-
description: "Output from the action"
12+
groups:
13+
description: "The matching groups (based on regex)"
1114
runs:
1215
using: "docker"
13-
image: "Dockerfile"
16+
image: "Dockerfile"

main.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import os
2-
import requests # noqa We are just importing this to prove the dependency installed correctly
3-
2+
import sys
3+
import re
44

55
def main():
6-
my_input = os.environ["INPUT_MYINPUT"]
7-
8-
my_output = f"Hello {my_input}"
9-
10-
print(f"::set-output name=myOutput::{my_output}")
11-
12-
6+
expression = os.environ["INPUT_EXPRESSION"]
7+
strings = os.environ["INPUT_STRINGS"]
8+
9+
groups = None
10+
for i in strings.split(" "):
11+
m = re.match(expression, i)
12+
if m:
13+
if groups is None:
14+
groups = m.groups
15+
elif groups != m.groups:
16+
sys.exit("Groups dont match" +
17+
"\nGroup 1: " + str(groups()) +
18+
"\nGroup 2: " + str(m.groups()))
19+
else:
20+
sys.exit("String doesnt match the pattern" +
21+
"\nString: " + i)
22+
print(f"::set-output name=groups::{groups}")
23+
1324
if __name__ == "__main__":
14-
main()
25+
main()

0 commit comments

Comments
 (0)