name: Dist

on:
  workflow_dispatch:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  deps: cmake libpcaudio-dev libsonic-dev ronn kramdown python3

jobs:

  reprotest:

    runs-on: ubuntu-latest
    name: Build with reprotest on ${{ matrix.arch }}
    strategy:
      fail-fast: false
      matrix:
        arch: [x86-64, x86-32]

        include:
          - arch: x86-32
            archdeps: "gcc-multilib g++-multilib libpcaudio-dev:i386 libsonic-dev:i386 libc6-dbg:i386 libgcc-s1:i386"
            archconfigflags: "-m32"

          - arch: x86-64
            archdeps: ""
            archconfigflags: ''

    steps:
      - uses: actions/checkout@v4
      - uses: firebuild/apt-eatmydata-action@v1
      - name: enable 32bit architecture
        run: sudo dpkg --add-architecture i386
        if: matrix.arch == 'x86-32'
      - name: dependencies
        run: sudo apt-get update && sudo apt-get install ${{ env.deps }} reprotest ${{ matrix.archdeps }}
      - name: run
        run: reprotest --vary=-user_group --vary=-domain_host 'CFLAGS="${{ matrix.archconfigflags }}" CXXFLAGS="${{ matrix.archconfigflags }}" rm -rf build && cmake -Bbuild -DUSE_ASYNC:BOOL=OFF && cmake --build build && ctest --test-dir build -T test -j1 --output-on-failure && touch success' success

  distcheck:

    runs-on: ubuntu-latest
    name: Run distcheck
    steps:
      - uses: actions/checkout@v4
      - uses: firebuild/apt-eatmydata-action@v1
      - name: dependencies
        run: sudo apt-get update && sudo apt-get install ${{ env.deps }}
      - name: configure
        run: cmake -Bbuild -DUSE_ASYNC:BOOL=OFF
      - name: make
        run: cmake --build build
      - name: make check
        run: ctest --test-dir build -T test -j8 --output-on-failure

      - name: make package_source
        run: cmake --build build --target package_source
      - name: unpack
        run: mkdir unpack && tar -C unpack -xf build/espeak-ng-*-Source.tar.bz2

      - name: re-configure
        run: cd unpack/espeak-ng-* && cmake -Bbuild -DUSE_ASYNC:BOOL=OFF
      - name: re-make
        run: cd unpack/espeak-ng-* && cmake --build build
      - name: re-make check
        run: cd unpack/espeak-ng-* && ctest --test-dir build -T test -j8 --output-on-failure
