name: "get cache key for submodule"
description: "Compute a cache key based on git submodule"
inputs:
  extras:
    description: "Extra cache key value"
    required: true
  osarch:
    description: "Override automatic OSARCH value"
    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: |
        JOB=${{ github.job }}
        SUBMODULE=$(echo $JOB | cut -d'-' -f1 | cut -d'_' -f1)
        FLAVOR=$(echo $JOB | cut -d'-' -f1 | cut -d'_' -f2)

        if [ -z "${{ inputs.osarch }}" ]; then
          OSARCH=$(echo $JOB | cut -d'-' -f2)
        else
          OSARCH=${{ inputs.osarch }}
        fi

        SHA=$(git submodule status ${SUBMODULE} | sed -e 's/^-//g' -e 's/^+//g' -e 's/^U//g' | awk '{ print $1 }')

        KEY=${SUBMODULE}-${FLAVOR}_${OSARCH}_${SHA}_${{ inputs.extras }}
        echo "::set-output name=key::${KEY}"
      shell: bash
