# $FreeBSD$

compute_engine_instance:
  # Image list available via
  # gcloud compute images list --project freebsd-org-cloud-dev --no-standard-images
  platform: freebsd
  image_project: freebsd-org-cloud-dev
  image: freebsd-13-2-release-amd64
  cpu: 8
  memory: 8G
  disk: 40

task:
  matrix:
  - name: World and kernel amd64 build and boot smoke test
    env:
      TARGET: amd64
      TARGET_ARCH: amd64
      TOOLCHAIN_PKG: llvm15
  - name: World and kernel arm64 build and boot smoke test
    trigger_type: manual
    env:
      TARGET: arm64
      TARGET_ARCH: aarch64
      TOOLCHAIN_PKG: llvm15
  - name: World and kernel gcc12 amd64 build and boot smoke test
    trigger_type: manual
    env:
      TARGET: amd64
      TARGET_ARCH: amd64
      TOOLCHAIN_PKG: amd64-gcc12
  timeout_in: 120m
  install_script:
  - sh .cirrus-ci/pkg-install.sh ${TOOLCHAIN_PKG} git-lite

  setup_script:
  - uname -a
  - gpart show
  - df -m
  - pkg --version
  - pw useradd user
  - mkdir -p /usr/obj/$(pwd -P)
  - chown user:user /usr/obj/$(pwd -P)

  script:
  - su user -c "make -j$(sysctl -n hw.ncpu) CROSS_TOOLCHAIN=${TOOLCHAIN_PKG} WITHOUT_TOOLCHAIN=yes buildworld buildkernel"

  package_script:
  - su user -c "make CROSS_TOOLCHAIN=${TOOLCHAIN_PKG} WITHOUT_TOOLCHAIN=yes PKG_FORMAT=tar packages"

  package_check_script:
  - su user -c "/usr/libexec/flua tools/pkgbase/metalog_reader.lua -c /usr/obj/$(pwd -P)/${TARGET}.${TARGET_ARCH}/worldstage/METALOG"

  test_script:
  - sh .cirrus-ci/pkg-install.sh qemu-nox11
  - sh tools/boot/ci-qemu-test.sh

  make_sysent_script:
  # Check that make sysent results were committed if required
  - make sysent
  - if ! git diff --exit-code; then printf "\n>>> Generated sysent files not updated, run make sysent <<<\n"; false; fi

  include_ldirs_script:
  # Check that includes/Makefile refers to existing directories
  - if ! make -C include/ check-ldirs; then printf "\n>>> include/Makefile lists nonexistant directories <<<\n"; false; fi

  makeman_script:
  # Check that the committed src.conf.5 matches the one generated by
  # tools/build/options/makeman (modulo the date which always updates)
  # XXX: This script is slow so keep it last
  - (make makeman 2> /tmp/makeman.out); cat /tmp/makeman.out
  - if ! git diff --exit-code --ignore-matching-lines "^.Dd" share/man/man5/src.conf.5; then printf "\n>>> src.conf.5 was not updated as required <<<\n"; false; fi
  - if grep -q "no description found" /tmp/makeman.out; then printf "\n>>> Missing description files <<<\n"; false; fi

  post_script:
  - df -m
  - du -m -s /usr/obj
