name: "ccache-clear"
description: "Delete all GitHub Actions caches matching a key prefix"
inputs:
  key:
    description: "Cache key prefix to match and delete"
    required: true

runs:
  using: "composite"
  steps:
    - name: Clear caches
      shell: bash
      run: |
        CACHES=$(gh cache list --key "ccache-${{ inputs.key }}" --json id,key --jq '.[] | "\(.id) \(.key)"' 2>/dev/null)
        if [ -z "$CACHES" ]; then
          echo "No caches found with key prefix: ${{ inputs.key }}"
          exit 0
        fi
        while read -r id key; do
          echo "Deleting cache: $id ($key)"
          gh cache delete "$id"
        done <<< "$CACHES"
