Skip to content

Commit 1fc1278

Browse files
committed
Workflow: Add logic to get latest artifact of a given name
1 parent b59f2d1 commit 1fc1278

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

.github/workflows/build-push.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ env:
1010
REPO_NAME: "documentation"
1111
FRONT_DOOR_USERNAME: ${{ secrets.FRONT_DOOR_USERNAME }}
1212
FRONT_DOOR_PASSWORD: ${{ secrets.FRONT_DOOR_PASSWORD }}
13-
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
13+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
14+
MAIN_REPORT_ARTIFACT_NAME: "lighthouse-reports-main"
1415

1516
jobs:
1617
deploy-example-site:
@@ -46,10 +47,32 @@ jobs:
4647
REPORT_NAME: "pr"
4748
run: |
4849
node performance/lighthouse-script.js
50+
- name: Retrieve the latest artifact ID for lighthouse report main
51+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
52+
id: fetch-artifact-id
53+
with:
54+
script: |
55+
const { owner, repo } = context.issue;
56+
const response = github.rest.actions.listArtifactsForRepo({
57+
owner,
58+
repo,
59+
});
60+
61+
const artifactName = process.env.MAIN_REPORT_ARTIFACT_NAME;
62+
const filteredArtifacts = artifacts.data.artifacts.filter(a => a.name === artifactName);
63+
if(filteredArtifacts.length === 0) {
64+
core.setFailed(`Error: Not able to find artifact with name ${artifactName}`);
65+
}
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}`);
69+
core.setOutput("artifact_id", latestArtifact.id);
70+
}
71+
result-encoding: string
4972
- name: Download the artifact for main
5073
uses: actions/download-artifact@f44cd7b40bfd40b6aa1cc1b9b5b7bf03d3c67110 # v4.1.0
5174
with:
52-
name: lighthouse-reports-main
75+
artifact-ids: ${{ steps.fetch_artifact.outputs.artifact_id }}
5376
path: ./main-report
5477
- name: Move the main report artifact to same directory as pr report
5578
run: |

0 commit comments

Comments
 (0)