stages:
  - check
  - build

variables:
  GIT_SUBMODULE_STRATEGY: recursive

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

clang-tidy:
  stage: check
  variables:
    IDF_TOOLCHAIN: "clang"
  script:
    - "idf.py build"
    - "idf.py clang-check"
    - "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_st4m.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:
    - "bash tools/format.sh"
    - "[ -z \"$(git status --porcelain -u no)\" ] || (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: &pages
  stage: build
  script:
    - cd docs
    - make html
    - mv _build/html ../public
  rules:
    - if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH

preview pages:
  <<: *pages
  artifacts:
    paths: ['public']
    # shorter artifacts keep duration to be storage friendly
    expire_in: 10m

# only update public page for CI runs on protected default branch
pages:
  <<: *pages
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
  artifacts:
    paths: ['public']
    expire_in: 1d
