```
default:
  image: debian:testing
  tags:
    - trixie

stages:
  - build
  - test
  - generate
  - lava

check devicetrees:
  stage: build
  tags:
    - ultra-heavyweight
  variables:
    DEBIAN_FRONTEND: noninteractive
    GIT_SUBMODULE_STRATEGY: normal
    ARCH: arm64
    DEFCONFIG: defconfig
    CROSS_COMPILE: aarch64-linux-gnu-
    DUT: rockchip/rk3588s-rock-5a.dtb rockchip/rk3588-rock-5b.dtb rockchip/rk3588-evb1-v10.dtb rockchip/rk3576-armsom-sige5.dtb
  before_script:
    - apt update
    - apt install -y devscripts
                     build-essential
                     crossbuild-essential-arm64
                     bc
                     bison
                     flex
                     swig
                     python3-dev
                     python3-pip
                     python3-setuptools
                     yamllint
    - pip3 install --break-system-packages dtschema
  script:
    - make $DEFCONFIG
    - make -j$(nproc) dt_binding_check
    - make -j$(nproc) CHECK_DTBS=y $DUT 2> dt-warnings.txt
    - if [[ $(cat dt-warnings.txt | wc -l) > 0 ]]; then cat dt-warnings.txt; exit 42; fi
  allow_failure:
    exit_codes:
      - 42

.build debian package:
  stage: build
  tags:
    - ultra-heavyweight
  cache:
    when: on_success
    key: $CI_COMMIT_REF_SLUG
    paths:
      - ccache
  variables:
    DEBIAN_FRONTEND: noninteractive
    GIT_SUBMODULE_STRATEGY: normal
    ARCH: amd64
    DEFCONFIG: defconfig
    CCACHE_BASEDIR: $CI_PROJECT_DIR
    CCACHE_DIR: $CI_PROJECT_DIR/ccache
  before_script:
    - dpkg --add-architecture arm64
    - apt update
    - apt install -y devscripts
                     build-essential
                     crossbuild-essential-arm64
                     bc
                     bison
                     ccache
                     flex
                     rsync
                     kmod
                     cpio
                     libelf-dev
                     libssl-dev
                     libssl-dev:arm64
    # Setup ccache
    - export PATH="/usr/lib/ccache:$PATH"
    - ccache -s
  script:
    - make $DEFCONFIG
    - ./scripts/config -e WLAN -e WLAN_VENDOR_BROADCOM -m BRCMUTIL -m BRCMFMAC
                       -e BRCMFMAC_PROTO_BCDC -e BRCMFMAC_PROTO_MSGBUF
                       -e BRCMFMAC_USB
                       -e WLAN_VENDOR_REALTEK -m RTW89 -m RTW89_CORE
                       -e DYNAMIC_DEBUG
                       -m RTW89_PCI -m RTW89_8825B -m RTW89_8852BE
                       -m BINFMT_MISC
                       -m XFS_FS -m EROFS_FS -m F2FS_FS
                       -m EXFAT_FS -m ISO9660_FS
    - make -j$(nproc) $ADDITIONAL_BUILD_CMD bindeb-pkg
    - mkdir artifacts && dcmd mv ../*.changes artifacts/
  artifacts:
    paths:
      - artifacts

build arm64 debian package:
  extends: .build debian package
  variables:
    ARCH: arm64
    CROSS_COMPILE: aarch64-linux-gnu-
    ADDITIONAL_BUILD_CMD: KBUILD_IMAGE=arch/arm64/boot/Image

generate tests:
  image: debian:trixie-slim
  stage: generate
  tags:
    - lightweight
  variables:
    GIT_STRATEGY: fetch
    GIT_DEPTH: "1"
  needs:
    - "build arm64 debian package"
  before_script:
    - apt update
    - apt install -y wget
  script:
    - mkdir deb
    - "for x in artifacts/linux-image*.deb ; do dpkg -x ${x} deb ; done"
    - cp deb/boot/vmlinuz* vmlinuz
    - mkdir -p deb/lib/firmware/arm/mali/arch10.8
    - wget -O deb/lib/firmware/arm/mali/arch10.8/mali_csffw.bin "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/arm/mali/arch10.8/mali_csffw.bin"
    - tar -f modules.tar.gz  -C deb  -c -z -v lib/modules lib/firmware
    - mkdir dtbs
    - cp -r deb/usr/lib/linux-image*/* dtbs
    - sed -i s,%%KERNEL_BUILD_JOB%%,${CI_JOB_ID},g lava/rock5b-testjob.yaml
    - sed -i s,%%KERNEL_BUILD_JOB%%,${CI_JOB_ID},g lava/sige5-testjob.yaml
  artifacts:
    paths:
      - vmlinuz*
      - modules.tar.gz
      - dtbs
      - lava/rock5b-testjob.yaml
      - lava/sige5-testjob.yaml

lava rock5b test:
  stage: lava
  environment: rock5b
  tags:
    - lava-runner
  script:
    - submit lava/rock5b-testjob.yaml
  needs:
    - "generate tests"
  artifacts:
    when: always
    paths:
      - "*"
    reports:
      junit: "*_junit.xml"

lava sige5 test:
  stage: lava
  environment: sige5
  tags:
    - lava-runner
  script:
    - submit lava/sige5-testjob.yaml
  needs:
    - "generate tests"
  artifacts:
    when: always
    paths:
      - "*"
    reports:
      junit: "*_junit.xml"
```