`actions/upload-artifact@v4` comes with the following [breaking change](https://github.com/actions/upload-artifact?tab=readme-ov-file#breaking-changes): "Due to how Artifacts are created in this new version, it is no longer possible to upload to the same named Artifact multiple times. You must either split the uploads into multiple Artifacts with different names, or only upload once. Otherwise you will encounter an error." Due to that we cannot copy multiple blob report folders into the same artifact name and rely on the action to merge them. Instead, as suggested by their migration guide, we upload each blob report into a uniquely named artifact with prefix `blob-report-` and then download all of them into same directory. This version change also affects how we store pull_request_number.txt into an artifact. Previously we relied on the fact that uploading artifact with the same name would silently override existing one, but now it's an error. To overcome that, we upload PR number file into uniquely named artifacts `pull-request-*` and later extract them into same location with `unzip -n` which will never override existing file, so we end up with single `pull_request_number.txt`. Reference #28800
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@v6
|
|
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 { data } = await github.rest.actions.listWorkflowRunArtifacts({
|
|
...context.repo,
|
|
run_id: context.payload.workflow_run.id
|
|
});
|
|
console.log('total = ', data.total_count);
|
|
const artifacts = data.artifacts.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'
|