name: Plugin Validation

on:
  workflow_call:
    inputs:
      soft-fail:
        description: "Whether to continue on validation errors"
        required: false
        type: boolean
        default: false

permissions:
  contents: read

jobs:
  validate:
    name: Validate Plugins
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - name: Setup Node.js
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Install PowerShell-Yaml
        shell: pwsh
        run: |
          if (-not (Get-Module -ListAvailable -Name PowerShell-Yaml | Where-Object { $_.Version -eq '0.4.7' })) {
            Install-Module -Name PowerShell-Yaml -RequiredVersion 0.4.7 -Force -Scope CurrentUser
          }

      - name: Create logs directory
        run: mkdir -p logs

      - name: Validate collection metadata
        run: npm run lint:collections-metadata

      - name: Validate marketplace manifest
        run: npm run lint:marketplace

      - name: Check plugin freshness
        run: |
          npm run plugin:generate
          if ! git diff --quiet plugins/; then
            echo "::error::Plugins out of date. Run 'npm run plugin:generate' and commit."
            if [ "${{ inputs.soft-fail }}" != "true" ]; then
              exit 1
            fi
          fi

