From 764275046972bc3651b9be48b3a916f62606235c Mon Sep 17 00:00:00 2001 From: cavoq Date: Sun, 15 Sep 2024 03:05:13 +0200 Subject: [PATCH] CP-Pipeline --- .github/workflows/workflow.yml | 84 +++++++++++++++++++++++++++------- ntp_amplification.py | 4 +- setup.py | 2 +- version.py | 1 + 4 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 version.py diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7ceab67..a1f3c3a 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -6,6 +6,28 @@ on: - master jobs: + lint: + name: Lint Code + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.13.0rc2 + + - name: Install Dependencies + run: pip install -r requirements-dev.txt + + - name: Install Linter + run: pre-commit install + + - name: Lint Code + run: pre-commit run --all-files + test: name: Run Tests runs-on: ubuntu-latest @@ -17,22 +39,18 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.11 + python-version: 3.13.0rc2 - name: Install Dependencies - run: pip install -r requirements.txt - - - name: Install Test Dependencies - run: pip install -r requirements-dev.txt + run: | + pip install -r requirements.txt + pip install -r requirements-dev.txt - name: Run Tests - run: - | - python -m unittest ntp_amplification_test.py - continue-on-error: true + run: python -m unittest ntp_amplification_test.py - lint: - name: Lint Code + publish: + name: Check Version and Publish runs-on: ubuntu-latest steps: @@ -42,13 +60,45 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.11 + python-version: 3.13.0rc2 - name: Install Dependencies - run: pip install -r requirements-dev.txt + run: | + pip install -r requirements.txt + pip install -r requirements-dev.txt - - name: Install Linter - run: pre-commit install + - name: Get Current Version + id: current_version + run: | + version=$(python -c "exec(open('version.py').read()); print(__version__)") + echo "Current version: $version" + echo "::set-output name=VERSION::$version" - - name: Lint Code - run: pre-commit run --all-files + - name: Check if Version is Incremented + id: version_check + run: | + git fetch origin master + git checkout master + + cur_version=$(python -c "exec(open('ntp_amplification/version.py').read()); print(__version__)") + echo "Main branch version: $cur_version" + + if [ "$cur_version" = "$version" ]; then + echo "Version has not been incremented, exiting..." + exit 1 + else + echo "Version is incremented, proceeding..." + fi + + - name: Push Changes to Repository + if: success() + env: + TOKEN: ${{ secrets.PYPI_TOKEN }} + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git checkout -b release + + git add . + git commit -m "Release version ${{ steps.current_version.outputs.VERSION }}" + git push origin master diff --git a/ntp_amplification.py b/ntp_amplification.py index c688aab..0258020 100644 --- a/ntp_amplification.py +++ b/ntp_amplification.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from version import __version__ + try: from scapy.all import IP, UDP, Raw, send except ImportError: @@ -94,7 +96,7 @@ def is_ipv4(address: str): def print_banner(): banner_text = "NTP-AMPLIFIER" - description_text = "NTP-Amplification Attack Tool v1.7.0" + description_text = f"NTP-Amplification Attack Tool v{__version__}" usage_text = "USAGE: ntp_amplification [options] " options_text = """OPTIONS: -h, --help: Show this help message and exit diff --git a/setup.py b/setup.py index 389da24..77d5d96 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup __package__ = "ntp-amplification" -__version__ = "1.7.0" +from version import __version__ with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() diff --git a/version.py b/version.py new file mode 100644 index 0000000..3c1e9cb --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +__version__ = "1.7.1"