name: Push RTI to Docker Hub
description: Build and push the RTI image to Docker Hub
inputs:
  tag:
    description: 'The tag of the RTI image to build and push'
    required: true
    default: 'latest'
  DOCKERHUB_USERNAME:
    description: 'The username to log in to Docker Hub'
    required: true
  DOCKERHUB_TOKEN:
    description: 'The token to log in to Docker Hub'
    required: true
  latest:
    description: 'Also push as latest tag if true'
    default: 'false'
runs:
  using: "composite"
  steps:
    - name: Login to Docker Hub
      uses: docker/login-action@v3
      with:
        username: ${{ inputs.DOCKERHUB_USERNAME }}
        password: ${{ inputs.DOCKERHUB_TOKEN }}
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v3
    - name: Check out lingua-franca repository
      uses: actions/checkout@v3
      with:
        submodules: recursive
        fetch-depth: 0
    - name: Build and push
      uses: docker/build-push-action@v6
      with:
        file: ./core/src/main/resources/lib/c/reactor-c/core/federated/RTI/rti.Dockerfile
        context: ./core/src/main/resources/lib/c/reactor-c
        platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/riscv64
        push: true
        tags: lflang/rti:${{ inputs.tag }}
      if: ${{ inputs.latest == 'false' }}
    - name: Build and push as latest
      uses: docker/build-push-action@v6
      with:
        file: ./core/src/main/resources/lib/c/reactor-c/core/federated/RTI/rti.Dockerfile
        context: ./core/src/main/resources/lib/c/reactor-c
        platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/riscv64
        push: true
        tags: lflang/rti:${{ inputs.tag }}, lflang/rti:latest
      if: ${{ inputs.latest == 'true' }}
