Skip to content

Commit 562d911

Browse files
[Github] Make unprivileged-download-artifact download multiple artifacts
This is designed to allow a workflow (e.g., premerge) upload comments across multiple jobs. Subsequent PRs will wire this up within the issue-write workflow to support reading comments from multiple files. Reviewers: tstellar, cmtice Reviewed By: cmtice Pull Request: llvm/llvm-project#170216
1 parent 8f6e95e commit 562d911

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

.github/workflows/test-unprivileged-download-artifact.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ jobs:
2121
if: github.repository_owner == 'llvm'
2222
runs-on: ubuntu-24.04
2323
steps:
24-
- name: Create Test File
24+
- name: Create Test Files
2525
run: |
26-
echo "test" > comment
27-
- name: Upload Test File
26+
echo "foo" > comment1
27+
echo "bar" > comment2
28+
- name: Upload Test File 1
2829
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
2930
with:
30-
name: workflow-args
31+
name: artifact-name-1
3132
path: |
32-
comment
33+
comment1
34+
- name: Upload Test File 2
35+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
36+
with:
37+
name: artifact-name-2
38+
path: |
39+
comment2
40+
3341

3442
test-download:
3543
name: Test Unprivileged Download Artifact
@@ -47,8 +55,10 @@ jobs:
4755
id: download-artifact
4856
with:
4957
run-id: ${{ github.run_id }}
50-
artifact-name: workflow-args
58+
artifact-name: artifact-name-
5159
- name: Assert That Contents are the Same
5260
run: |
53-
cat comment
54-
[[ "$(cat comment)" == "test" ]]
61+
cat comment1
62+
[[ "$(cat comment1)" == "foo" ]]
63+
cat comment2
64+
[[ "$(cat comment2)" == "bar" ]]

.github/workflows/unprivileged-download-artifact/action.yml

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ outputs:
1919
The filename of the downloaded artifact or the empty string if the
2020
artifact was not found.
2121
value: ${{ steps.download-artifact.outputs.filename }}
22-
artifact-id:
22+
artifact-ids:
2323
description: "The id of the artifact being downloaded."
24-
value: ${{ steps.artifact-url.outputs.id }}
24+
value: ${{ steps.artifact-url.outputs.ids }}
2525

2626

2727
runs:
@@ -36,46 +36,67 @@ runs:
3636
response = await github.rest.actions.listArtifactsForRepo({
3737
owner: context.repo.owner,
3838
repo: context.repo.repo,
39-
name: "${{ inputs.artifact-name }}"
4039
})
4140
} else {
4241
response = await github.rest.actions.listWorkflowRunArtifacts({
4342
owner: context.repo.owner,
4443
repo: context.repo.repo,
4544
run_id: "${{ inputs.run-id }}",
46-
name: "${{ inputs.artifact-name }}"
4745
})
4846
}
4947
5048
console.log(response)
5149
50+
artifacts_to_download = []
5251
for (artifact of response.data.artifacts) {
52+
if (artifact.name.startsWith("${{ inputs.artifact-name }}")) {
53+
artifacts_to_download.push(artifact)
54+
}
55+
}
56+
57+
for (artifact of artifacts_to_download) {
5358
console.log(artifact);
5459
}
5560
56-
if (response.data.artifacts.length == 0) {
57-
console.log("Could not find artifact ${{ inputs.artifact-name }} for workflow run ${{ inputs.run-id }}")
61+
if (artifacts_to_download.length == 0) {
62+
console.log("Could not find artifacts starting with name ${{ inputs.artifact-name }} for workflow run ${{ inputs.run-id }}")
5863
return;
5964
}
6065
61-
const url_response = await github.rest.actions.downloadArtifact({
62-
owner: context.repo.owner,
63-
repo: context.repo.repo,
64-
artifact_id: response.data.artifacts[0].id,
65-
archive_format: "zip"
66-
})
66+
artifact_ids = []
67+
artifact_urls = []
68+
artifact_names = []
69+
for (artifact_to_download of artifacts_to_download) {
70+
const url_response = await github.rest.actions.downloadArtifact({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
artifact_id: artifact_to_download.id,
74+
archive_format: "zip"
75+
})
76+
77+
artifact_ids.push(artifact_to_download.id)
78+
artifact_urls.push('"' + url_response.url + '"')
79+
artifact_names.push('"' + artifact_to_download.name + '"')
80+
}
6781
68-
core.setOutput("url", url_response.url);
69-
core.setOutput("id", response.data.artifacts[0].id);
82+
core.setOutput("urls", artifact_urls.join(" "));
83+
core.setOutput("ids", artifact_ids.join(" "));
84+
core.setOutput("names", artifact_names.join(" "));
7085
7186
- shell: bash
72-
if: steps.artifact-url.outputs.url != ''
87+
if: steps.artifact-url.outputs.urls != ''
7388
id: download-artifact
7489
run: |
75-
curl -L -o ${{ inputs.artifact-name }}.zip "${{ steps.artifact-url.outputs.url }}"
76-
echo "filename=${{ inputs.artifact-name }}.zip" >> $GITHUB_OUTPUT
90+
artifact_urls=(${{ steps.artifact-url.outputs.urls }})
91+
artifact_names=(${{ steps.artifact-url.outputs.names }})
92+
for i in "${!artifact_urls[@]}"; do
93+
curl -L -o "${artifact_names[$i]}.zip" "${artifact_urls[$i]}"
94+
done
7795
7896
- shell: bash
79-
if: steps.download-artifact.outputs.filename != ''
97+
if: steps.artifact-url.outputs.names != ''
8098
run: |
81-
unzip ${{ steps.download-artifact.outputs.filename }}
99+
artifact_names=(${{ steps.artifact-url.outputs.names }})
100+
for name in "${artifact_names[@]}"; do
101+
unzip "${name}.zip"
102+
done

0 commit comments

Comments
 (0)