name: Build Image
inputs:
  tags:
    description: "Docker image tags"
    required: true
  gh-token:
    description: "Github token"
    required: true

runs:
  using: 'composite'
  steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Download binaries
      uses: actions/download-artifact@v4
      with:
        path: .

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v3

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v3

    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v5
      with:
        images: |
          ghcr.io/sergi0g/cup
        tags: ${{ inputs.tags }}

    - name: Login to GitHub Container Registry
      uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: sergi0g
        password: ${{ inputs.gh-token }}

    - name: Build and push image
      uses: docker/build-push-action@v6
      with:
        context: .
        file: ./.github/actions/build-image/Dockerfile
        platforms: linux/amd64,linux/arm64
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        cache-from: type=gha
        cache-to: type=gha,mode=max
