Skip to content

Commit 1a1e9ad

Browse files
committed
Workflow: Refactor JS code for getting latest artifact ID
1 parent 4945933 commit 1a1e9ad

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

.github/workflows/build-push.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,24 @@ jobs:
6060
6161
const artifactName = process.env.MAIN_REPORT_ARTIFACT_NAME;
6262
const filteredArtifacts = response.data.artifacts.filter(a => a.name === artifactName);
63+
6364
if(filteredArtifacts.length === 0) {
64-
core.setFailed(`Error: Not able to find artifact with name ${artifactName}`);
65+
return core.setFailed(`Error: Not able to find artifact with name ${artifactName}`);
6566
}
66-
else {
67-
const latestArtifact = filteredArtifacts.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))[0];
68-
console.log(`Success! Found the latest artifact with name ${artifactName}, with artifact id ${latestArtifact.id} | workflow id ${latestArtifact.workflow_run.id}`);
69-
core.setOutput("artifact_id", latestArtifact.id);
70-
core.setOutput("run_id", latestArtifact.workflow_run.id);
7167
72-
let download = await github.rest.actions.downloadArtifact({
73-
owner: owner,
74-
repo: repo,
75-
artifact_id: latestArtifact.id,
76-
archive_format: 'zip',
77-
});
68+
const latestArtifact = filteredArtifacts.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))[0];
69+
console.log(`Success! Found the latest artifact with name ${artifactName}, with artifact id ${latestArtifact.id} | workflow id ${latestArtifact.workflow_run.id}`);
7870
79-
let fs = require('fs');
80-
fs.writeFileSync('./artifact-lighthouse-report-main.zip', Buffer.from(download.data));
81-
}
71+
const download = await github.rest.actions.downloadArtifact({
72+
owner: owner,
73+
repo: repo,
74+
artifact_id: latestArtifact.id,
75+
archive_format: 'zip',
76+
});
77+
78+
const fs = require('fs');
79+
fs.writeFileSync('./artifact-lighthouse-report-main.zip', Buffer.from(download.data));
80+
8281
result-encoding: string
8382
- name: Unzip the artifact
8483
run: |

0 commit comments

Comments
 (0)