name: generic-dev

on:
  pull_request:
    branches: [ dev, release, actionsTest ]

jobs:

# Dev PR jobs that still have to be migrated from travis
#
# versionTag (only on release tags)
# valgrindTest (keeps failing for some reason. need investigation)
# staticAnalyze (need trusty so need self-hosted)
# pcc-fuzz: (need trusty so need self-hosted)
# min-decomp-macros (flakey)
#
# setting up self-hosted is pretty straightforward, but
# I need admins permissions to the repo for that it looks like
# So I'm tabling that for now
#
# The release branch exclusive jobs will be in a separate
# workflow file (the osx tests and meson build that is)

  benchmarking:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: make benchmarking
      run: make benchmarking

  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: make test
      run: make test

  check-32bit: # designed to catch https://github.com/facebook/zstd/issues/2428
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: make check on 32-bit
      run: |
        make libc6install
        CFLAGS="-m32 -O1 -fstack-protector" make check V=1

  gcc-6-7-libzstd:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: gcc-6 + gcc-7 + libzstdmt compilation
      run: |
        make gcc6install gcc7install
        CC=gcc-6 CFLAGS=-Werror make -j all
        make clean
        CC=gcc-7 CFLAGS=-Werror make -j all
        make clean
        LDFLAGS=-Wl,--no-undefined make -C lib libzstd-mt
        make -C tests zbufftest-dll

    # candidate test (to check) : underlink test
    # LDFLAGS=-Wl,--no-undefined : will make the linker fail if dll is underlinked
    # zbufftest-dll : test that a user program can link to multi-threaded libzstd without specifying -pthread

  gcc-8-asan-ubsan-testzstd:
    runs-on: ubuntu-16.04 # fails on 18.04
    steps:
    - uses: actions/checkout@v2
    - name: gcc-8 + ASan + UBSan + Test Zstd
      run: |
        make gcc8install
        CC=gcc-8 CFLAGS="-Werror" make -j all
        make clean
        CC=gcc-8 make -j uasan-test-zstd </dev/null

  gcc-6-asan-ubsan-testzstd-32bit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: gcc-6 + ASan + UBSan + Test Zstd, 32bit mode
      run: |
        make gcc6install libc6install
        CC=gcc-6 CFLAGS="-Werror -m32" make -j all32
        make clean
        CC=gcc-6 make -j uasan-test-zstd32

  clang-38-msan-testzstd:
    runs-on: ubuntu-16.04 # fails on 18.04
    steps:
    - uses: actions/checkout@v2
    - name: clang-3.8 + MSan + Test Zstd
      run: |
        # make clang38install (doesn't work)
        sudo apt-add-repository "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main"
        sudo apt-get update
        sudo apt-get install clang-3.8
        CC=clang-3.8 make clean msan-test-zstd HAVE_ZLIB=0 HAVE_LZ4=0 HAVE_LZMA=0

    # Note : external libraries must be turned off when using MSAN tests,
    # because they are not msan-instrumented,
    # so any data coming from these libraries is always considered "uninitialized"

  cmake-build-and-test-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: cmake build and test check
      run: |
        FUZZERTEST=-T1mn ZSTREAM_TESTTIME=-T1mn make cmakebuild
        cp -r ./ "../zstd source"
        cd "../zstd source"
        FUZZERTEST=-T1mn ZSTREAM_TESTTIME=-T1mn make cmakebuild

  gcc-8-asan-ubsan-fuzz:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: gcc-8 + ASan + UBSan + Fuzz Test
      run: |
        make gcc8install
        CC=gcc-8 FUZZER_FLAGS="--long-tests" make clean uasan-fuzztest

  gcc-6-asan-ubsan-fuzz32:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: gcc-6 + ASan + UBSan + Fuzz Test 32bit
      run: |
        make gcc6install libc6install
        CC=gcc-6 CFLAGS="-O2 -m32" FUZZER_FLAGS="--long-tests" make uasan-fuzztest

  clang-38-msan-fuzz:
    runs-on: ubuntu-16.04 # fails on 18.04
    steps:
    - uses: actions/checkout@v2
    - name: clang-3.8 + MSan + Fuzz Test
      run: |
        # make clang38install (doesn't work)
        sudo apt-add-repository "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main"
        sudo apt-get update
        sudo apt-get install clang-3.8
        CC=clang-3.8 make clean msan-fuzztest

  asan-ubsan-msan-regression:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: ASan + UBSan + MSan + Regression Test
      run: |
        make -j uasanregressiontest
        make clean
        make -j msanregressiontest

  cpp-gnu90-c99-compatibility:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: C++, gnu90 and c99 compatibility
      run: |
        make cxxtest
        make clean
        make gnu90build
        make clean
        make c99build
        make clean
        make travis-install   # just ensures `make install` works

  mingw-cross-compilation:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: mingw cross-compilation
      run: |
        # sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix; (doesn't work)
        sudo apt-get install gcc-mingw-w64
        CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CFLAGS="-Werror -O1" make zstd

# TODO: Broken test - fix and uncomment
#  armbuild:
#    runs-on: ubuntu-16.04 # doesn't work on latest
#    steps:
#    - uses: actions/checkout@v2
#    - name: ARM Build Test
#      run: |
#        make arminstall
#        make armbuild

# TODO: Broken test - fix and uncomment
#  armfuzz:
#    runs-on: ubuntu-16.04 # doesn't work on latest
#    steps:
#    - uses: actions/checkout@v2
#    - name: Qemu ARM emulation + Fuzz Test
#      run: |
#        make arminstall
#        make armfuzz

  bourne-shell:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Bourne shell compatibility (shellcheck)
      run: |
        wget https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.x86_64.tar.xz
        tar -xf shellcheck-v0.7.1.linux.x86_64.tar.xz
        shellcheck-v0.7.1/shellcheck --shell=sh --severity=warning --exclude=SC2010 tests/playTests.sh

  icc:
    name: icc-check
    runs-on: ubuntu-latest
    steps:
    - name: install icc
      run: |
        export DEBIAN_FRONTEND=noninteractive
        sudo apt-get -qqq update
        sudo apt-get install -y wget build-essential pkg-config cmake ca-certificates gnupg
        sudo wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
        sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
        sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
        sudo apt-get update
        sudo apt-get install -y intel-basekit intel-hpckit
    - uses: actions/checkout@v2
    - name: make check
      run: |
        make CC=/opt/intel/oneapi/compiler/latest/linux/bin/intel64/icc check
