From a7748ded79b0d34d560139e6d32f88afacb302a7 Mon Sep 17 00:00:00 2001 From: Restioson Date: Fri, 18 Oct 2024 15:55:16 +0200 Subject: [PATCH] chore(ci): set up Lighthouse auditing in CI For now, this just hits the main pages --- .env.lhci | 13 +++++++++++ .github/workflows/testing.yml | 43 +++++++++++++++++++++++++++++++++++ .gitignore | 3 +++ app/lighthouserc.js | 31 +++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 .env.lhci create mode 100644 app/lighthouserc.js diff --git a/.env.lhci b/.env.lhci new file mode 100644 index 00000000..512e3854 --- /dev/null +++ b/.env.lhci @@ -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/ diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 24341673..98fa7a1b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -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/cli@0.14.x + - 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 diff --git a/.gitignore b/.gitignore index 168936e7..cfb3489d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ app/media/ /logging/ /pdf_uploads/ /pdf_upload_completed/ + +# Generated Lighthouse CI artifacts +.lighthouseci/ diff --git a/app/lighthouserc.js b/app/lighthouserc.js new file mode 100644 index 00000000..682cd36a --- /dev/null +++ b/app/lighthouserc.js @@ -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, + } + } + } +}