88env :
99 REPO_OWNER : " nginx"
1010 REPO_NAME : " documentation"
11+ FRONT_DOOR_USERNAME : ${{ secrets.FRONT_DOOR_USERNAME }}
12+ FRONT_DOOR_PASSWORD : ${{ secrets.FRONT_DOOR_PASSWORD }}
13+ GITHUB_PR_NUMBER : ${{ github.event.pull_request.number }}
14+ MAIN_REPORT_ARTIFACT_NAME : " lighthouse-reports-main"
1115
1216jobs :
1317 deploy-example-site :
2428 auto_deploy_env : " prod"
2529 secrets :
2630 AZURE_CREDENTIALS : ${{secrets.AZURE_CREDENTIALS_DOCS}}
27- AZURE_KEY_VAULT : ${{secrets.AZURE_KEY_VAULT_DOCS}}
31+ AZURE_KEY_VAULT : ${{secrets.AZURE_KEY_VAULT_DOCS}}
32+ lighthouseci :
33+ if : github.event.pull_request
34+ needs : deploy-example-site
35+ runs-on : ubuntu-22.04
36+ steps :
37+ - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
38+ with :
39+ ref : ${{ github.event.workflow_run.head_branch }}
40+ - uses : actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
41+ with :
42+ node-version : 22
43+ - name : Installing packages
44+ run : cd performance && npm ci
45+ - name : Generating lighthouse reports for PR...
46+ env :
47+ REPORT_NAME : " pr"
48+ run : |
49+ 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 = await github.rest.actions.listArtifactsForRepo({
57+ owner,
58+ repo,
59+ });
60+
61+ const artifactName = process.env.MAIN_REPORT_ARTIFACT_NAME;
62+ const filteredArtifacts = response.data.artifacts.filter(a => a.name === artifactName);
63+
64+ if(filteredArtifacts.length === 0) {
65+ return core.setFailed(`Error: Not able to find artifact with name ${artifactName}`);
66+ }
67+
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}`);
70+
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+
81+ result-encoding : string
82+ - name : Unzip the artifact
83+ run : |
84+ unzip ./artifact-lighthouse-report-main.zip
85+ ls -al
86+ - name : Move the main report artifact to same directory as pr report
87+ run : |
88+ mv main-report.json ./lighthouse-reports
89+ - name : Compare the artifacts for negative differences in performance
90+ continue-on-error : true
91+ run : |
92+ FIELDS=("performance" "accessibility")
93+ TOLERANCE=0.05
94+ FLOOR_VALUE=0.90
95+ for FIELD in "${FIELDS[@]}"; do
96+ PR_VALUE=$(cat lighthouse-reports/pr-report.json | jq -r ".categories.$FIELD.score")
97+ MAIN_VALUE=$(cat lighthouse-reports/main-report.json | jq -r ".categories.$FIELD.score")
98+ echo "$FIELD: PR - $PR_VALUE | Main - $MAIN_VALUE"
99+
100+ if (( $(echo "$PR_VALUE < $FLOOR_VALUE" | bc -l) )); then
101+ echo "Error: $FIELD score in PR ($PR_VALUE) is less than accepted value ($FLOOR_VALUE)"
102+ exit 1
103+ fi
104+
105+ if [ $FIELD = "performance" ]; then
106+ LOWER_BOUND=$(echo "$MAIN_VALUE - $TOLERANCE" | bc)
107+ UPPER_BOUND=$(echo "$MAIN_VALUE + $TOLERANCE" | bc)
108+ if (( $(echo "$PR_VALUE < $LOWER_BOUND" | bc -l) || $(echo "$PR_VALUE > $UPPER_BOUND" | bc -l) )); then
109+ echo "Error: $FIELD score in PR ($PR_VALUE) is less than in MAIN ($MAIN_VALUE)"
110+ exit 1
111+ fi
112+ else
113+ if (( $(echo "$PR_VALUE < $MAIN_VALUE" | bc -l) )); then
114+ echo "Error: $FIELD score in PR ($PR_VALUE) is less than in MAIN ($MAIN_VALUE)"
115+ exit 1
116+ fi
117+ fi
118+ done
119+ - uses : actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
120+ if : ${{ !cancelled() }}
121+ with :
122+ name : lighthouse-reports-pr
123+ path : lighthouse-reports/pr-report.json
124+ retention-days : 3
0 commit comments