stages:
  - format
  - build_and_test
  - quality
  - package

.env:
  image: axiomteam/gecko-ci:v0.0.11
  tags:
    - docker

format:
  extends: .env
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /^wip*$/
      when: manual
    - if: $CI_COMMIT_TAG || $CI_MERGE_REQUEST_ID
    - when: manual
  stage: format
  script:
    - flutter format --set-exit-if-changed lib

build_and_test:
  extends: .env
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /^wip*$/
      when: manual
    - if: $CI_COMMIT_TAG || $CI_MERGE_REQUEST_ID
    - when: manual
  stage: build_and_test
  script:
    - flutter analyze

releases:test:
  extends: .env
  stage: package
  allow_failure: true
  rules:
    - if: $CI_COMMIT_TAG
      when: never
    - when: manual
  script:
    - bash "release/android/build-apk.sh" "$(date +%Y%m%d).$(date +%H%M).$(date +%S)+0"
  artifacts:
    paths: &releases_artifacts
      - work/bin/
    expire_in: 72h

releases:x64:
  extends: .env
  stage: package
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - bash "release/android/build-apk.sh" "${CI_COMMIT_TAG#v}"
  artifacts:
    paths: *releases_artifacts
    expire_in: 1 mos
