82 lines · yaml
1name: Unprivileged Download Artifact2description: >-3 Download artifacts from another workflow run without using an access token.4inputs:5 run-id:6 description: >-7 The run-id for the workflow run that you want to download the artifact8 from. If ommitted it will download the most recently created artifact9 from the repo with the artifact-name.10 required: false11 artifact-name:12 desciption: The name of the artifact to download.13 required: true14 15 16outputs:17 filename:18 description: >-19 The filename of the downloaded artifact or the empty string if the20 artifact was not found.21 value: ${{ steps.download-artifact.outputs.filename }}22 artifact-id:23 description: "The id of the artifact being downloaded."24 value: ${{ steps.artifact-url.outputs.id }}25 26 27runs:28 using: "composite"29 steps:30 - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.031 id: artifact-url32 with:33 script: |34 var response;35 if (!"${{ inputs.run-id }}") {36 response = await github.rest.actions.listArtifactsForRepo({37 owner: context.repo.owner,38 repo: context.repo.repo,39 name: "${{ inputs.artifact-name }}"40 })41 } else {42 response = await github.rest.actions.listWorkflowRunArtifacts({43 owner: context.repo.owner,44 repo: context.repo.repo,45 run_id: "${{ inputs.run-id }}",46 name: "${{ inputs.artifact-name }}"47 })48 }49 50 console.log(response)51 52 for (artifact of response.data.artifacts) {53 console.log(artifact);54 }55 56 if (response.data.artifacts.length == 0) {57 console.log("Could not find artifact ${{ inputs.artifact-name }} for workflow run ${{ inputs.run-id }}")58 return;59 }60 61 const url_response = await github.rest.actions.downloadArtifact({62 owner: context.repo.owner,63 repo: context.repo.repo,64 artifact_id: response.data.artifacts[0].id,65 archive_format: "zip"66 })67 68 core.setOutput("url", url_response.url);69 core.setOutput("id", response.data.artifacts[0].id);70 71 - shell: bash72 if: steps.artifact-url.outputs.url != ''73 id: download-artifact74 run: |75 curl -L -o ${{ inputs.artifact-name }}.zip "${{ steps.artifact-url.outputs.url }}"76 echo "filename=${{ inputs.artifact-name }}.zip" >> $GITHUB_OUTPUT77 78 - shell: bash79 if: steps.download-artifact.outputs.filename != ''80 run: |81 unzip ${{ steps.download-artifact.outputs.filename }}82