name: Docker
on:
  push:
    paths:
      - '.github/workflows/test_docker.yml'
      - '**/Dockerfile*'
    branches:
      - main
      - release-*
  pull_request:
    paths:
      - .github/workflows/test_docker.yml
      - '**/Dockerfile*'
      - scripts/CLI_VERSION
      - '**/pom.xml'
    branches:
      - main
      - release-*
jobs:
  test:
    name: Test
    timeout-minutes: 120
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        flavor: [focal, jammy]
    steps:
      - uses: actions/checkout@v3
      - name: Build Docker image
        run: bash utils/docker/build.sh --amd64 ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
      - name: Test
        run: |
          CONTAINER_ID="$(docker run --rm --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash)"
          docker exec "${CONTAINER_ID}" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh
