From 574f9d5453293726f6f4f8d5897cbf134480f0dc Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Mon, 15 Mar 2021 09:25:15 -0700
Subject: [PATCH v60 17/17] ci: add

---
 .cirrus.yml                | 229 +++++++++++++++++++++++++++++++++++++
 ci/LinuxDockerfile         |   4 +
 ci/WindowsDockerfile       |  26 +++++
 ci/windows_build_config.pl |   3 +
 4 files changed, 262 insertions(+)
 create mode 100644 .cirrus.yml
 create mode 100644 ci/LinuxDockerfile
 create mode 100644 ci/WindowsDockerfile
 create mode 100644 ci/windows_build_config.pl

diff --git a/.cirrus.yml b/.cirrus.yml
new file mode 100644
index 00000000000..22e8a4faffc
--- /dev/null
+++ b/.cirrus.yml
@@ -0,0 +1,229 @@
+env:
+  # accelerate initial clone
+  CIRRUS_CLONE_DEPTH: 1
+  # target to test, for all but OSX and windows
+  CHECK: check-world
+  CHECKFLAGS: -Otarget
+
+
+task:
+  name: FreeBSD
+  compute_engine_instance:
+    image_project: pg-vm-images-aio
+    image: family/pg-aio-freebsd-12-2
+    platform: freebsd
+    cpu: 4
+    memory: 8G
+  env:
+    CCACHE_SIZE: "500M"
+    CCACHE_DIR: "/tmp/ccache_dir"
+  ccache_cache:
+    folder: "/tmp/ccache_dir"
+  sysconfig_script:
+    - sudo sysctl kern.corefile='/tmp/%N.%P.core'
+  create_user_script:
+    - pw useradd postgres
+    - chown -R postgres:postgres .
+    - mkdir -p /tmp/ccache_dir
+    - chown -R postgres:postgres /tmp/ccache_dir
+  build_script:
+    - su postgres -c './configure --enable-cassert --enable-debug --enable-tap-tests --with-includes=/usr/local/include --with-libs=/usr/local/lib CC="ccache cc"'
+    - su postgres -c 'gmake -s -j4'
+  freebsd_test_script:
+    - su postgres -c 'time gmake -s -j4 ${CHECK} ${CHECKFLAGS}' > test.log 2>&1
+  on_failure:
+    core_script:
+      for corefile in $(find /tmp -name '*.core' 2>/dev/null) ; do binary=$(gdb -quiet -core $corefile -batch -ex 'info auxv' | grep AT_EXECPATH | perl -pe "s/^.*\"(.*)\"\$/\$1/g") ; echo dumping $corefile for $binary ; gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile ; done
+    debug_script:
+      - for F in ` find . -name initdb.log -o -name regression.diffs -o -name 'postmaster*.log'` ; do echo === $F === ; head -1000 $F ; done
+    log_artifacts:
+      path: "**/**.log"
+      type: text/plain
+
+
+task:
+  name: Linux Debian Bullseye
+  compute_engine_instance:
+    image_project: pg-vm-images-aio
+    image: family/pg-aio-bullseye
+    platform: linux
+    cpu: 4
+    memory: 8G
+    nested_virtualization: false
+  env:
+    CCACHE_SIZE: "4GB"
+    CCACHE_DIR: "/tmp/ccache_dir"
+    DEBUGINFOD_URLS: "https://debuginfod.debian.net"
+    TIMEOUT_CMD: timeout -s KILL -v 25m
+  ccache_cache:
+    folder: "/tmp/ccache_dir"
+  test_script:
+    - id
+    - uname -a
+    - cat /proc/cmdline
+    - lsblk
+    - cat /proc/cmdline
+    - ulimit -a -H
+    - ulimit -a -S
+    - export
+  create_user_script:
+    - useradd -m postgres
+    - chown -R postgres:postgres .
+    - mkdir -p /tmp/ccache_dir
+    - chown -R postgres:postgres /tmp/ccache_dir
+    - echo '* - memlock 134217728' > /etc/security/limits.d/postgres.conf
+    - su postgres -c 'ulimit -l -H'
+    - su postgres -c 'ulimit -l -S'
+    - echo '/tmp/%e-%s-%p.core' > /proc/sys/kernel/core_pattern
+  configure_script:
+    - su postgres -c './configure --enable-cassert --enable-debug --enable-tap-tests --with-tcl --with-python --with-perl --with-ldap --with-openssl --with-icu --with-llvm CC="ccache gcc" CXX="ccache g++" CLANG="ccache clang"'
+  build_script:
+    - su postgres -c 'make -s -j4 && make -j4 -C contrib'
+  linux_test_script:
+    - su postgres -c 'ulimit -c unlimited ; ${TIMEOUT_CMD} make -s ${CHECK} ${CHECKFLAGS} -j8'
+  on_failure:
+    cores_script:
+      - for corefile in $(find /tmp/ -name '*.core' 2>/dev/null) ; do binary=$(gdb -quiet -core $corefile -batch -ex 'info auxv' | grep AT_EXECFN | perl -pe "s/^.*\"(.*)\"\$/\$1/g") ; echo dumping $corefile for $binary ; gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $binary $corefile ; done
+    debug_script:
+      - for F in ` find . -name initdb.log -o -name regression.diffs -o -name 'postmaster*.log'` ; do echo === $F === ; head -1000 $F ; done
+    log_artifacts:
+      path: "**/**.log"
+      type: text/plain
+
+
+task:
+  name: macOS
+  osx_instance:
+    image: catalina-base
+  env:
+    CHECK: check
+  install_script:
+    - sudo chmod 777 /cores
+    - uname -a
+    - brew install make coreutils
+    - cpan -T IPC::Run
+  build_script:
+    - export PERL5LIB=~/perl5/lib/perl5
+    - ./configure --prefix=$HOME/install --enable-cassert --enable-debug --enable-tap-tests --without-readline CFLAGS="-O0"
+    - gmake -s -j12
+    - gmake -s install
+  macos_test_script:
+    - ulimit -c unlimited
+    - export PERL5LIB=~/perl5/lib/perl5
+    - gtimeout -s KILL -v 15m gmake -s -j12 ${CHECK} ${CHECKFLAGS}
+  on_failure:
+    debug_script:
+      - for F in ` find . -name initdb.log -o -name regression.diffs -o -name 'postmaster*.log'` ; do echo === $F === ; head -1000 $F ; done
+      - for corefile in $(find /cores/ -name 'core.*' 2>/dev/null) ; do lldb -c $corefile --batch -o 'thread backtrace all' -o 'quit' ; done
+    log_artifacts:
+      path: "**/**.log"
+      type: text/plain
+
+
+task:
+  name: Windows
+  windows_container:
+    dockerfile: ci/WindowsDockerfile
+    cpu: 8
+    memory: 8G
+  env:
+    PROVE_FLAGS: -j10
+    # Avoid re-installing over and over
+    NO_TEMP_INSTALL: 1
+    TIMEOUT_CMD: timeout -k60s 30m
+
+  test_script:
+    - powershell -Command get-psdrive -psprovider filesystem
+    - set
+
+  config_script:
+    - copy ci\windows_build_config.pl src\tools\msvc\config.pl
+    - vcvarsall x64
+    - perl src/tools/msvc/mkvcbuild.pl
+  build_script:
+    - set IgnoreWarnIntDirInTempDetected=true
+    - vcvarsall x64
+    - msbuild -m pgsql.sln
+  install_script:
+    - perl src\tools\msvc\install.pl tmp_install
+
+  check_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl check parallel
+
+  ecpgcheck_script:
+    # tries to build additional stuff
+    - vcvarsall x64
+    # References ecpg_regression.proj in the current dir
+    - cd src\tools\msvc
+    - timeout -k60s 30m perl vcregress.pl ecpgcheck
+
+  startcreate_script:
+    - tmp_install\bin\pg_ctl.exe initdb -D tmp_check\db -l tmp_check\initdb.log
+    - tmp_install\bin\pg_ctl.exe start -D tmp_check\db -o -cmax_prepared_transactions=10 -l tmp_check\postmaster.log
+  modulescheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl modulescheck
+  isolationcheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl isolationcheck
+  contribcheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl contribcheck
+  plcheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl plcheck
+  stop_script:
+    # XXX: should ensure this gets called if previous steps fail
+    - tmp_install\bin\pg_ctl.exe stop -D tmp_check\db -l tmp_check\postmaster.log
+  recoverycheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl recoverycheck
+  bincheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl bincheck
+  upgradecheck_script:
+    - timeout -k60s 30m perl src/tools/msvc/vcregress.pl upgradecheck
+  on_failure:
+    log_artifacts:
+      path: "**/**.log"
+      type: text/plain
+    regress_log_artifacts:
+      path: "**/tmp_check/log/regress_log*"
+      type: text/plain
+    regress_diffs_artifacts:
+      path: "**/**.diffs*"
+      type: text/plain
+
+
+task:
+  name: CompilerWarnings
+  depends_on:
+  - FreeBSD
+  - Linux Debian Bullseye
+  - Windows
+  - macOS
+  container:
+    dockerfile: ci/LinuxDockerfile
+  env:
+    CCACHE_SIZE: "4GB"
+    CCACHE_DIR: "/tmp/ccache_dir"
+  ccache_cache:
+    folder: "/tmp/ccache_dir"
+  setup_script:
+    - echo "COPT=-Werror" > src/Makefile.custom
+    - gcc -v
+    - clang -v
+  # gcc with asserts disabled
+  always:
+    gcc_warning_script:
+      - ./configure --cache gcc.cache CC="ccache gcc"
+      - time make -s -j4 clean && time make -s -j4
+  # gcc with asserts enabled
+  always:
+    gcc_a_warning_script:
+      - ./configure --cache gcc.cache --enable-cassert CC="ccache gcc"
+      - time make -s -j4 clean && time make -s -j4
+  # clang with asserts disabled
+  always:
+    clang_warning_script:
+      - ./configure --cache clang.cache CC="ccache clang"
+      - time make -s -j4 clean && time make -s -j4
+  # clang with asserts enabled
+  always:
+    clang_a_warning_script:
+      - ./configure --cache clang.cache --enable-cassert CC="ccache clang"
+      - time make -s -j4 clean && time make -s -j4
diff --git a/ci/LinuxDockerfile b/ci/LinuxDockerfile
new file mode 100644
index 00000000000..1278068596a
--- /dev/null
+++ b/ci/LinuxDockerfile
@@ -0,0 +1,4 @@
+FROM debian:bullseye
+RUN apt-get -y update
+RUN apt-get -y upgrade
+RUN DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install gcc g++ libreadline-dev flex bison make perl libipc-run-perl clang llvm-dev libperl-dev libpython3-dev tcl-dev libldap2-dev libicu-dev docbook-xml docbook-xsl fop libxml2-utils xsltproc krb5-admin-server krb5-kdc krb5-user slapd ldap-utils libssl-dev pkg-config locales-all liburing-dev python3-distutils ccache gdb
diff --git a/ci/WindowsDockerfile b/ci/WindowsDockerfile
new file mode 100644
index 00000000000..6211322cc40
--- /dev/null
+++ b/ci/WindowsDockerfile
@@ -0,0 +1,26 @@
+#FROM cirrusci/windowsservercore:2019
+FROM cirrusci/windowsservercore:cmake
+
+SHELL ["powershell", "-NoLogo", "-NoProfile", "-Command"]
+
+RUN powershell -NoLogo -NoProfile -Command \
+  choco install -y --no-progress strawberryperl ; \
+  choco install -y --no-progress winflexbison diffutils ; \
+  Rename-Item -Path c:\ProgramData\chocolatey\bin\win_flex.exe flex.exe ; \
+  Rename-Item -Path c:\ProgramData\chocolatey\bin\win_bison.exe bison.exe ; \
+  Remove-Item C:\ProgramData\chocolatey\logs\*.* -Force -Recurse ; \
+  Remove-Item C:\Users\ContainerAdministrator\AppData\Local\Temp\*.* -Force -Recurse
+
+# not needed anymore, installed in cmake image after
+# https://github.com/cirruslabs/docker-images-windows/pull/21/commits/437d7321d33198f27246dac11d80bac29a0aed0a
+#RUN powershell -NoLogo -NoProfile -Command \
+#  choco feature disable -n=usePackageExitCodes ; \
+#  choco install -d -y --no-progress visualstudio2019buildtools --parameters=\"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.18362 \" ; \
+#  Remove-Item C:\ProgramData\chocolatey\logs\*.* -Force -Recurse ; \
+#  Remove-Item C:\Users\ContainerAdministrator\AppData\Local\Temp\*.* -Force -Recurse
+
+SHELL ["cmd", "/s", "/c"]
+
+# Adding VS path to vcvarsall.bat so user of container doesn't need to know the full path
+# Ordered so strawberry perl wins over git perl
+RUN setx path /m "C:\strawberry\perl\bin;C:\Program Files\Git\usr\bin;c:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build;%PATH%"
diff --git a/ci/windows_build_config.pl b/ci/windows_build_config.pl
new file mode 100644
index 00000000000..a8abfa2a02f
--- /dev/null
+++ b/ci/windows_build_config.pl
@@ -0,0 +1,3 @@
+$config->{"tap_tests"} = 1;
+$config->{"asserts"} = 1;
+1;
-- 
2.31.0.121.g9198c13e34

