name: Upload PyTest cache

description: Uploads the pytest cache to S3

inputs:
  cache_dir:
    description: Path to the pytest cache directory, relative to $GITHUB_WORKSPACE. This folder will be zipped and uploaded to S3.
    required: true
  shard:
    description: Shard number for the current job
    required: false
    default: "0"
  sha:
    description: SHA for the commit
    required: true
  test_config:
    description: Name of the test config
    required: false
    default: "default"
  job_identifier:
    description: Text that uniquely identifies a given job type within a workflow. All shards of a job should share the same job identifier.
    required: true

runs:
  using: composite
  steps:
    - uses: nick-fields/retry@v3.0.0
      name: Setup dependencies
      with:
        shell: bash
        timeout_minutes: 5
        max_attempts: 5
        retry_wait_seconds: 30
        command: |
          set -eu
          python3 -m pip install boto3==1.35.42

    - name: Upload the cache
      shell: bash
      env:
        CACHE_DIR: ${{ inputs.cache_dir }}
        JOB_IDENTIFIER: ${{ inputs.job_identifier }}
        SHA: ${{ inputs.sha }}
        TEST_CONFIG: ${{ inputs.test_config }}
        SHARD: ${{ inputs.shard }}
        REPO: ${{ github.repository }}
      run: |
        python3 .github/scripts/pytest_cache.py \
          --upload \
          --cache_dir $GITHUB_WORKSPACE/$CACHE_DIR \
          --pr_identifier $GITHUB_REF \
          --job_identifier $JOB_IDENTIFIER \
          --sha $SHA \
          --test_config $TEST_CONFIG \
          --shard $SHARD \
          --repo $REPO \
          --temp_dir $RUNNER_TEMP \
