name: Publish PetClinic benchmark image
on:
  push:
    paths:
      - 'benchmark-overhead/Dockerfile-petclinic-base'
    branches:
      - main
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
    steps:
      - uses: actions/checkout@v3

      - uses: docker/setup-buildx-action@v2

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

      - name: Create timestamp for docker image tag
        run: echo "TS=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV

      - name: Push to GitHub packages
        uses: docker/build-push-action@v3
        with:
          push: true
          file: benchmark-overhead/Dockerfile-petclinic-base
          tags: ghcr.io/open-telemetry/opentelemetry-java-instrumentation/petclinic-rest-base:${{ env.TS }}
