name: Build and Push Docker Image
description: Builds a Docker image and pushes it to GitHub Container Registry
inputs:
  app:
    description: Name of the app
    required: true
  token:
    description: GitHub token
    required: true
outputs:
  version:
    description: Version of the app
    value: ${{ steps.get_version.outputs.version }}
runs:
  using: composite
  steps:
    - name: Checkout Repository
      uses: actions/checkout@v4

    - name: Get package.json version
      id: get_version
      run: echo ::set-output name=version::$(node -p "require('./apps/${{ inputs.app }}/package.json').version")
      shell: bash

    - name: Convert repository owner to lowercase
      id: repo
      run: echo "::set-output name=lowercase::$(echo ${{ github.repository_owner }} | awk '{print tolower($0)}')"
      shell: bash

    - name: Build and Push Docker Image
      uses: premid/premid/.github/actions/build-docker@monorepo
      with:
        dockerfile: ./apps/${{ inputs.app }}/Dockerfile
        push: true
        token: ${{ inputs.token }}
        tags: ghcr.io/${{ steps.repo.outputs.lowercase }}/${{ inputs.app }}:${{ steps.get_version.outputs.version }},ghcr.io/${{ steps.repo.outputs.lowercase }}/${{ inputs.app }}:latest
