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
    env:
      DEVNULLRIGHTS: 1
      READFROMBLOCKDEVICE: 1
    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: |
        sudo apt update
        APT_PACKAGES="gcc-multilib" make apt-install
        CFLAGS="-m32 -O1 -fstack-protector" make check V=1

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

    # candidate test (to check) : underlink test
    # LDFLAGS=-Wl,--no-undefined : will make the linker fail if dll is underlinked

  gcc-8-asan-ubsan-testzstd:
    runs-on: ubuntu-latest
    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 V=1

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

  clang-msan-testzstd:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: clang + MSan + Test Zstd
      run: |
        sudo apt-get update
        sudo apt-get install clang
        CC=clang make msan-test-zstd HAVE_ZLIB=0 HAVE_LZ4=0 HAVE_LZMA=0 V=1

    # 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-asan-ubsan-fuzz32:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: ASan + UBSan + Fuzz Test 32bit
      run: |
        make libc6install
        CFLAGS="-O2 -m32" FUZZER_FLAGS="--long-tests" make uasan-fuzztest

  clang-msan-fuzz:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: clang + MSan + Fuzz Test
      run: |
        sudo apt-get update
        sudo apt-get install clang
        CC=clang FUZZER_FLAGS="--long-tests" 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

# For reference : icc tests
# icc tests are currently failing on Github Actions, likely to issues during installation stage
# To be fixed later
#
#  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
