name: Build gRPC smoke test distribution

on:
  push:
    paths:
      - 'smoke-tests/grpc/**'
      - '.github/workflows/build-grpc-smoke-dist.yaml'
    branches: 'main'
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11 for running Gradle
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - name: Cache gradle dependencies
        uses: burrunan/gradle-cache-action@v1.6
        with:
          job-id: grpc-smoke

      - name: Login to GitHub Package Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GHCR_TOKEN }}

      - name: Build Docker Image
        run: |
          TAG="$(date '+%Y%m%d').$GITHUB_RUN_ID"
          echo "Pushing to tag $TAG"
          ./gradlew jib -PtargetJDK=8 -Djib.httpTimeout=120000 -Djib.console=plain --stacktrace -Ptag=$TAG
          ./gradlew jib -PtargetJDK=11 -Djib.httpTimeout=120000 -Djib.console=plain --stacktrace -Ptag=$TAG
          ./gradlew jib -PtargetJDK=15 -Djib.httpTimeout=120000 -Djib.console=plain --stacktrace -Ptag=$TAG
        working-directory: smoke-tests/grpc
