diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f37b650..f1675cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,11 @@ name: Test -on: push +on: + push: + branches: + - '**' + tags: + - 'v*' jobs: test: @@ -8,27 +13,56 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v6 - name: Extract branch name shell: bash - run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/heads/} | tr / -)" + run: echo "tag=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_OUTPUT id: extract_branch - name: "Pull core image" shell: bash - run: echo -n "##[set-output name=tag;]" && docker pull tomlegkov/marine-core:${{ steps.extract_branch.outputs.tag }} > /dev/null && echo "${{ steps.extract_branch.outputs.tag }}" || echo marine + run: | + if docker pull tomlegkov/marine-core:${{ steps.extract_branch.outputs.tag }} > /dev/null 2>&1; then + echo "tag=${{ steps.extract_branch.outputs.tag }}" >> $GITHUB_OUTPUT + else + echo "tag=marine" >> $GITHUB_OUTPUT + fi id: detect_tag + - name: Extract version from tag + if: startsWith(github.ref, 'refs/tags/v') + run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT + id: extract_version + - name: "Build marine-python docker image" - run: docker build --build-arg MARINE_CORE_TAG=${{ steps.detect_tag.outputs.tag }} --pull -t marine-python . + run: docker build --build-arg MARINE_CORE_TAG=${{ steps.detect_tag.outputs.tag }} --build-arg MARINE_VERSION=${{ steps.extract_version.outputs.version || '0.0.0' }} --pull -t marine-python . - name: "Extract wheel from docker image" run: docker run -i --rm -v $(pwd)/dist:/io marine-python sh -c "cp /dist/marine*.whl /io/" - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v6 with: + name: wheel path: dist/*.whl - name: "Run marine-python tests" run: docker run -i --rm marine-python + + release: + needs: test + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/download-artifact@v6 + with: + name: wheel + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: '*.whl' + generate_release_notes: true diff --git a/Dockerfile b/Dockerfile index 57fd1b9..242a281 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,15 @@ COPY README.md ./ COPY LICENSE ./ COPY marine ./marine +ARG MARINE_VERSION=0.0.0 ENV PY="/opt/python/cp38-cp38/bin/python" -RUN mkdir -p marine/.ws/data && \ +RUN echo "__version__ = \"${MARINE_VERSION}\"" > marine/_version.py && \ + mkdir -p marine/.ws/data && \ rsync -L --exclude idl2wrs --exclude 'lib*.so*' --exclude 'plugins*' --exclude 'marine_*' --exclude tshark --exclude '*.html' --exclude 'lib*.a' /build/run/* marine/.ws/data/ && \ mkdir marine/.ws/libs && \ - rsync -L /build/run/libmarine.so /build/run/lib*so.0 marine/.ws/libs/ && \ + rsync -L /build/run/libmarine.so /build/run/lib*so.* marine/.ws/libs/ && \ + $PY -m pip install --no-cache-dir setuptools wheel && \ $PY setup.py bdist_wheel --dist-dir /tmp WORKDIR /dist @@ -25,7 +28,7 @@ RUN /scripts/expose_auditwheel.sh && \ $PY /scripts/modify_auditwheel_policy.py && \ /scripts/patch_auditwheel_recursive_dependency_bug.sh -RUN auditwheel repair --plat manylinux2014_x86_64 -w /dist /tmp/marine*.whl +RUN auditwheel repair --lib-sdir /.ws/libs/ --plat manylinux2014_x86_64 -w /dist /tmp/marine*.whl @@ -33,7 +36,10 @@ FROM centos/python-38-centos7 USER root -RUN yum install -y libpcap && \ +RUN sed -i 's/mirror\.centos\.org/vault.centos.org/g' /etc/yum.repos.d/CentOS-*.repo && \ + sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/CentOS-*.repo && \ + sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/CentOS-*.repo && \ + yum install -y libpcap && \ yum clean all && \ rm -rf /var/yum/cache diff --git a/marine/__init__.py b/marine/__init__.py index 869d1ff..aa5f2a1 100644 --- a/marine/__init__.py +++ b/marine/__init__.py @@ -13,3 +13,4 @@ from .exceptions import * from .marine import Marine from . import encap_consts +from ._version import __version__ diff --git a/marine/_version.py b/marine/_version.py new file mode 100644 index 0000000..6c8e6b9 --- /dev/null +++ b/marine/_version.py @@ -0,0 +1 @@ +__version__ = "0.0.0" diff --git a/marine/marine.py b/marine/marine.py index a945cca..2f62409 100644 --- a/marine/marine.py +++ b/marine/marine.py @@ -147,6 +147,7 @@ def __init__(self, epan_auto_reset_count: Optional[int] = None): self._marine.marine_free.argtypes = [MARINE_RESULT_POINTER] self._marine.marine_dissect_all_packet_fields.restype = MARINE_PACKET_POINTER self._marine.marine_packet_free.argtypes = [MARINE_PACKET_POINTER] + self._marine.get_wireshark_version.restype = c_char_p return_code = self._marine.init_marine() if return_code < 0: @@ -241,9 +242,11 @@ def filter_and_parse( bpf, display_filter, tuple(encoded_fields) if fields is not None else None, - tuple(field_template_indices) - if field_template_indices is not None - else None, + ( + tuple(field_template_indices) + if field_template_indices is not None + else None + ), encapsulation_type, ) if filter_key in self._filters_cache: @@ -469,3 +472,7 @@ def _detect_encap(self, fields: Optional[List[str]]) -> int: def report_fields(self) -> None: self._marine.marine_report_fields() + + def get_wireshark_version(self) -> str: + version = self._marine.get_wireshark_version() + return version.decode("utf-8") diff --git a/marine/simple_marine.py b/marine/simple_marine.py index 2a4b4b9..8d11cc3 100644 --- a/marine/simple_marine.py +++ b/marine/simple_marine.py @@ -141,3 +141,10 @@ def report_fields() -> None: Dumps to stdout all of marine, similiarly to `tshark -G` """ return get_marine().report_fields() + + +def get_wireshark_version() -> str: + """ + Gets the version of wireshark used by marine. + """ + return get_marine().get_wireshark_version() diff --git a/setup.py b/setup.py index 8f776aa..93ed8ae 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,10 @@ from setuptools import setup +from marine._version import __version__ + setup( name="marine", - version="3.1.2", + version=__version__, description="Python client for Marine", packages=["marine"], include_package_data=True, diff --git a/tests/marine/benchmark/main.py b/tests/marine/benchmark/main.py index c9f2ca2..febc0bd 100644 --- a/tests/marine/benchmark/main.py +++ b/tests/marine/benchmark/main.py @@ -26,6 +26,7 @@ TODO: simulate PL in conversations TODO: add support for real TCP conversations with ack and seq management """ + import argparse import os import time diff --git a/tests/marine/test_marine.py b/tests/marine/test_marine.py index a81d47e..03809b4 100644 --- a/tests/marine/test_marine.py +++ b/tests/marine/test_marine.py @@ -1,6 +1,7 @@ """ Note: in order to run the tests, you must put libmarine.so next to the marine_fixtures.py file """ + import pytest from typing import List, Union, Optional, Dict from marine.marine import Marine, MarineFieldsValidationResult @@ -1095,3 +1096,8 @@ def test_value_error_for_unknown_pref_name(marine_instance): def test_type_error_for_invalid_pref_type(marine_instance): with pytest.raises(TypeError): marine_instance.prefs.set_str("amqp", "tls.port", "1234") + + +def test_get_wireshark_version(marine_instance: Marine): + version = marine_instance.get_wireshark_version() + assert isinstance(version, str)