name: Alpine CI
on:
  pull_request:
  push:
  schedule:
    - cron: 0 0 * * 0
  workflow_dispatch:
jobs:
  build:
    if: "!contains(github.event.head_commit.message, '[skip alpine ci]')"
    container: alpine:latest
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install dependencies
        run: |-
          echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
          apk update
          apk add \
            argon2-dev \
            clang \
            cmake \
            g++ \
            gettext \
            git \
            gnutls-dev \
            mariadb-dev \
            openldap-dev \
            openssl-dev \
            pcre2-dev \
            samurai \
            sqlite-dev \
            tre-dev

      - name: Enable extras
        run: |-
          for MODULE in enc_argon2 enc_posix ldap mysql regex_pcre2 regex_posix regex_tre sqlite ssl_gnutls ssl_openssl
          do
            ln -s $PWD/modules/extra/$MODULE.cpp $PWD/modules
          done

      - name: Run CMake
        env:
          CC: ${{ matrix.compiler.cc }}
          CXX: ${{ matrix.compiler.cxx }}
          CXXFLAGS: -Werror
        run: |-
          cmake -B "build" \
                -D "CMAKE_BUILD_TYPE=Debug" \
                -D "INSTDIR=$(readlink -f ../run)" \
                -G "Ninja" \
                -Wdeprecated \
                -Wdev

      - name: Build and install
        env:
          VERBOSE: ${{ runner.debug }}
        run: |-
          ninja -C "build" ${{ runner.debug == '1' && '-v' || '' }} install

    strategy:
      fail-fast: false
      matrix:
        compiler:
          - cc: clang
            cxx: clang++
          - cc: gcc
            cxx: g++
