name: Linux

on:
  push:
    branches: ["master"]
    tags: ["4.*"]
  pull_request:
    branches: ["master"]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: build + test
    strategy:
      fail-fast: false
      matrix:
        os:
          - amazonlinux:2023
          - ubuntu:22.04
          - ubuntu:24.04
    runs-on: ubuntu-latest
    container:
      image: ${{ matrix.os }}
      volumes:
        - ${{ contains('amazonlinux:2 ubuntu:16.04 ubuntu:18.04', matrix.os) && '/node20217:/node20217:rw,rshared' || ' ' }}
        - ${{ contains('amazonlinux:2 ubuntu:16.04 ubuntu:18.04', matrix.os) && '/node20217:/__e/node20:ro,rshared' || ' ' }}
    steps:
      - name: Install `yum` dependencies
        run: yum install -y gcc make gzip tar openssl-devel libevent-devel wget which
        if: ${{ contains(matrix.os, 'amazonlinux') }}

      - name: Install Node.js 20 built against glibc 2.17 for GitHub Actions
        run: |
          set -ex
          which apt \
             && apt update \
             && apt install -y wget xz-utils
          which yum \
             && yum install -y wget xz
          wget https://unofficial-builds.nodejs.org/download/release/v20.9.0/node-v20.9.0-linux-x64-glibc-217.tar.xz
          tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
          ldd /__e/node20/bin/node
        working-directory: /tmp/
        if: ${{ contains('amazonlinux:2 ubuntu:16.04 ubuntu:18.04', matrix.os) }}

      - uses: actions/checkout@v6

      - name: Install `apt` dependencies
        # Set env variable or otherwise `tzdata` package requires interaction.
        env:
          DEBIAN_FRONTEND: noninteractive
        uses: ./.github/workflows/actions/ubuntu-build-deps
        if: ${{ contains(matrix.os, 'ubuntu') }}

      - run: ./configure
      - run: make

      - run: make check

      - run: ./run_tests.sh
        working-directory: examples/
      - run: ./run_tests_conf.sh
        working-directory: examples/
      - run: ./run_tests_prom.sh
        working-directory: examples/
        if: ${{ contains(matrix.os, 'ubuntu') }}
