# Woodpecker CI pipeline.
# Stages run sequentially per _docs/02_document/deployment/ci_cd_pipeline.md §2.
# A failed stage stops the pipeline.

clone:
  git:
    image: woodpeckerci/plugin-git

steps:
  fetch:
    image: rust:1.82-bookworm
    commands:
      - cargo fetch --locked

  lint:
    image: rust:1.82-bookworm
    commands:
      - rustup component add rustfmt clippy
      - cargo fmt --all -- --check
      - cargo clippy --all-targets --all-features -- -D warnings

  unit-test:
    image: rust:1.82-bookworm
    commands:
      - cargo test --workspace --all-features --locked

  build-arm64:
    image: rust:1.82-bookworm
    commands:
      - rustup target add aarch64-unknown-linux-gnu
      - cargo install --locked cargo-zigbuild
      - apt-get update && apt-get install -y --no-install-recommends zig
      - cargo zigbuild --release --target aarch64-unknown-linux-gnu --workspace --locked

  build-no-vlm:
    image: rust:1.82-bookworm
    commands:
      - cargo build --workspace --no-default-features --locked
      - cargo test --workspace --no-default-features --locked

  integration-test:
    image: rust:1.82-bookworm
    commands:
      - cargo test --workspace --all-features --locked -- --test-threads=1
    when:
      event: [push, pull_request]

  sitl-conformance:
    image: docker:24-cli
    commands:
      - docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from autopilot
    when:
      event: [push, pull_request]

  security-scan:
    image: rust:1.82-bookworm
    commands:
      - cargo install --locked cargo-audit cargo-deny
      - cargo audit
      - cargo deny check

  package:
    image: docker:24-cli
    commands:
      - docker build -t azaion/autopilot:$${CI_COMMIT_BRANCH}-arm64 .
    when:
      branch: [dev, main]
      event: push

  sign:
    image: cosign:latest
    commands:
      - cosign sign --yes azaion/autopilot:$${CI_COMMIT_TAG}-arm64
    when:
      event: tag

  publish:
    image: docker:24-cli
    commands:
      - docker push azaion/autopilot:$${CI_COMMIT_TAG}-arm64
    when:
      event: tag

  # Benchmark gate is opt-in (manual / nightly) per ci_cd_pipeline.md §6.
  benchmark-gate:
    image: rust:1.82-bookworm
    commands:
      - cargo bench --workspace -- --save-baseline ci
    when:
      event: cron
