Skip to content

Commit

Permalink
Fix #51
Browse files Browse the repository at this point in the history
* fix: correcting regex for formatting string #51 
* ci: add cron.yml

---------

Co-authored-by: Xyphuz <38447974+wst24365888@users.noreply.github.com>
  • Loading branch information
kevinjone25 and wst24365888 committed Apr 27, 2024
1 parent 0ffcc16 commit 36d18a6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
with:
python-version: '3.10.4'

- name: Changing naming convention
run: |
python3 naming.py
- name: Setup Poetry
uses: abatilo/actions-poetry@v3
with:
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CRON

on:
schedule:
- cron: '0 0 * * *'

jobs:
#renew git submodule
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: update compose-spec submodule
run: |
git submodule update --init --recursive
git submodule update --remote --recursive
- name: Commit changes
run: |
git commit -am "Update submodules" || echo "No changes to commit"
git push
2 changes: 1 addition & 1 deletion compose_viz/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def parse(self, file_path: str, root_service: Optional[str] = None) -> Compose:
container_port = str(int(port_data))
host_port = f"0.0.0.0:{container_port}"
elif type(port_data) is str:
regex = r"((?P<host_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)|:)?((?P<host_port>\d+(\-\d+)?):)?((?P<container_port>\d+(\-\d+)?))?(/(?P<protocol>\w+))?" # noqa: E501
regex = r"((?P<host_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:|(\$\{([^}]+)\}):)|:|)?((?P<host_port>\d+(\-\d+)?):)?((?P<container_port>\d+(\-\d+)?))?(/(?P<protocol>\w+))?" # noqa: E501
match = re.match(regex, port_data)

if match:
Expand Down
20 changes: 20 additions & 0 deletions naming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def revise_naming_convention():
name_mapping = {
"EnvFile1": "EnvFilePath",
"Volume1": "AdditionalVolumeOption",
"External": "ExternalVolumeNetwork",
"External1": "ExternalConfig",
}

with open("./compose_viz/spec/compose_spec.py", "r") as spec_file:
spec_content = spec_file.read()

for origin_name, new_name in name_mapping.items():
spec_content.replace(origin_name, new_name)

return


if __name__ == "__main__":
revise_naming_convention()
print("Revised naming convention successfully!")
4 changes: 4 additions & 0 deletions tests/test_parse_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
host_port="0.0.0.0:7777",
container_port="7777",
),
Port(
host_port="${BIND_IP:-127.0.0.1}:8080",
container_port="8080",
),
Port(
host_port="127.0.0.1:8080",
container_port="80",
Expand Down
1 change: 1 addition & 0 deletions tests/ymls/ports/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- "127.0.0.1:5000-5010:5000-5010"
- "6060:6060/udp"
- ":7777"
- "${BIND_IP:-127.0.0.1}:8080:8080"
- target: 80
host_ip: 127.0.0.1
published: 8080
Expand Down

0 comments on commit 36d18a6

Please sign in to comment.