
stages:
  - build
  - analyze

analyze:
  stage: analyze
  image: cirrusci/flutter:latest
  before_script:
    - cd "$CI_PROJECT_DIR/"
  script:
    - flutter analyze --write=analyzer-output.txt
  artifacts:
    paths:
      - analyzer-output.txt

build:
  stage: build
  image: cirrusci/flutter:latest
  before_script:
    - cd "$CI_PROJECT_DIR/"
  script:
    - flutter packages get
    - flutter build apk
  artifacts:
    paths:
      - /build/app/outputs/apk/release/app-release.apk

test:
  stage: build
  image: cirrusci/flutter:latest
  before_script:
    - cd "$CI_PROJECT_DIR/"
    - flutter packages get
  script:
    - flutter test --coverage
  artifacts:
    paths:
      - /coverage/lcov.info

sonar:
  stage: analyze
  image:
    name: jdwvierling/sonarflutter:1
    entrypoint: [""]
  variables:
    # Defines the location of the analysis task cache
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
    # Shallow cloning needs to be disabled.
    # See https://docs.sonarqube.org/latest/analysis/gitlab-cicd/.
    GIT_DEPTH: 0
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - sonar-scanner
