nomy-data-models 0.2.4

Data model definitions for Nomy wallet analysis data processing
Documentation
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

# Set explicit permissions to address the linter warning
permissions:
  contents: read

jobs:
  python-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install
      - name: Install git hooks
        run: |
          chmod +x ./scripts/install-hooks.sh
          ./scripts/install-hooks.sh
      - name: Verify pre-commit hook is working
        run: |
          # Check if the pre-commit hook is installed
          if [ ! -f .git/hooks/pre-commit ]; then
            echo "Error: pre-commit hook is not installed. Run scripts/install-hooks.sh to install it."
            exit 1
          fi
          # Check if the pre-commit hook is up-to-date
          if ! diff -q .git/hooks/pre-commit scripts/git-hooks/pre-commit > /dev/null; then
            echo "Error: pre-commit hook is not up-to-date. Run scripts/install-hooks.sh to update it."
            exit 1
          fi
          # Check if the pre-commit hook is running isort with the --check flag
          if ! grep -q "isort --check\|isort --profile black --check" .git/hooks/pre-commit; then
            echo "Error: pre-commit hook is not running isort with the --check flag. Update scripts/git-hooks/pre-commit."
            exit 1
          fi
          echo "Pre-commit hook is installed and up-to-date."
      - name: Lint with black and isort
        run: |
          poetry run black --check nomy_data_models tests
          poetry run isort --check nomy_data_models tests
      - name: Type check with mypy
        run: |
          poetry run mypy nomy_data_models

  python-test:
    runs-on: ubuntu-latest
    needs: python-lint
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install
      - name: Test with pytest (with coverage)
        run: |
          poetry run pytest tests/python

  rust-model-generation:
    runs-on: ubuntu-latest
    needs: python-lint
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install
      - name: Install git hooks
        run: |
          chmod +x ./scripts/install-hooks.sh
          ./scripts/install-hooks.sh
      - name: Generate and verify Rust models
        run: |
          poetry run python scripts/generate_rust.py --verify
      - name: Upload Rust models as artifact
        uses: actions/upload-artifact@v4
        with:
          name: rust-models
          path: src/models/
          retention-days: 1

  rust-build-test:
    runs-on: ubuntu-latest
    needs: rust-model-generation
    steps:
      - uses: actions/checkout@v4
      - name: Download Rust models
        uses: actions/download-artifact@v4
        with:
          name: rust-models
          path: src/models/
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
          toolchain: 1.81.0
      - name: Check formatting
        run: |
          cargo fmt
          git diff --exit-code || (echo "Formatting issues fixed. Please pull the changes and try again." && exit 1)
      - name: Build
        run: |
          cargo build --verbose
      - name: Run tests
        run: |
          cargo test --verbose
      - name: Run Clippy
        run: |
          cargo clippy -- \
            -A clippy::too_many_arguments \
            -A unused_imports \
            -A non_camel_case_types

  publish:
    runs-on: ubuntu-latest
    needs: [python-test, rust-build-test]
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install
      - name: Build and publish Python package
        env:
          POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
        run: |
          poetry build
          poetry publish
      - name: Download Rust models
        uses: actions/download-artifact@v4
        with:
          name: rust-models
          path: src/models/
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
          toolchain: 1.81.0
      - name: Publish Rust crate
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          cargo publish --allow-dirty