# Kuality Quality Gate — CircleCI Config Template
#
# Environment variables (Project Settings → Environment Variables):
#   KUALITY_API_KEY    — your Kuality API key (from Organization → API Keys)
#   STAGING_URL        — e.g. https://staging.yoursite.com
#   SCAN_TYPES         — scan type to run (default: web)

version: 2.1

jobs:
  kuality-scan:
    docker:
      - image: cimg/base:current
    steps:
      - run:
          name: Install Kuality CLI
          command: |
            ARCH=$(uname -m)
            case "$ARCH" in
              x86_64)  ARCH="amd64" ;;
              aarch64) ARCH="arm64" ;;
            esac
            curl -fsSL "https://github.com/kuality-io/cli/releases/latest/download/kuality_latest_linux_${ARCH}.tar.gz" -o kuality.tar.gz
            tar xzf kuality.tar.gz
            sudo mv kuality /usr/local/bin/
      - run:
          name: Run Kuality scan
          command: |
            kuality scan "${STAGING_URL}" \
              --type "${SCAN_TYPES:-web}" \
              --fail-on high \
              --format junit > kuality-report.xml
      - store_test_results:
          path: kuality-report.xml
      - store_artifacts:
          path: kuality-report.xml

workflows:
  quality-gate:
    jobs:
      - kuality-scan:
          filters:
            branches:
              only:
                - main
                - /pull\/.*/
