name: Docker build and publish

permissions:
  contents: read
  actions: read
  packages: write

on:
  workflow_call:
    inputs:
      commit_tag:
        required: true
        type: string
      develop_tag:
        required: true
        type: string
      push_image:
        required: false
        type: boolean
        default: false
      coordinator_changed:
        required: true
        type: string
      postman_changed:
        required: true
        type: string
      prover_changed:
        required: true
        type: string
      transaction_exclusion_api_changed:
        required: true
        type: string
      coordinator_image_tagged:
        required: true
        type: string
      prover_image_tagged:
        required: true
        type: string
      postman_image_tagged:
        required: true
        type: string
      transaction_exclusion_api_image_tagged:
        required: true
        type: string
    secrets:
      DOCKERHUB_USERNAME:
        required: false
      DOCKERHUB_TOKEN:
        required: false

jobs:
  coordinator:
    uses: ./.github/workflows/coordinator-build-and-publish.yml
    if: ${{ always() && (inputs.coordinator_changed == 'true' || inputs.coordinator_image_tagged != 'true') }}
    with:
      commit_tag: ${{ inputs.commit_tag }}
      develop_tag: ${{ inputs.develop_tag }}
      image_name: consensys/linea-coordinator
      push_image: ${{ inputs.push_image }}
    secrets: inherit

  prover:
    uses: ./.github/workflows/prover-build-and-publish.yml
    if: ${{ always() && (inputs.prover_changed == 'true' || inputs.prover_image_tagged != 'true') }}
    with:
      commit_tag: ${{ inputs.commit_tag }}
      develop_tag: ${{ inputs.develop_tag }}
      image_name: consensys/linea-prover
      push_image: ${{ inputs.push_image }}
    secrets: inherit

  postman:
    uses: ./.github/workflows/postman-build-and-publish.yml
    if: ${{ always() && (inputs.postman_changed == 'true' || inputs.postman_image_tagged != 'true') }}
    with:
      commit_tag: ${{ inputs.commit_tag }}
      develop_tag: ${{ inputs.develop_tag }}
      image_name: consensys/linea-postman
      push_image: ${{ inputs.push_image }}
    secrets: inherit

  transaction_exclusion_api:
    uses: ./.github/workflows/transaction-exclusion-api-build-and-publish.yml
    if: ${{ always() && (inputs.transaction_exclusion_api_changed == 'true' || inputs.transaction_exclusion_api_image_tagged != 'true') }}
    with:
      commit_tag: ${{ inputs.commit_tag }}
      develop_tag: ${{ inputs.develop_tag }}
      image_name: consensys/linea-transaction-exclusion-api
      push_image: ${{ inputs.push_image }}
    secrets: inherit
