name: DownloadArtifacts
description: 'Downloads and unarchives artifacts for a workflow that runs on workflow_run so that it can use its data'
runs:
  using: "composite"
  steps:
    - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
      with:
        script: |
          let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
             owner: context.repo.owner,
             repo: context.repo.repo,
             run_id: context.payload.workflow_run.id,
          });
          let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
            return artifact.name == "artifacts"
          })[0];
          let download = await github.rest.actions.downloadArtifact({
             owner: context.repo.owner,
             repo: context.repo.repo,
             artifact_id: matchArtifact.id,
             archive_format: 'zip',
          });
          let fs = require('fs');
          fs.writeFileSync(`/tmp/artifacts.zip`, Buffer.from(download.data));
    - run: |
        mkdir -p /tmp/artifacts
        unzip /tmp/artifacts.zip -d /tmp/artifacts
      shell: bash
    - run: |
        echo "Downloaded artifacts:"
        ls -ablh /tmp/artifacts
      shell: bash
