name: "get cache key for submodule"
description: "Compute a cache key based on git submodule"
inputs:
  submodule:
    description: "Name of submodule"
    default: "tensorflow"
    required: false
  flavor:
    description: "Cache flavor"
    default: "opt"
    required: false
  arch:
    description: "Cache architecture"
    required: true
  extras:
    description: "Extra cache key value"
    default: "0"
    required: false
outputs:
  key:
    description: "Computed cache key name"
    value: ${{ steps.compute_cache_key.outputs.key }}
runs:
  using: "composite"
  steps:
    - id: compute_cache_key
      run: |
        set -xe
        SUBMODULE=${{ inputs.submodule }}
        SHA=$(git submodule status ${SUBMODULE} | sed -e 's/^-//g' -e 's/^+//g' -e 's/^U//g' | awk '{ print $1 }')
        KEY=${SUBMODULE}-${{ inputs.flavor }}_${{ inputs.arch }}_${SHA}_${{ inputs.extras }}
        echo "key=${KEY}" >> $GITHUB_OUTPUT  
      shell: bash
