image: fedora:30

variables:
  DOCKER_DRIVER: overlay2

stages:
  - build

build:
  stage: build
  retry: 2
  cache:
    paths:
      - packages
      - crossgcc
      - build
    key: "heads-$GITLAB_USER_LOGIN-2"
  script:
    - dnf install -y @development-tools gcc-c++ gcc-gnat zlib-devel perl-Digest-MD5 perl-Digest-SHA uuid-devel pcsc-tools ncurses-devel lbzip2 libuuid-devel lzma elfutils-libelf-devel bc bzip2 bison flex git gnupg iasl m4 nasm patch python wget libusb-devel cmake automake pv bsdiff autoconf libtool cpio texinfo
    - git fetch origin 
    - git reset --hard origin/$CI_COMMIT_REF_NAME

    - echo "Removing old x230-flash artifacts..."
    - rm -rf ./build/x230-flash/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=x230-flash board..."
    - make BOARD=x230-flash || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "x230-flash hashes:"
    - cat ./build/x230-flash/hashes.txt
    - echo "Archiving x230-flash logs..."
    - tar zcvf ./build/x230-flash/logs.tar.gz ./build/log/*

    - echo "Removing old t430-flash artifacts..."
    - rm -rf ./build/t430-flash/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=t430-flash board..."
    - make BOARD=t430-flash || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "t430-flash hashes:"
    - cat ./build/t430-flash/hashes.txt
    - echo "Archiving t430-flash logs..."
    - tar zcvf ./build/t430-flash/logs.tar.gz ./build/log/*

    - echo "Removing old x230-external-flash artifacts..."
    - rm -rf ./build/x230-external-flash/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=x230-external-flash board..."
    - make BOARD=x230-external-flash || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "x230-external-flash hashes:"
    - cat ./build/x230-external-flash/hashes.txt
    - echo "Archiving x230-external-flash logs..."

    - tar zcvf ./build/x230-external-flash/logs.tar.gz ./build/log/*
    - echo "Removing old x230-hotp-verification artifacts..."
    - rm -rf ./build/x230-hotp-verification/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=x230-hotp-verification board..."
    - make BOARD=x230-hotp-verification || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "x230-hotp-verification hashes:"
    - cat ./build/x230-hotp-verification/hashes.txt
    - echo "Archiving x230-hotp-verification logs..."
    - tar zcvf ./build/x230-hotp-verification/logs.tar.gz ./build/log/*

    - echo "Removing old x230 artifacts..."
    - rm -rf ./build/x230/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=x230 board..."
    - make BOARD=x230 || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "x230 hashes:"
    - cat ./build/x230/hashes.txt
    - echo "Archiving x230 logs..."
    - tar zcvf ./build/x230/logs.tar.gz ./build/log/*
    - echo "Removing old t430 artifacts..."
    - rm -rf ./build/t430/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=t430 board..."
    - make BOARD=t430 || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "t430 hashes:"
    - cat ./build/t430/hashes.txt
    - echo "Archiving t430 logs..."
    - tar zcvf ./build/t430/logs.tar.gz ./build/log/*
    - echo "Removing old kgpe-d16_workstation artifacts..."
    - rm -rf ./build/kgpe-d16_workstation/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=kgpe-d16_workstation board..."
    - make BOARD=kgpe-d16_workstation || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "kgpe-d16_workstation hashes:"
    - cat ./build/kgpe-d16_workstation/hashes.txt
    - echo "Archiving kgpe-d16_workstation logs..."
    - tar zcvf ./build/kgpe-d16_workstation/logs.tar.gz ./build/log/*
    - echo "Removing old kgpe-d16_workstation-usb_keyboard artifacts..."
    - rm -rf ./build/kgpe-d16_workstation-usb_keyboard/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=kgpe-d16_workstation-usb_keyboard board..."
    - make BOARD=kgpe-d16_workstation || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "kgpe-d16_workstation-usb_keyboard hashes:"
    - cat ./build/kgpe-d16_workstation-usb_keyboard/hashes.txt
    - echo "Archiving kgpe-d16_workstation-usb_keyboard logs..."
    - tar zcvf ./build/kgpe-d16_workstation-usb_keyboard/logs.tar.gz ./build/log/*
    - echo "Removing old kgpe-d16_server-whiptail artifacts..."
    - rm -rf ./build/kgpe-d16_server-whiptail/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=kgpe-d16_server-whiptail board..."
    - make BOARD=kgpe-d16_server-whiptail || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "kgpe-d16_server-whiptail hashes:"
    - cat ./build/kgpe-d16_server-whiptail/hashes.txt
    - echo "Archiving kgpe-d16_server-whiptail logs..."
    - tar zcvf ./build/kgpe-d16_server-whiptail/logs.tar.gz ./build/log/*
    - echo "Removing old kgpe-d16_server artifacts..."
    - rm -rf ./build/kgpe-d16_server/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=kgpe-d16_server board..."
    - make BOARD=kgpe-d16_server || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "kgpe-d16_server hashes:"
    - cat ./build/kgpe-d16_server/hashes.txt
    - echo "Archiving kgpe-d16_server logs..."
    - tar zcvf ./build/kgpe-d16_server/logs.tar.gz ./build/log/*
   - echo "Removing old qemu-coreboot artifacts..."
    - rm -rf ./build/qemu-coreboot/*
    - rm -rf ./build/log/*
    - echo "Building BOARD=qemu-coreboot board..."
    - make BOARD=qemu-coreboot || (find ./build/log/ -cmin 1|xargs tail; exit 1)
    - echo "qemu-coreboot hashes:"
    - cat ./build/qemu-coreboot/hashes.txt
    - echo "Archiving qemu-coreboot logs..."
    - tar zcvf ./build/qemu-coreboot/logs.tar.gz ./build/log/*

    - echo "Calculate used space for cache"
    - du -shc packages crossgcc build
  artifacts:
    paths:
      - ./build/kgpe-d16_workstation
      - ./build/kgpe-d16_workstation-usb_keyboard
      - ./build/kgpe-d16_server
      - ./build/qemu-coreboot
      - ./build/x230-flash
      - ./build/t430-flash
      - ./build/x230-hotp-verification
      - ./build/x230-external-flash
      - ./build/x230
