stages:
  - check
  - build
  - deploy

variables:
  GIT_SUBMODULE_STRATEGY: recursive

default:
  # built via:
  #     docker load < $(nix-build nix/docker-image.nix)
  image: registry.k0.hswaw.net/q3k/flow3r-build:wlzk2mlpfymmpzbi4cs6vlgmbviz0pl1

clang-tidy:
  stage: check
  script:
    - "bash tools/clang-tidy.sh"
    - "python3 tools/codequal-report.py clang-tidy warnings.txt > cqual.json"
  artifacts:
    when: always
    reports:
      codequality: cqual.json

mypy:
  stage: check
  variables:
    MYPYPATH: python_payload/mypystubs
  script:
    - "set +e +o pipefail"
    - "mypy python_payload/main.py --strict --no-color-output > warnings.txt; result=$?"
    - "python3 tools/codequal-report.py mypy warnings.txt > cqual.json"
    - "set -e -o pipefail"
    - "[ $result == 0 ]"
  artifacts:
    when: always
    reports:
      codequality: cqual.json

format:
  stage: check
  script:
    - "git clean -fdx"
    - "bash tools/format.sh"
    - "[ -z \"$(git status --porcelain)\" ] || (echo 'Differences found, please run tools/format.sh.' && git diff HEAD && exit 1)"

build-p3:
  stage: build
  script:
    - idf.py -g p3 build
  artifacts:
    expose_as: 'Proto 3 ELF'
    paths: ['build/flow3r.elf']
    expire_in: 5 hours

build-p4:
  stage: build
  script:
    - idf.py -g p4 build
  artifacts:
    expose_as: 'Proto 4 ELF'
    paths: ['build/flow3r.elf']
    expire_in: 5 hours

build-p6:
  stage: build
  script:
    - idf.py -g p6 build
  artifacts:
    expose_as: 'Proto 6 ELF'
    paths: ['build/flow3r.elf']
    expire_in: 5 hours

pages:
  stage: deploy
  only:
    - main
  script:
    - cd docs
    - make html
    - mv _build/html ../public
  artifacts:
    paths: ['public']
    expire_in: 1d