name: 'Save Caches'
description: 'Save ccache, depends sources, and built depends caches'
inputs:
  provider:
    description: 'The cache provider to use'
    required: true
runs:
  using: 'composite'
  steps:
    - name: debug cache hit inputs
      shell: bash
      run: |
        echo "depends sources direct cache hit to primary key: ${{ env.depends-sources-cache-hit }}"
        echo "depends built direct cache hit to primary key: ${{ env.depends-built-cache-hit }}"
        echo "previous releases direct cache hit to primary key: ${{ env.previous-releases-cache-hit }}"

    - name: Save Ccache cache
      uses: ./.github/actions/cache/save/internal
      if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) }}
      with:
        path: ${{ env.CCACHE_DIR }}
        key: ccache-${{ env.CONTAINER_NAME }}-${{ github.run_id }}
        provider: ${{ inputs.provider }}

    - name: Save depends sources cache
      uses: ./.github/actions/cache/save/internal
      if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) && (env.depends-sources-cache-hit != 'true') }}
      with:
        path: ${{ env.SOURCES_PATH }}
        key: depends-sources-${{ env.CONTAINER_NAME }}-${{ env.DEPENDS_HASH }}
        provider: ${{ inputs.provider }}

    - name: Save built depends cache
      uses: ./.github/actions/cache/save/internal
      if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) && (env.depends-built-cache-hit != 'true' )}}
      with:
        path: ${{ env.BASE_CACHE }}
        key: depends-built-${{ env.CONTAINER_NAME }}-${{ env.DEPENDS_HASH }}
        provider: ${{ inputs.provider }}

    - name: Save previous releases cache
      uses: ./.github/actions/cache/save/internal
      if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) && (env.previous-releases-cache-hit != 'true' )}}
      with:
        path: ${{ env.PREVIOUS_RELEASES_DIR }}
        key: previous-releases-${{ env.CONTAINER_NAME }}-${{ env.PREVIOUS_RELEASES_HASH }}
        provider: ${{ inputs.provider }}
