Skip to content

Commit 76e1b58

Browse files
Add compatibility with upload-artifact v4 (#9330)
Refs 5af984a
1 parent c5b23cd commit 76e1b58

File tree

2 files changed

+45
-51
lines changed

2 files changed

+45
-51
lines changed

.github/workflows/primer_comment.yaml

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,40 @@ jobs:
6363
run_id: ${{ github.event.workflow_run.id }},
6464
});
6565
66-
// Get 'main' output
67-
const [matchArtifactWorkflowMain] = artifacts_workflow.data.artifacts.filter((artifact) =>
68-
artifact.name == "primer_output_main");
69-
const downloadOne = await github.rest.actions.downloadArtifact({
70-
owner: context.repo.owner,
71-
repo: context.repo.repo,
72-
artifact_id: matchArtifactWorkflowMain.id,
73-
archive_format: "zip",
74-
});
75-
fs.writeFileSync("primer_main_output.zip", Buffer.from(downloadOne.data));
66+
// Get 'main' and 'PR' outputs and PR number
67+
const artifacts = artifacts_workflow.data.artifacts.filter((artifact) =>
68+
artifact.name.startsWith(`primer_output_main_${process.env.DEFAULT_PYTHON}`)
69+
|| artifact.name.startsWith(`primer_output_pr_${process.env.DEFAULT_PYTHON}`)
70+
|| artifact.name === 'pr_number'
71+
);
72+
for (const artifact of artifacts) {
73+
const downloaded = await github.rest.actions.downloadArtifact({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
artifact_id: artifact.id,
77+
archive_format: "zip",
78+
});
79+
fs.writeFileSync(`${artifact.name}.zip`, Buffer.from(downloaded.data));
80+
}
7681
77-
// Get PR output
78-
const [matchArtifactWorkflowPR] = artifacts_workflow.data.artifacts.filter((artifact) =>
79-
artifact.name == "primer_output_pr");
80-
const downloadTwo = await github.rest.actions.downloadArtifact({
81-
owner: context.repo.owner,
82-
repo: context.repo.repo,
83-
artifact_id: matchArtifactWorkflowPR.id,
84-
archive_format: "zip",
85-
});
86-
fs.writeFileSync("primer_pr_output.zip", Buffer.from(downloadTwo.data));
87-
88-
// Get PR number
89-
const [matchArtifactWorkflowNumber] = artifacts_workflow.data.artifacts.filter((artifact) =>
90-
artifact.name == "pr_number");
91-
const downloadThree = await github.rest.actions.downloadArtifact({
92-
owner: context.repo.owner,
93-
repo: context.repo.repo,
94-
artifact_id: matchArtifactWorkflowNumber.id,
95-
archive_format: "zip",
96-
});
97-
fs.writeFileSync("primer_pr_number.zip", Buffer.from(downloadThree.data));
98-
- run: unzip primer_main_output.zip
99-
- run: unzip primer_pr_output.zip
100-
- run: unzip primer_pr_number.zip
82+
- name: Unzip outputs
83+
run: |
84+
unzip primer_output_main_${{ env.DEFAULT_PYTHON }}_batch0.zip
85+
unzip primer_output_main_${{ env.DEFAULT_PYTHON }}_batch1.zip
86+
unzip primer_output_main_${{ env.DEFAULT_PYTHON }}_batch2.zip
87+
unzip primer_output_main_${{ env.DEFAULT_PYTHON }}_batch3.zip
88+
unzip primer_output_pr_${{ env.DEFAULT_PYTHON }}_batch0.zip
89+
unzip primer_output_pr_${{ env.DEFAULT_PYTHON }}_batch1.zip
90+
unzip primer_output_pr_${{ env.DEFAULT_PYTHON }}_batch2.zip
91+
unzip primer_output_pr_${{ env.DEFAULT_PYTHON }}_batch3.zip
92+
unzip pr_number.zip
10193
- name: Compare outputs
10294
run: |
10395
. venv/bin/activate
10496
python tests/primer/__main__.py compare \
10597
--commit=${{ github.event.workflow_run.head_sha }} \
106-
--base-file=output_${{ steps.python.outputs.python-version }}_main_BATCHIDX.txt \
107-
--new-file=output_${{ steps.python.outputs.python-version }}_pr_BATCHIDX.txt \
98+
--base-file=output_${{ matrix.python-version }}_main_BATCHIDX.txt \
99+
--new-file=output_${{ matrix.python-version }}_pr_BATCHIDX.txt \
108100
--batches=4
109101
- name: Post comment
110102
id: post-comment

.github/workflows/primer_run_pr.yaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,13 @@ jobs:
7777
- name: Download last 'main' run info
7878
id: download-main-run
7979
uses: actions/github-script@v7.0.1
80+
env:
81+
COMMIT_STRING_ARTIFACT: primer_commitstring_${{ matrix.python-version }}
82+
OUTPUT_ARTIFACT:
83+
primer_output_main_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}
8084
with:
8185
script: |
86+
const { COMMIT_STRING_ARTIFACT, OUTPUT_ARTIFACT } = process.env
8287
// Download 'main' pylint output
8388
const fs = require('fs');
8489
const runs = await github.rest.actions.listWorkflowRuns({
@@ -100,32 +105,33 @@ jobs:
100105
101106
// Get commitstring
102107
const [matchArtifactMain] = artifacts_main.data.artifacts.filter((artifact) =>
103-
artifact.name == "primer_commitstring");
108+
artifact.name === COMMIT_STRING_ARTIFACT);
104109
const downloadWorkflow = await github.rest.actions.downloadArtifact({
105110
owner: context.repo.owner,
106111
repo: context.repo.repo,
107112
artifact_id: matchArtifactMain.id,
108113
archive_format: "zip",
109114
});
110-
fs.writeFileSync("primer_commitstring.zip", Buffer.from(downloadWorkflow.data));
115+
fs.writeFileSync(`${COMMIT_STRING_ARTIFACT}.zip`, Buffer.from(downloadWorkflow.data));
111116
112117
// Get output
113118
const [matchArtifactMainOutput] = artifacts_main.data.artifacts.filter((artifact) =>
114-
artifact.name == "primer_output");
119+
artifact.name === OUTPUT_ARTIFACT);
115120
const downloadWorkflowTwo = await github.rest.actions.downloadArtifact({
116121
owner: context.repo.owner,
117122
repo: context.repo.repo,
118123
artifact_id: matchArtifactMainOutput.id,
119124
archive_format: "zip",
120125
});
121-
fs.writeFileSync("primer_output_main.zip", Buffer.from(downloadWorkflowTwo.data));
126+
fs.writeFileSync(`${OUTPUT_ARTIFACT}.zip`, Buffer.from(downloadWorkflowTwo.data));
122127
return lastRunMain.head_sha;
123128
- name: Copy and unzip the commit string
124129
run: |
125-
unzip primer_commitstring.zip
130+
unzip primer_commitstring_${{ matrix.python-version }}.zip
126131
cp commit_string_${{ matrix.python-version }}.txt tests/.pylint_primer_tests/commit_string_${{ matrix.python-version }}.txt
127132
- name: Unzip the output of 'main'
128-
run: unzip primer_output_main.zip
133+
run: |
134+
unzip primer_output_main_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}.zip
129135
- name: Get commit string
130136
id: commitstring
131137
run: |
@@ -175,20 +181,16 @@ jobs:
175181
uses: actions/upload-artifact@v4.0.0
176182
with:
177183
name:
178-
primer_output_pr_${{ steps.python.outputs.python-version }}_batch${{
179-
matrix.batchIdx }}
184+
primer_output_pr_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}
180185
path:
181-
tests/.pylint_primer_tests/output_${{ steps.python.outputs.python-version
182-
}}_pr_batch${{ matrix.batchIdx }}.txt
186+
tests/.pylint_primer_tests/output_${{ matrix.python-version }}_pr_batch${{
187+
matrix.batchIdx }}.txt
183188
- name: Upload output of 'main'
184189
uses: actions/upload-artifact@v4.0.0
185190
with:
186191
name:
187-
primer_output_main_${{ steps.python.outputs.python-version }}_batch${{
188-
matrix.batchIdx }}
189-
path:
190-
output_${{ steps.python.outputs.python-version }}_main_batch${{
191-
matrix.batchIdx }}.txt
192+
primer_output_main_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}
193+
path: output_${{ matrix.python-version }}_main_batch${{ matrix.batchIdx }}.txt
192194

193195
# Save PR number so we know which PR to comment on
194196
- name: Save PR number

0 commit comments

Comments
 (0)