# Android Cast build pipeline (CircleCI-compatible shape)
version: 2.1

parameters:
  git_ref:
    type: string
    default: next
  gradle_task:
    type: string
    default: assembleDebug
  run_tests:
    type: boolean
    default: true
  run_native:
    type: boolean
    default: true
  run_apk:
    type: boolean
    default: true
  auto_ota:
    type: boolean
    default: false
  ota_channel:
    type: string
    default: staging

jobs:
  android-build:
    docker:
      - image: androidcast-ci:00.01.00.1000
    steps:
      - checkout
      - run:
          name: Native codecs
          command: |
            if [ "<< pipeline.parameters.run_native >>" = "true" ]; then
              ./scripts/ci-build-and-publish-ota.sh
            fi
      - run:
          name: Gradle + tests
          command: |
            export GRADLE_TASK="<< pipeline.parameters.gradle_task >>"
            export RUN_UNIT_TESTS="<< pipeline.parameters.run_tests >>"
            export RUN_APK="<< pipeline.parameters.run_apk >>"
            export AUTO_OTA="<< pipeline.parameters.auto_ota >>"
            export OTA_CHANNEL="<< pipeline.parameters.ota_channel >>"
            ./scripts/ci-build-and-publish-ota.sh
      - store_artifacts:
          path: out/builds

workflows:
  build:
    jobs:
      - android-build:
          filters:
            branches:
              only: [next, master]
