Skip to content

Commit 10955fb

Browse files
authored
Make reusable action for downloading workflow run artifact (#1308)
1 parent 53d061d commit 10955fb

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Download workflow_run artifact'
2+
description: 'Downloads and unzips artifact from workflow that triggered workflow_run'
3+
inputs:
4+
artifact-name:
5+
description: 'Name of artifact'
6+
required: true
7+
expect-files:
8+
description: 'Check for existence of expected files'
9+
required: false
10+
runs:
11+
using: "composite"
12+
steps:
13+
- run: echo Hello ${{ inputs.who-to-greet }}.
14+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
15+
- name: 'Download render-test-result artifact'
16+
uses: actions/github-script@v6
17+
with:
18+
script: |
19+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
run_id: context.payload.workflow_run.id,
23+
});
24+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
25+
return artifact.name == ${{ inputs.artifact-name }}
26+
})[0];
27+
let download = await github.rest.actions.downloadArtifact({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
artifact_id: matchArtifact.id,
31+
archive_format: 'zip',
32+
});
33+
let fs = require('fs');
34+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${{ inputs.artifact-name }}.zip`, Buffer.from(download.data));
35+
36+
- name: Unzip artifact
37+
run: unzip ${{ inputs.artifact-name }}.zip
38+
39+
- name: "Check file existence"
40+
uses: andstor/file-existence-action@v2.0.0
41+
if: ${{ inputs.expect-files }}
42+
with:
43+
fail: true
44+
files: ${{ inputs.expect-files }}

.github/workflows/pr-render-test-result.yml

+4-24
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,18 @@ jobs:
1515
runs-on: ubuntu-22.04
1616
if: github.event.workflow_run.event == 'pull_request'
1717
steps:
18-
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
19-
- name: 'Download render-test-result artifact'
20-
uses: actions/github-script@v6
18+
- uses: .github/actions/download-workflow-run-artifact
2119
with:
22-
script: |
23-
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
24-
owner: context.repo.owner,
25-
repo: context.repo.repo,
26-
run_id: context.payload.workflow_run.id,
27-
});
28-
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
29-
return artifact.name == "render-test-result"
30-
})[0];
31-
let download = await github.rest.actions.downloadArtifact({
32-
owner: context.repo.owner,
33-
repo: context.repo.repo,
34-
artifact_id: matchArtifact.id,
35-
archive_format: 'zip',
36-
});
37-
let fs = require('fs');
38-
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/render-test-result.zip`, Buffer.from(download.data));
39-
20+
artifact-name: render-test-result
21+
expect-files: "./pr_number, metrics/linux-gcc8-release-style.html"
22+
4023
- name: Configure AWS Credentials
4124
uses: aws-actions/configure-aws-credentials@v2
4225
with:
4326
aws-region: us-west-2
4427
role-to-assume: ${{ vars.OIDC_AWS_ROLE_TO_ASSUME }}
4528
role-session-name: ${{ github.run_id }}
4629

47-
- name: 'Unzip render-test-result artifact'
48-
run: unzip render-test-result.zip
49-
5030
- name: Upload render test results to S3
5131
id: upload_render_test_results
5232
run: |

0 commit comments

Comments
 (0)