-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make reusable action for downloading workflow run artifact (#1308)
- Loading branch information
Showing
2 changed files
with
48 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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: | ||
- run: echo Hello ${{ inputs.who-to-greet }}. | ||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run | ||
- name: 'Download render-test-result 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]; | ||
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: Unzip artifact | ||
run: unzip ${{ inputs.artifact-name }}.zip | ||
|
||
- name: "Check file existence" | ||
uses: andstor/[email protected] | ||
if: ${{ inputs.expect-files }} | ||
with: | ||
fail: true | ||
files: ${{ inputs.expect-files }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters