* The results are paginated by default to return max 30 entries, see
[this
page](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28).
We use
[octakit.paginate](https://octokit.github.io/rest.js/v20#pagination),
wrapped into
[github-script](60a0d83039)
to automatically load all artifacts urls.
* Also bumped github-script to v7
47 lines
1.7 KiB
YAML
47 lines
1.7 KiB
YAML
name: 'Download artifacts'
|
|
description: 'Download artifacts from GitHub'
|
|
inputs:
|
|
namePrefix:
|
|
description: 'Name prefix of the artifacts to download'
|
|
required: true
|
|
type: string
|
|
default: 'blob-report'
|
|
path:
|
|
description: 'Directory with downloaded artifacts'
|
|
required: true
|
|
type: string
|
|
default: '.'
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Create temp downloads dir
|
|
shell: bash
|
|
run: mkdir -p '${{ inputs.path }}/artifacts'
|
|
- name: Download artifacts
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
console.log(`downloading artifacts for workflow_run: ${context.payload.workflow_run.id}`);
|
|
console.log(`workflow_run: ${JSON.stringify(context.payload.workflow_run, null, 2)}`);
|
|
const allArtifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
|
|
...context.repo,
|
|
run_id: context.payload.workflow_run.id
|
|
});
|
|
console.log('total = ', allArtifacts.length);
|
|
const artifacts = allArtifacts.filter(a => a.name.startsWith('${{ inputs.namePrefix }}'));
|
|
const fs = require('fs');
|
|
for (const artifact of artifacts) {
|
|
const result = await github.rest.actions.downloadArtifact({
|
|
...context.repo,
|
|
artifact_id: artifact.id,
|
|
archive_format: 'zip'
|
|
});
|
|
console.log('downloaded artifact', result);
|
|
fs.writeFileSync(`${{ inputs.path }}/artifacts/${artifact.name}.zip`, Buffer.from(result.data));
|
|
}
|
|
- name: Unzip artifacts
|
|
shell: bash
|
|
run: |
|
|
unzip -n '${{ inputs.path }}/artifacts/*.zip' -d ${{ inputs.path }}
|
|
rm -rf '${{ inputs.path }}/artifacts'
|