name: Build container
description: Build and push a container

inputs:
  target:
    required: true

runs:
  using: composite
  steps:
    - uses: docker/metadata-action@v4
      id: meta
      with:
        images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ inputs.target }}
        tags: |
          type=ref,event=branch
          type=semver,pattern={{version}}
          type=semver,pattern={{major}}.{{minor}}

    - uses: docker/build-push-action@v3
      with:
        context: .
        pull: true
        push: ${{ github.event_name == 'push' }}
        build-args: |
          LIBRETIME_VERSION=${{ env.LIBRETIME_VERSION }}
        target: ${{ inputs.target }}
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}
        cache-from: type=gha,scope=${{ inputs.target }}
        cache-to: type=gha,scope=${{ inputs.target }},mode=max
