name: unity-get-product-name
description: "Get the correct Unity product name from a provided project."
inputs:
  projectPath:
    description: "Path to the Unity project."
    required: true
    default: "."
outputs:
  name:
    description: "Unity product name."
    value: ${{ steps.getProductName.outputs.productName }}
  nameShort:
    description: "Unity product name without spaces."
    value: ${{ steps.getProductName.outputs.productNameShort }}
runs:
  using: "composite"
  steps:
  - name: "Get Unity project name."
    id: getProductName
    run: |
      PRODUCT_KEY="productName"
      PRODUCT_FILE="ProjectSettings/ProjectSettings.asset"
      PRODUCT_FILE_PATH="${{ inputs.projectPath }}/$PRODUCT_FILE"

      PRODUCT=$(grep -w $PRODUCT_KEY $PRODUCT_FILE_PATH | cut -d ':' -f2 | xargs)
      PRODUCT_SHORT=$(echo "$PRODUCT" | tr -d ' ')

      echo "name=$PRODUCT" >> "$GITHUB_OUTPUT"
      echo "nameShort=$PRODUCT_SHORT" >> "$GITHUB_OUTPUT"
      cat "$GITHUB_OUTPUT"
    shell: bash
