---
runs:
  using: composite
  steps:
    - name: Create `ctest` symbolic link
      run: |
        if ! command -v ctest &> /dev/null && command -v ctest3 &> /dev/null; then
          ln --symbolic ctest3 /usr/bin/ctest
        fi
      shell: bash --noprofile --norc -euxo pipefail {0}

    - name: Test `mod_tile`
      run: ctest --exclude-regex 'clear_dirs|remove_tiles' --output-on-failure
      shell: bash --noprofile --norc -euxo pipefail {0}
      working-directory: build

    - name: Archive test artifacts on failure
      if: failure()
      run: |
        TAR_FILENAME=${{ matrix.image || matrix.os || github.job }}-${{ matrix.compiler }}.tar.gz
        TAR_FILENAME=$(echo "${TAR_FILENAME}" | sed 's/:/-/g')
        tar -zcf ${TAR_FILENAME} tests
      shell: bash --noprofile --norc -euxo pipefail {0}
      working-directory: build

    - name: Upload test artifacts on failure
      if: failure()
      uses: actions/upload-artifact@v3
      with:
        name: Test Artifacts
        path: build/*.tar.gz
