policy-rs 1.4.12

Policy library for working with protobuf-defined policy objects
# https://taskfile.dev

version: "3"

vars:
  PROJECT_NAME: policy-rs
  BUILD_DIR: target

tasks:
  default:
    desc: "Build the project in debug mode"
    aliases: [b]
    cmds:
      - cargo build

  build:
    desc: "Build the project in debug mode"
    cmds:
      - cargo build

  "build:release":
    desc: "Build the project in release mode"
    aliases: [br, release]
    cmds:
      - cargo build --release

  test:
    desc: "Run all tests"
    aliases: [t]
    cmds:
      - cargo test

  "test:verbose":
    desc: "Run all tests with verbose output"
    aliases: [tv]
    cmds:
      - cargo test -- --nocapture

  format:
    desc: "Format all Rust source files"
    aliases: [fmt, f]
    dir: "{{.TASKFILE_DIR}}"
    cmds:
      - cargo fmt

  "format:check":
    desc: "Check if code is formatted correctly"
    aliases: [fmt-check, fc]
    dir: "{{.TASKFILE_DIR}}"
    cmds:
      - cargo fmt --check

  lint:
    desc: "Run linting checks (clippy)"
    aliases: [l]
    cmds:
      - cargo clippy -- -D warnings

  "lint:fix":
    desc: "Run clippy and apply fixes"
    aliases: [lf]
    cmds:
      - cargo clippy --fix --allow-dirty --allow-staged

  clean:
    desc: "Clean build artifacts"
    aliases: [c]
    cmds:
      - cargo clean
      - echo "Cleaned build artifacts"

  check:
    desc: "Check the project (compile without building)"
    cmds:
      - cargo check

  docs:
    desc: "Generate documentation"
    cmds:
      - cargo doc --no-deps
      - echo "Documentation generated in target/doc/"

  "docs:open":
    desc: "Generate and open documentation"
    cmds:
      - cargo doc --no-deps --open

  deps:
    desc: "Check dependencies and Rust installation"
    cmds:
      - rustc --version
      - cargo --version

  "deps:update":
    desc: "Update dependencies"
    cmds:
      - cargo update

  "deps:outdated":
    desc: "Check for outdated dependencies"
    cmds:
      - "cargo outdated || echo 'Install cargo-outdated: cargo install cargo-outdated'"

  do:
    desc: "Run all pre-commit checks"
    cmds:
      - task format
      - task lint
      - task test
      - echo "All checks passed"

  signoff:
    desc: "Sign off the codebase"
    aliases: [sign, s]
    deps:
      - do
    cmds:
      - gh signoff

  info:
    desc: "Show project information"
    cmds:
      - "echo 'Project: {{.PROJECT_NAME}}'"
      - "echo 'Build directory: {{.BUILD_DIR}}'"
      - rustc --version
      - cargo --version

  watch:
    desc: "Watch for changes and rebuild"
    aliases: [w]
    cmds:
      - "cargo watch -x build || echo 'Install cargo-watch: cargo install cargo-watch'"

  "watch:test":
    desc: "Watch for changes and run tests"
    aliases: [wt]
    cmds:
      - "cargo watch -x test || echo 'Install cargo-watch: cargo install cargo-watch'"

  # =============================================================================
  # Proto / Buf
  # =============================================================================

  "proto:export":
    desc: "Export proto files from buf registry"
    cmds:
      - mkdir -p proto
      - buf export buf.build/opentelemetry/opentelemetry -o proto
      - buf export buf.build/tero/policy -o proto

  "proto:generate":
    desc: "Generate Rust code from protos"
    cmds:
      - cargo build

  "proto:update":
    desc: "Export protos and regenerate Rust code"
    cmds:
      - "task proto:export"
      - "task proto:generate"

  # =============================================================================
  # Release
  # =============================================================================

  release:
    desc: "Run all checks and build release"
    aliases: [r]
    cmds:
      - task do
      - task build:release
      - echo "Release build complete"

  ci:setup:
    desc: "🔧 Install CI/development dependencies (idempotent, safe to run locally)"
    dir: "{{.TASKFILE_DIR}}"
    cmds:
      - |
        echo "🔧 Setting up CI environment..."

        echo "🔧 Checking for required dependencies..."

        # Check for protoc (needed for proto code generation)
        if ! command -v protoc >/dev/null 2>&1; then
          echo "📦 Installing protoc..."
          if [ "$(uname)" = "Darwin" ]; then
            if command -v brew >/dev/null 2>&1; then
              brew install protobuf
            else
              echo "⚠️  Homebrew not found. Install protobuf manually or use Hermit."
            fi
          elif [ "$(uname)" = "Linux" ]; then
            if command -v apt-get >/dev/null 2>&1; then
              sudo apt-get update && sudo apt-get install -y protobuf-compiler
            elif command -v yum >/dev/null 2>&1; then
              sudo yum install -y protobuf-compiler
            else
              echo "⚠️  Unknown package manager. Install protobuf-compiler manually."
            fi
          else
            echo "⚠️  Unknown platform: $(uname)"
          fi
        else
          echo "✅ protoc already installed"
        fi

        # Check for cmake (needed to build vectorscan-rs-sys)
        if ! command -v cmake >/dev/null 2>&1; then
          echo "📦 Installing cmake..."
          if [ "$(uname)" = "Darwin" ]; then
            if command -v brew >/dev/null 2>&1; then
              brew install cmake
            else
              echo "⚠️  Homebrew not found. Install cmake manually or use Hermit."
            fi
          elif [ "$(uname)" = "Linux" ]; then
            if command -v apt-get >/dev/null 2>&1; then
              sudo apt-get update && sudo apt-get install -y cmake
            elif command -v yum >/dev/null 2>&1; then
              sudo yum install -y cmake
            else
              echo "⚠️  Unknown package manager. Install cmake manually."
            fi
          else
            echo "⚠️  Unknown platform: $(uname)"
          fi
        else
          echo "✅ cmake already installed"
        fi

        # Install boost headers (needed to build vectorscan-rs-sys)
        echo "📦 Installing boost headers..."
        if [ "$(uname)" = "Darwin" ]; then
          if command -v brew >/dev/null 2>&1; then
            brew install boost
          else
            echo "⚠️  Homebrew not found. Install boost manually or use Hermit."
          fi
        elif [ "$(uname)" = "Linux" ]; then
          if command -v apt-get >/dev/null 2>&1; then
            sudo apt-get update && sudo apt-get install -y libboost-dev
          elif command -v yum >/dev/null 2>&1; then
            sudo yum install -y boost-devel
          else
            echo "⚠️  Unknown package manager. Install boost manually."
          fi
        else
          echo "⚠️  Unknown platform: $(uname)"
        fi
        echo "✅ boost installed"

        echo "✅ CI setup complete"