image: fedora:30

variables:
  DOCKER_DRIVER: overlay2

stages:
  - build

build:
  stage: build
  retry: 1
  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-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 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/qemu-coreboot
      - ./build/x230-flash
      - ./build/t430-flash
      - ./build/x230-hotp-verification
      - ./build/x230
      - ./build/t430