name: 'Tests'
on:
  push:
jobs:
  test:
    strategy:
      matrix:
        suite:
          - wpunit
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 1000
          submodules: recursive
      # ------------------------------------------------------------------------------
      # Checkout slic
      # ------------------------------------------------------------------------------
      - name: Checkout slic
        uses: actions/checkout@v2
        with:
          repository: stellarwp/slic
          ref: main
          path: slic
          fetch-depth: 1
      # ------------------------------------------------------------------------------
      # Prepare our composer cache directory
      # ------------------------------------------------------------------------------
      - name: Get Composer Cache Directory
        id: get-composer-cache-dir
        run: |
          echo "::set-output name=dir::$(composer config cache-files-dir)"
      - uses: actions/cache@v2
        id: composer-cache
        with:
          path: ${{ steps.get-composer-cache-dir.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-
      # ------------------------------------------------------------------------------
      # Initialize slic
      # ------------------------------------------------------------------------------
      - name: Set up slic env vars
        run: |
          echo "SLIC_BIN=${GITHUB_WORKSPACE}/slic/slic" >> $GITHUB_ENV
          echo "SLIC_WP_DIR=${GITHUB_WORKSPACE}/slic/_wordpress" >> $GITHUB_ENV
          echo "SLIC_WORDPRESS_DOCKERFILE=Dockerfile.base" >> $GITHUB_ENV
      - name: Set run context for slic
        run: echo "SLIC=1" >> $GITHUB_ENV && echo "CI=1" >> $GITHUB_ENV
      - name: Start ssh-agent
        run: |
          mkdir -p "${HOME}/.ssh";
          ssh-agent -a /tmp/ssh_agent.sock;
      - name: Export SSH_AUTH_SOCK env var
        run: echo "SSH_AUTH_SOCK=/tmp/ssh_agent.sock" >> $GITHUB_ENV
      - name: Set up slic for CI
        run: |
          cd ${GITHUB_WORKSPACE}/..
          ${SLIC_BIN} here
          ${SLIC_BIN} interactive off
          ${SLIC_BIN} build-prompt off
          ${SLIC_BIN} build-subdir off
          ${SLIC_BIN} xdebug off
          ${SLIC_BIN} debug on
          ${SLIC_BIN} info
          ${SLIC_BIN} config
      - name: Set up StellarWP Telemetry
        run: |
          ${SLIC_BIN} use telemetry
          ${SLIC_BIN} composer install --ignore-platform-reqs
      - name: Run suite wpunit
        run: ${SLIC_BIN} run ${{ matrix.suite }} --ext DotReporter
