name: Push RTI Image to Docker Hub

on:
  push:
    branches:
      - master
  workflow_dispatch:
  workflow_call:

jobs:
  build-and-push:
    runs-on: ubuntu-24.04
    name: Build and push RTI to Docker Hub
    steps:
      - name: Check out lingua-franca repository
        uses: actions/checkout@v3
        with:
          repository: lf-lang/lingua-franca
          submodules: recursive
          fetch-depth: 0
      - name: Look up the current version and export as environment variable
        run: |
          export LF_VERSION=$(cat core/src/main/resources/org/lflang/StringsBundle.properties | sed -n 's/.*VERSION = \(.*\)/\1/p' | tr '[:upper:]' '[:lower:]')
          echo "lf_version=$LF_VERSION"
          echo "lf_version=$LF_VERSION" >> $GITHUB_ENV
      - name: Build and push RTI to Docker Hub
        uses: ./.github/actions/push-rti-docker
        with:
          tag: ${{ env.lf_version }}
          latest: false
          DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
          DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
        if: ${{ endsWith(env.lf_version, '-snapshot') && github.repository_owner == 'lf-lang' }}

      - name: Update latest (released versions only)
        uses: ./.github/actions/push-rti-docker
        with:
          tag: ${{ env.lf_version }}
          latest: true
          DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
          DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
        if: ${{ !endsWith(env.lf_version, '-snapshot') && github.repository_owner == 'lf-lang' }}
