name: "Build Debian cross-compile Docker image"
inputs:
  img-name:
    description: 'Image Name'
    required: true
  deb-vers:
    description: 'Debian version'
    required: true
  arch:
    description: 'Cross compile architecture'
    required: true
  tag:
    description: 'Image tag'
    required: true
  user:
    description: 'Registry user'
    required: true
  pass:
    description: 'Registry password/token'
    required: true
runs:
  using: "composite"
  steps:
    # Log into the Github container registry using
    # the provided credentials passed in the workflow.
    - name: Log in to the Container registry
      uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: ${{ inputs.user }}
        password: ${{ inputs.pass }}

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

    # Sets the image name and tags for subsequent steps.
    - name: Extract metadata (tags, labels) for Docker
      id: meta
      uses: docker/metadata-action@v5
      with:
        images: ghcr.io/dosbox-staging/${{ inputs.img-name }}
        tags: |
          type=raw,${{ inputs.tag }}
    
    # Builds the docker image using the outputs from
    # the metadata step, then pushes to the registry 
    # in the "log in" step.
    - name: Build and push base Docker image
      uses: docker/build-push-action@v5
      with:
        context: ./packages
        file: ./packages/Dockerfile.debian
        push: true
        build-args: |
          DEB_VERS=${{ inputs.deb-vers }}
          DPKG_ARCH=${{ inputs.arch }}
        platforms: linux/amd64
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}