Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
56 lines
2.0 KiB
YAML
56 lines
2.0 KiB
YAML
name: 'Download workflow_run artifact'
|
|
description: 'Downloads and unzips artifact from workflow that triggered workflow_run'
|
|
inputs:
|
|
artifact-name:
|
|
description: 'Name of artifact'
|
|
required: true
|
|
expect-files:
|
|
description: 'Check for existence of expected files'
|
|
required: false
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
|
|
- name: Download ${{ inputs.artifact-name }} artifact
|
|
uses: actions/github-script@v6
|
|
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 == "${{ inputs.artifact-name }}"
|
|
})[0];
|
|
if (!matchArtifact) {
|
|
console.log("Could not find artifact '${{ inputs.artifact-name }}'");
|
|
return;
|
|
}
|
|
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(`${process.env.GITHUB_WORKSPACE}/${{ inputs.artifact-name }}.zip`, Buffer.from(download.data));
|
|
|
|
- name: "Check .zip file existence"
|
|
id: zip_exists
|
|
uses: andstor/file-existence-action@v2.0.0
|
|
with:
|
|
files: ${{ inputs.artifact-name }}.zip
|
|
|
|
- name: Unzip artifact
|
|
shell: bash
|
|
if: steps.zip_exists.outputs.files_exists == 'true'
|
|
run: unzip ${{ inputs.artifact-name }}.zip
|
|
|
|
- name: "Check file existence"
|
|
uses: andstor/file-existence-action@v2.0.0
|
|
if: ${{ inputs.expect-files }}
|
|
with:
|
|
fail: true
|
|
files: ${{ inputs.expect-files }}
|