feat(ci): add automated Lighthouse audit pipeline
All checks were successful
Portfolio/pipeline/head This commit looks good

This commit is contained in:
2026-01-12 18:18:49 +01:00
parent 4d1099d563
commit d20909032f
15 changed files with 2308 additions and 19 deletions

View File

@@ -1 +1,4 @@
NODE_VERSION=24
CADDY_VERSION=2.10.2 CADDY_VERSION=2.10.2
LHCI_VERSION=0.15.x
ZENIKA_VERSION=124-with-node

7
.gitignore vendored
View File

@@ -5,6 +5,7 @@ dist/
# dependencies # dependencies
node_modules/ node_modules/
.pnpm-store/
# logs # logs
npm-debug.log* npm-debug.log*
@@ -22,3 +23,9 @@ pnpm-debug.log*
# jetbrains setting folder # jetbrains setting folder
.idea/ .idea/
# vscode
.vscode/
# Lighthouse CI reports
.lighthouseci/

1
.husky/commit-msg Normal file
View File

@@ -0,0 +1 @@
pnpm exec commitlint --edit "$1"

2
.husky/pre-commit Normal file
View File

@@ -0,0 +1,2 @@
pnpm run lint
pnpm run check

24
.lighthouserc.cjs Normal file
View File

@@ -0,0 +1,24 @@
module.exports = {
ci: {
collect: {
staticDistDir: '/app/dist',
settings: {
chromeFlags: '--no-sandbox --disable-setuid-sandbox --headless=new --disable-gpu --disable-dev-shm-usage',
targets: ['filesystem'],
},
numberOfRuns: 1
},
assert: {
assertions: {
'categories:performance': ['error', {minScore: 0.9}],
'categories:accessibility': ['error', {minScore: 0.9}],
'categories:best-practices': ['error', {minScore: 0.9}],
'categories:seo': ['error', {minScore: 0.9}],
},
},
upload: {
target: 'filesystem',
outputDir: './.lighthouseci', // C'est ici que Jenkins ira chercher les fichiers
},
},
};

View File

@@ -1,7 +1,8 @@
ARG NODE_VERSION
ARG CADDY_VERSION ARG CADDY_VERSION
# --- BUILD --- # --- BUILD ---
FROM node:24-alpine AS build FROM node:${NODE_VERSION}-alpine AS build
RUN corepack enable && corepack prepare pnpm@latest --activate RUN corepack enable && corepack prepare pnpm@latest --activate
ENV ASTRO_TELEMETRY_DISABLED=1 ENV ASTRO_TELEMETRY_DISABLED=1
@@ -10,10 +11,19 @@ WORKDIR /app
# Copy depedencies # Copy depedencies
COPY package.json pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
# Copy all and build # Install pnpm with cache
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
PNPM_HOME="/pnpm" pnpm install --frozen-lockfile
# Copy all
COPY . . COPY . .
# Check files
RUN pnpm run lint
RUN pnpm run check
# Build
RUN pnpm build RUN pnpm build
# --- DEPLOY --- # --- DEPLOY ---

43
Jenkinsfile vendored
View File

@@ -2,6 +2,7 @@ pipeline {
agent any agent any
environment { environment {
DOCKER_HOST = "unix:///var/run/docker.sock" DOCKER_HOST = "unix:///var/run/docker.sock"
APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
} }
stages { stages {
stage('Build') { stage('Build') {
@@ -9,12 +10,41 @@ pipeline {
// Get Caddy version // Get Caddy version
sh "cp .env.dist .env" sh "cp .env.dist .env"
// Push portfolio version // Push portfolio version
sh "echo '\nPORTFOLIO_VERSION=${env.BRANCH_NAME}-${env.BUILD_NUMBER}' >> .env" sh "echo '\nPORTFOLIO_VERSION=${env.APP_VERSION}' >> .env"
echo "Building new portfolio version..." echo "Building new portfolio version..."
sh "docker compose build" sh "docker compose build"
} }
} }
stage('Lighthouse Audit') {
steps {
// Create volumes but no run with safety
sh "docker rm -f audit-tmp lighthouse-audit || true"
sh "docker compose --profile audit create --no-build --remove-orphans lighthouse-audit"
// Extract astro data from temp container to tmp-dist folder
sh "docker create --name audit-tmp portfolio:${env.APP_VERSION}"
sh "mkdir -p ./tmp-dist"
sh "docker cp audit-tmp:/usr/share/caddy/. ./tmp-dist"
sh "docker rm -f audit-tmp"
// Inject data from tmp-dist and config to audit container
sh "docker cp ./tmp-dist/. lighthouse-audit:/app/dist/"
sh "docker cp .lighthouserc.cjs lighthouse-audit:/app/dist/audit-config.cjs"
sh "rm -rf ./tmp-dist"
// Now run
sh "docker start -a lighthouse-audit"
// Get reports
sh "mkdir -p ./.lighthouseci"
sh "docker cp lighthouse-audit:/app/.lighthouseci/. ./.lighthouseci/"
// Clean
sh "docker rm -f lighthouse-audit"
}
}
stage('Deploy') { stage('Deploy') {
// Deploy only master branch // Deploy only master branch
when { when {
@@ -35,7 +65,16 @@ pipeline {
} }
post { post {
always { always {
echo "Clean unused image..." echo "Publish Lighthouse audit..."
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: false,
reportDir: '.lighthouseci',
reportFiles: '*.html',
reportName: 'Lighthouse Report'
])
echo "Clean unused image"
sh "docker image prune -f" sh "docker image prune -f"
} }
success { echo "Success !" } success { echo "Success !" }

1
commitlint.config.js Normal file
View File

@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };

View File

@@ -3,6 +3,7 @@ services:
build: build:
context: . context: .
args: args:
- NODE_VERSION=${NODE_VERSION}
- CADDY_VERSION=${CADDY_VERSION} - CADDY_VERSION=${CADDY_VERSION}
image: portfolio:${PORTFOLIO_VERSION} image: portfolio:${PORTFOLIO_VERSION}
container_name: portfolio container_name: portfolio
@@ -10,6 +11,26 @@ services:
networks: networks:
- reverse-proxy - reverse-proxy
lighthouse-audit:
profiles:
- audit
image: zenika/alpine-chrome:${ZENIKA_VERSION}
container_name: lighthouse-audit
user: "0:0"
volumes:
- audit_dist:/app/dist
- audit_reports:/app/.lighthouseci
- npm_cache:/root/.npm
environment:
- CHROME_PATH=/usr/bin/chromium-browser
working_dir: /app
command: npx --prefer-offline @lhci/cli@${LHCI_VERSION} autorun --config=/app/dist/audit-config.cjs
volumes:
audit_dist:
audit_reports:
npm_cache:
networks: networks:
reverse-proxy: reverse-proxy:
external: true external: true

24
eslint.config.mjs Normal file
View File

@@ -0,0 +1,24 @@
import eslintPluginAstro from 'eslint-plugin-astro';
import tsParser from '@typescript-eslint/parser';
export default [
// Configuration pour les fichiers Astro
...eslintPluginAstro.configs.recommended,
{
files: ["**/*.astro"],
languageOptions: {
parser: eslintPluginAstro.parser,
parserOptions: {
parser: tsParser,
extraFileExtensions: [".astro"],
},
},
rules: {
// Tes règles personnalisées ici
},
},
// On ignore le dossier de build
{
ignores: ["dist/*", ".astro/*"]
}
];

28
local-lighthouse.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# Clean old audits and containers
rm -rf ./.lighthouseci
docker rm -f lighthouse-audit || true
# Load env file and avoid warning for unused portofolio version
if [ -f .env.dist ]; then
export $(grep -v '^#' .env.dist | xargs)
fi
export PORTFOLIO_VERSION="local-audit"
# Create container but no start
docker compose --profile audit create --no-build --remove-orphans lighthouse-audit
# Inject data and config to container
docker cp ./dist/. lighthouse-audit:/app/dist/
docker cp .lighthouserc.cjs lighthouse-audit:/app/dist/audit-config.cjs
# Now run
docker start -a lighthouse-audit
# Get reports
mkdir -p ./.lighthouseci
docker cp lighthouse-audit:/app/.lighthouseci/. ./.lighthouseci/
# Clean container
docker rm -f lighthouse-audit

View File

@@ -6,13 +6,34 @@
"dev": "astro dev", "dev": "astro dev",
"build": "astro build", "build": "astro build",
"preview": "astro preview", "preview": "astro preview",
"astro": "astro" "astro": "astro",
"lint": "eslint .",
"check": "astro check",
"prepare": "husky"
}, },
"dependencies": { "dependencies": {
"@astrojs/check": "^0.9.6",
"@astrojs/mdx": "^4.3.13", "@astrojs/mdx": "^4.3.13",
"@astrojs/rss": "^4.0.14", "@astrojs/rss": "^4.0.14",
"@astrojs/sitemap": "^3.6.0", "@astrojs/sitemap": "^3.6.0",
"astro": "^5.16.6", "astro": "^5.16.6",
"sharp": "^0.34.3" "sharp": "^0.34.3"
},
"devDependencies": {
"@commitlint/cli": "^20.3.1",
"@commitlint/config-conventional": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^8.52.0",
"@typescript-eslint/parser": "^8.52.0",
"astro-eslint-parser": "^1.2.2",
"eslint": "^9.39.2",
"eslint-plugin-astro": "^1.5.0",
"husky": "^9.1.7",
"typescript": "^5.9.3"
},
"pnpm": {
"onlyBuiltDependencies": [
"esbuild",
"sharp"
]
} }
} }

2126
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

3
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,3 @@
ignoredBuiltDependencies:
- esbuild
- sharp

View File

@@ -1,6 +1,5 @@
{ {
"extends": "astro/tsconfigs/strict", "extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"], "exclude": ["dist"],
"compilerOptions": { "compilerOptions": {
"strictNullChecks": true "strictNullChecks": true