From 36d18a630047408fde4a3875fab4ee97f3748768 Mon Sep 17 00:00:00 2001 From: Cheng Chih Yuan <64208218+kevinjone25@users.noreply.github.com> Date: Sun, 28 Apr 2024 01:34:03 +0800 Subject: [PATCH] Fix #51 * fix: correcting regex for formatting string #51 * ci: add cron.yml --------- Co-authored-by: Xyphuz <38447974+wst24365888@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++++ .github/workflows/cron.yml | 20 ++++++++++++++++++++ compose_viz/parser.py | 2 +- naming.py | 20 ++++++++++++++++++++ tests/test_parse_file.py | 4 ++++ tests/ymls/ports/docker-compose.yml | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cron.yml create mode 100644 naming.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d3b3df..2558da5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml new file mode 100644 index 0000000..c3e1aab --- /dev/null +++ b/.github/workflows/cron.yml @@ -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 diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 0539f0f..82fab0c 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -107,7 +107,7 @@ class Parser: container_port = str(int(port_data)) host_port = f"0.0.0.0:{container_port}" elif type(port_data) is str: - regex = r"((?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)|:)?((?P\d+(\-\d+)?):)?((?P\d+(\-\d+)?))?(/(?P\w+))?" # noqa: E501 + regex = r"((?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:|(\$\{([^}]+)\}):)|:|)?((?P\d+(\-\d+)?):)?((?P\d+(\-\d+)?))?(/(?P\w+))?" # noqa: E501 match = re.match(regex, port_data) if match: diff --git a/naming.py b/naming.py new file mode 100644 index 0000000..f1ecc72 --- /dev/null +++ b/naming.py @@ -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!") diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index 255d750..2526330 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -176,6 +176,10 @@ from compose_viz.parser import Parser 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", diff --git a/tests/ymls/ports/docker-compose.yml b/tests/ymls/ports/docker-compose.yml index 725e10a..72b8599 100644 --- a/tests/ymls/ports/docker-compose.yml +++ b/tests/ymls/ports/docker-compose.yml @@ -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