generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 5
Add lighthouse to build workflow #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0942918
Workflow: Add lighthouse to build
lamATnginx ba8e30d
Lighthouse: Move to performance folder
lamATnginx 5c1cad6
Lighthouse: Add readme
lamATnginx b9e3e1a
Workflow: Fix needs
lamATnginx 1e7b286
Chore: Fixed CI install
lamATnginx ca7a642
Chore: Merge branch 'main' into add-lighthouse
lamATnginx fb8b4f2
Lighthouse: Updated script
lamATnginx f3c5af2
Lighthouse: Add workflow to create the report artifact on push main
lamATnginx e3935b4
Workflow: Resolve issue with download-artifact@v3 being deprecated
lamATnginx f375934
Workflow: Add floor value check
lamATnginx ffb2030
Chore: Merge branch 'main' into add-lighthouse
lamATnginx acbf7f4
Workflows: Made artifact naming better
lamATnginx 33fb1d7
Security: Pinning dep versions
lamATnginx 78634ac
Workflow: Moved pull request query pagination to variables
lamATnginx 39cf303
Dep: Updated performance package lock
lamATnginx 5d8175e
Workflow: Fixed SHA for download artifact
lamATnginx b59f2d1
Lighthouse: Added error message to sign in function
lamATnginx 1fc1278
Workflow: Add logic to get latest artifact of a given name
lamATnginx c5b0116
Lighthouse: Fixed wait for signing in
lamATnginx 6103889
Workflow: Fixed undefined bug with artifact id fetching
lamATnginx 350a0fe
Workflow: Fixed mv command from path
lamATnginx 3ceef09
Workflow: Update download-artifact to v5.0.0
lamATnginx 4c59709
Workflow: Add workflow id
lamATnginx 1cfb785
Workflow: Use GH API to download lh report artifact
lamATnginx e5193ec
Workflow: Fixed moving the downloaded artifact command
lamATnginx e98c229
Workflow: Fixed floor value
lamATnginx 4945933
Workflow: Add frontdoor credentials to lh
lamATnginx 1a1e9ad
Workflow: Refactor JS code for getting latest artifact ID
lamATnginx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Update lighthouse report artifact for main branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
env: | ||
OWNER: nginxinc | ||
REPO: nginx-hugo-theme | ||
FRONT_DOOR_USERNAME: ${{ secrets.FRONT_DOOR_USERNAME }} | ||
FRONT_DOOR_PASSWORD: ${{ secrets.FRONT_DOOR_PASSWORD }} | ||
jobs: | ||
generate-lighthouse-report: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
with: | ||
ref: ${{ github.event.workflow_run.head_branch }} | ||
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | ||
with: | ||
node-version: 18 | ||
- name: Installing packages | ||
run: cd performance && npm ci | ||
- name: Get PR number being merged | ||
env: | ||
PAGE: 1 | ||
PER_PAGE: 10 | ||
run: | | ||
RESPONSE=$(curl -L \ | ||
-X GET \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
-s "https://api.github.com/repos/${{ env.OWNER }}/${{ env.REPO }}/pulls?state=closed&direction=desc&page=${{ env.PAGE }}&per_page=${{ env.PER_PAGE }}") | ||
LATEST_PR_NUMBER=$(echo "$RESPONSE" | jq -r '.[] | select(.merged_at != null) | .number' | head -1) | ||
echo "GITHUB_PR_NUMBER=$LATEST_PR_NUMBER" >> $GITHUB_ENV | ||
- name: Generating lighthouse reports for main... | ||
env: | ||
REPORT_NAME: "main" | ||
GITHUB_PR_NUMBER: ${{ env.GITHUB_PR_NUMBER }} | ||
run: | | ||
node performance/lighthouse-script.js | ||
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 | ||
with: | ||
name: lighthouse-reports-main | ||
path: lighthouse-reports/main-report.json | ||
retention-days: 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ exampleSite/hugo | |
|
||
# Biome | ||
biome.rb | ||
|
||
# Local Lighthouse artifacts | ||
*/lighthouse-reports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Important Information | ||
|
||
This folder is only to be run in the CI/CD system. Should not be ran locally! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const puppeteer = require('puppeteer'); | ||
const fs = require('fs'); | ||
|
||
const PORT = 8041; | ||
const REPORT_NAME = process.env.REPORT_NAME; | ||
const PR_NUMBER = process.env.GITHUB_PR_NUMBER; | ||
const OUTPUT_DIR = './lighthouse-reports'; | ||
|
||
const signIntoFrontDoor = async (browser, env) => { | ||
const page = await browser.newPage(); | ||
try { | ||
await page.authenticate({ | ||
username: process.env.FRONT_DOOR_USERNAME, | ||
password: process.env.FRONT_DOOR_PASSWORD, | ||
}); | ||
await page.goto(env['url']); | ||
await page.waitForSelector('.grid-container'); | ||
console.log('Logged in...'); | ||
await page.close(); | ||
} catch (error) { | ||
console.log('Unable to log in or not needed...', error); | ||
} | ||
}; | ||
|
||
const generateLighthouseReport = async (env) => { | ||
const OUTPUT_FILE = `${env['title']}-report.json`; | ||
const lighthouse = (await import('lighthouse')).default; | ||
lamATnginx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log(`Running Lighthouse for ${env['title']}...`); | ||
const result = await lighthouse(env['url'], { port: PORT }); | ||
fs.writeFileSync(`${OUTPUT_DIR}/${OUTPUT_FILE}`, result.report); | ||
console.log(`Generated report for ${env['title']}...`); | ||
}; | ||
|
||
const launchBrowser = async () => { | ||
return await puppeteer.launch({ | ||
args: [`--remote-debugging-port=${PORT}`], | ||
headless: true, | ||
}); | ||
}; | ||
|
||
(async () => { | ||
const browser = await launchBrowser(); | ||
if (!fs.existsSync(OUTPUT_DIR)) { | ||
fs.mkdirSync(OUTPUT_DIR); | ||
} | ||
|
||
const environment = { | ||
title: `${REPORT_NAME}`, | ||
url: `https://frontdoor-test-docs.nginx.com/previews/nginx-hugo-theme/${PR_NUMBER}/`, | ||
}; | ||
|
||
console.log(`Running on ${environment.url}...`); | ||
await signIntoFrontDoor(browser, environment); | ||
await generateLighthouseReport(environment); | ||
|
||
browser.close(); | ||
})(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.