name: "Spiced Matrix Artifact Retrieval"
description: "Retrieve artifacts from a saved GitHub Actions run"
inputs:
  repository:
    description: repository where spliced was run and artifacts saved to (defaults to running)
    required: false
  days:
    description: number of days to check back (defaults to 2)
    required: true
    default: 2
  token:
    description: GitHub token to use GitHub API (required)
    required: true
  runid:
    description: An optional runid to filter artifact retrieval to
    required: false
  outdir:
    description: name of output directory to save to (defaults to artifacts)
    required: true
    default: artifacts
  branch:
    description: The branch of spack to use (defaults to develop)
    required: true
    default: main
  release:
    description: A spack release to use (if defined, overrides branch)
    required: false
    default: ""
  do_install:
    description: Should spliced be installed first?
    required: false
    default: true  

runs:
  using: "composite"
  steps:
    - name: Set Root Directory
      env:
        ACTION_PATH: ${{ github.action_path }}
      run: ${{ github.action_path }}/scripts/set_root.sh
      shell: bash

    - name: Install Spliced
      env:
        INPUT_BRANCH: ${{ inputs.branch }}
        INPUT_RELEASE: ${{ inputs.release }}
        INPUT_DOINSTALL: ${{ inputs.do_install }}
      run: ${{ env.ACTION_ROOT }}/install/scripts/install.sh
      shell: bash

    - name: Retrieve artifacts
      env:
        INPUT_REPOSITORY: ${{ inputs.repository }}
        GITHUB_REPOSITORY: ${{ github.repository }}
        INPUT_TOKEN: ${{ inputs.token }}
        INPUT_DAYS: ${{ inputs.days }}
        INPUT_RUNID: ${{ inputs.runid }}
        INPUT_OUTDIR: ${{ inputs.outdir }}
        ACTION_PATH: ${{ github.action_path }}
      run: ${{ github.action_path }}/scripts/run.sh
      shell: bash
