name: Publish Play images for smoke tests

on:
  push:
    paths:
      - 'smoke-tests/images/play/**'
      - '.github/workflows/publish-smoke-test-play-images.yml'
    branches:
      - main
  workflow_dispatch:

jobs:
  publish:
    uses: ./.github/workflows/reusable-smoke-test-images.yml
    with:
      project: ":smoke-tests:images:play"
      publish: true
      # Play doesn't support Java 16+ yet
      # https://github.com/playframework/playframework/pull/10819
      skip-java-17: true
      skip-java-18: true
      skip-java-19: true

  publish-java-15:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up JDK for running Gradle
        uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 17

      - name: Login to GitHub package registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Set tag
        run: echo "TAG=$(date '+%Y%m%d').$GITHUB_RUN_ID" >> $GITHUB_ENV

      - name: Set up Gradle cache
        uses: gradle/gradle-build-action@v2

        # Play doesn't support Java 16 (or 17) yet
        # https://github.com/playframework/playframework/pull/10819
      - name: Build Java 15 Docker image
        run: ./gradlew :smoke-tests:images:play:jib -PtargetJDK=15 -Djib.httpTimeout=120000 -Djib.console=plain -Ptag=${{ env.TAG }}

  open-issue-on-failure:
    needs:
      - publish
      - publish-java-15
    if: failure()
    uses: ./.github/workflows/reusable-open-issue-on-failure.yml
