Skip to content

Commit

Permalink
chore(ci): set up Lighthouse auditing in CI
Browse files Browse the repository at this point in the history
For now, this just hits the main pages
  • Loading branch information
Restioson committed Oct 28, 2024
1 parent ef47fd0 commit a7748de
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .env.lhci
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5'
DEBUG=''
DB_HOST=localhost
ALLOWED_HOSTS=localhost
DB_PORT=5432
DB_NAME=term_db
DB_USER=sadilar
DB_PASSWORD=sadilar
LOGGING_FILE=/home/runner/work/term_platform/term_platform/app/debug.log
LOGGING_HANDLERS_LEVEL=INFO
LOGGING_LOGGERS_LEVEL=INFO
LOGGING_LOGGERS_DJANGO_LEVEL=INFO
TESTING_DIR=/home/runner/work/term_platform/term_platform/app/general/tests/files/
43 changes: 43 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,46 @@ jobs:
run: |
cd app/
python manage.py check
lighthouse:
runs-on: ubuntu-latest # operating system your code will run on
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: sadilar
POSTGRES_PASSWORD: sadilar
POSTGRES_DB: term_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
sudo apt-get install -y gettext
npm install -g @lhci/[email protected]
- name: Setup LHCI env
run: cp .env.lhci app/.env
- name: Run Lighthouse
run: cd app && lhci autorun
- name: Archive Lighthouse results
if: always() # Ensure results are uploaded on failure too
uses: actions/upload-artifact@v4
with:
name: lighthouse-report
path: app/.lighthouseci/
include-hidden-files: true
- name: Archive Django logs
if: always() # Ensure logs are uploaded on failure too
uses: actions/upload-artifact@v4
with:
name: django-logs
path: app/debug.log
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ app/media/
/logging/
/pdf_uploads/
/pdf_upload_completed/

# Generated Lighthouse CI artifacts
.lighthouseci/
31 changes: 31 additions & 0 deletions app/lighthouserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
ci: {
collect: {
// We don't care about variable page performance metrics in CI - just static asserts
numberOfRuns: 1,
startServerCommand: "../entrypoint.sh",
url: [
"http://localhost:8000",
"http://localhost:8000/search/",
"http://localhost:8000/institutions/",
"http://localhost:8000/projects/",
"http://localhost:8000/documents/",
"http://localhost:8000/languages/",
"http://localhost:8000/subjects/"
]
},
assert: {
"preset": "lighthouse:recommended",
"assertions": {
// Gunicorn doesn't do this, but the reverse proxy in front of it does
"uses-text-compression": false,

// We don't think these are worth worrying about for now
"unminified-javascript": false,
"unused-css-rules": false,
"unminified-css": false,
"render-blocking-resources": false,
}
}
}
}

0 comments on commit a7748de

Please sign in to comment.