name: Docker
on:
  push:
    paths:
      - '.github/workflows/test_docker.yml'
      - '**/Dockerfile*'
    branches:
      - main
      - release-*
  pull_request:
    paths:
      - .github/workflows/test_docker.yml
      - '**/Dockerfile*'
      - scripts/DRIVER_VERSION
      - '**/pom.xml'
    branches:
      - main
      - release-*
jobs:
  test:
    name: Test
    timeout-minutes: 120
    runs-on: ${{ matrix.runs-on }}
    strategy:
      fail-fast: false
      matrix:
        flavor: [jammy, noble]
        runs-on: [ubuntu-24.04, ubuntu-24.04-arm]
    steps:
      - uses: actions/checkout@v4
      - name: Build Docker image
        run: |
          ARCH="${{ matrix.runs-on == 'ubuntu-24.04-arm' && 'arm64' || 'amd64' }}"
          bash utils/docker/build.sh --$ARCH ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
      - name: Test
        run: |
          CONTAINER_ID="$(docker run --rm -e CI --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
