name: End-to-End Blackbox Tests

on:
  workflow_dispatch:
  workflow_call:
    inputs:
      should_skip:
        required: false
        type: string

jobs:
  test:
    name: Test
    if: inputs.should_skip != 'true'
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-version:
          - '16'
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Prepare
        uses: ./.github/actions/prepare

      - name: Install oracle client
        run: |
          sudo apt update -y && sudo apt install -y alien libaio1 && \
          wget https://download.oracle.com/otn_software/linux/instantclient/214000/$ORACLE_DL && \
          sudo alien -i $ORACLE_DL
        env:
          ORACLE_DL: oracle-instantclient-basic-21.4.0.0.0-1.el8.x86_64.rpm

      - name: Start databases
        run: docker compose -f tests-blackbox/docker-compose.yml up -d --quiet-pull --wait

      - name: Run tests
        run: pnpm run -w test:blackbox

  result:
    name: Result
    if: inputs.should_skip != 'true' && always()
    runs-on: ubuntu-latest
    needs: test
    steps:
      - name: Mark result as failed
        if: needs.test.result != 'success'
        run: exit 1
