Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/lighthouse-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI - Lighthouse

on:
pull_request:
branches:
- main

jobs:
lhci:
runs-on: ubuntu-latest
env:
NODE_OPTIONS: --max-old-space-size=8192
GATSBY_CONCURRENT_DOWNLOAD: 1

steps:
- name: Check for Lighthouse Trigger
id: trigger_check
run: |
if grep -q "Lighthouse Test" <<< "${{ github.event.pull_request.body }}"; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi


- name: Extract and build URLs from PR body paths
id: extract
if: steps.trigger_check.outputs.should_run == 'true'
shell: bash
env:
PR_BODY: ${{ github.event.pull_request.body || '' }}
run: |
echo "$PR_BODY" > pr_body.txt

# A more robust way to read each path and build the ARGS string
ARGS=""
while read -r path; do
# The -n flag ensures we only process non-empty lines
if [ -n "$path" ]; then
clean_path=$(echo "$path" | sed 's/[),.;:]*$//')
full_url="http://localhost:9000$clean_path"
ARGS="$ARGS --collect.url='$full_url'"
fi
done < <(grep -Eo '^/[a-zA-Z0-9/_.-]*$' pr_body.txt || true)

# This part remains the same
if [ -z "$ARGS" ]; then
echo "has_urls=false" >> $GITHUB_OUTPUT
echo "has_localhost=false" >> $GITHUB_OUTPUT
exit 0
fi

echo "ARGS=$ARGS" >> $GITHUB_ENV
echo "has_urls=true" >> $GITHUB_OUTPUT
echo "has_localhost=true" >> $GITHUB_OUTPUT

- name: Checkout code
if: steps.trigger_check.outputs.should_run == 'true' && steps.extract.outputs.has_localhost == 'true'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install dependencies & build
if: steps.trigger_check.outputs.should_run == 'true' && steps.extract.outputs.has_localhost == 'true'
run: |
rm -rf .cache public
npm ci
npm run build

- name: Start static server
if: steps.trigger_check.outputs.should_run == 'true' && steps.extract.outputs.has_localhost == 'true'
shell: bash
run: |
npx http-server ./public -p 9000 --silent &
TIMEOUT=60
COUNT=0
until curl -sSf http://localhost:9000/ >/dev/null; do
sleep 1
COUNT=$((COUNT+1))
if [ $COUNT -ge $TIMEOUT ]; then
echo "Server did not start within timeout"
exit 1
fi
done
echo "Local server ready"

- name: Run Lighthouse CI for supplied URLs
if: steps.trigger_check.outputs.should_run == 'true' && steps.extract.outputs.has_urls == 'true'
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
npm install -g @lhci/[email protected]
if [ -z "${ARGS}" ]; then
echo "No URLs provided. Skipping LHCI."
exit 0
fi
echo "Running LHCI autorun with URLs: $ARGS"
lhci autorun $ARGS
4 changes: 2 additions & 2 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const plugins = [
{
resolve: 'gatsby-plugin-canonical-urls',
options: {
siteUrl: process.env.GATSBY_DEFAULT_SITE_URL,
siteUrl: process.env.GATSBY_DEFAULT_SITE_URL || 'https://cilium.io',
},
},
{
Expand Down Expand Up @@ -281,7 +281,7 @@ module.exports = {
// pathPrefix: "",
siteImage: '/images/social-preview.jpg',
siteLanguage: 'en',
siteUrl: process.env.GATSBY_DEFAULT_SITE_URL,
siteUrl: process.env.GATSBY_DEFAULT_SITE_URL || 'https://cilium.io',
/* author */
authorName: 'cilium',
authorTwitterAccount: '@ciliumproject',
Expand Down
25 changes: 25 additions & 0 deletions lighthouserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
ci: {
collect: {
staticDistDir: './public',
numberOfRuns: 1,
settings: {
emulatedFormFactor: 'Desktop',
throttlingMethod: 'simulate',
},
},

assert: {
assertions: {
'categories:performance': ['warn', { minScore: 0.7 }],
'categories:accessibility': ['warn', { minScore: 0.9 }],
'categories:best-practices': ['warn', { minScore: 0.9 }],
'categories:seo': ['warn', { minScore: 0.9 }],
},
},

upload: {
target: 'temporary-public-storage',
},
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"babel-loader": "^9.2.1",
"classnames": "^2.5.1",
"framer-motion": "^12.12.1",
"gatsby": "^5.14.3",
"gatsby": "^5.14.6",
"gatsby-adapter-netlify": "^1.2.1",
"gatsby-plugin-algolia-search": "^0.5.7",
"gatsby-plugin-canonical-urls": "^5.14.0",
"gatsby-plugin-feed": "^5.14.0",
Expand Down