chore: add jenkins support with htmlhint and lighthouse support
Some checks failed
jenkins-ci Build failed
6
.htmlhintrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"attr-value-double-quotes": false,
|
||||||
|
"tag-pair": true,
|
||||||
|
"id-unique": true,
|
||||||
|
"tagname-lowercase": false
|
||||||
|
}
|
||||||
24
.lighthouserc.cjs
Normal 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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
121
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
environment {
|
||||||
|
GITEA_REPO_PATH = "lucas/site-veloboomboom"
|
||||||
|
GITEA_API_URL = "https://gitea.lucasroyer.fr/api/v1"
|
||||||
|
DOCKER_HOST = "unix:///run/user/1001/docker.sock"
|
||||||
|
|
||||||
|
TOOLBOX_PATH ="/home/lucas/services/static-sites/static-toolbox"
|
||||||
|
SOURCE_DIR = "html"
|
||||||
|
DEPLOY_PATH = "/home/lucas/services/static-sites/site-veloboomboom/html-prod"
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Check toolbox') {
|
||||||
|
steps {
|
||||||
|
sh """
|
||||||
|
if ! docker image inspect static-toolbox >/dev/null 2>&1; then
|
||||||
|
echo "Missing toolbox, rebuild using Docker socket..."
|
||||||
|
# On crée l'image à la volée car Jenkins ne voit pas le script 'build'
|
||||||
|
echo "FROM node:25-alpine\nRUN npm install -g htmlhint\nWORKDIR /apps\nENTRYPOINT [\"htmlhint\"]" | docker build -t static-toolbox -
|
||||||
|
fi
|
||||||
|
"""
|
||||||
|
// sh """
|
||||||
|
// if ! docker image inspect static-toolbox >/dev/null 2>&1; then
|
||||||
|
// echo "Missing toolbox, rebuild..."
|
||||||
|
// ${env.TOOLBOX_PATH}/build
|
||||||
|
// fi
|
||||||
|
// """
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Lint HTML') {
|
||||||
|
steps {
|
||||||
|
echo "Check HTML files..."
|
||||||
|
sh "docker run --rm --volumes-from jenkins -w \$(pwd) static-toolbox '${env.SOURCE_DIR}/**/*.html' --config .htmlhintrc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Lighthouse Audit') {
|
||||||
|
steps {
|
||||||
|
echo "Prepare Lighthouse audit..."
|
||||||
|
|
||||||
|
// Safe creation
|
||||||
|
sh "docker rm -f lighthouse-audit || true"
|
||||||
|
|
||||||
|
sh """
|
||||||
|
docker run --name lighthouse-audit \
|
||||||
|
--volumes-from jenkins \
|
||||||
|
-w \$(pwd) \
|
||||||
|
--user "0:0" \
|
||||||
|
-v /home/lucas/.npm-cache:/root/.npm \
|
||||||
|
-e CHROME_PATH=/usr/bin/chromium-browser \
|
||||||
|
--entrypoint "npx" \
|
||||||
|
zenika/alpine-chrome:latest \
|
||||||
|
--prefer-offline @lhci/cli@0.13.0 autorun --config=./.lighthouserc.cjs
|
||||||
|
"""
|
||||||
|
|
||||||
|
// Inject data from tmp-dist and config to audit container
|
||||||
|
sh "docker cp ./${env.SOURCE_DIR}/. lighthouse-audit:/app/dist/"
|
||||||
|
sh "docker cp .lighthouserc.cjs lighthouse-audit:/app/dist/audit-config.cjs"
|
||||||
|
|
||||||
|
// Now run
|
||||||
|
echo "Running Lighthouse audit..."
|
||||||
|
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') {
|
||||||
|
steps {
|
||||||
|
echo "Deploy new site..."
|
||||||
|
sh "mkdir -p ${env.DEPLOY_PATH}"
|
||||||
|
|
||||||
|
h "rsync -avz --delete ${env.SOURCE_DIR}/ ${env.DEPLOY_PATH}/"
|
||||||
|
// Update caddy-reverse-proxy cache
|
||||||
|
sh "docker exec caddy-reverse-proxy caddy reload --config /etc/caddy/Caddyfile"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
echo "Publish Lighthouse audit..."
|
||||||
|
publishHTML([
|
||||||
|
allowMissing: true,
|
||||||
|
alwaysLinkToLastBuild: true,
|
||||||
|
keepAll: false,
|
||||||
|
reportDir: '.lighthouseci',
|
||||||
|
reportFiles: '*.html',
|
||||||
|
reportName: 'Lighthouse Report'
|
||||||
|
])
|
||||||
|
script {
|
||||||
|
echo "Waiting for Gitea to be online..."
|
||||||
|
|
||||||
|
echo "Send Gitea check..."
|
||||||
|
// Get and store SHA
|
||||||
|
def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||||
|
|
||||||
|
// Convert from Jenkins to Gitea API
|
||||||
|
def buildState = (currentBuild.currentResult == 'SUCCESS') ? 'success' : 'failure'
|
||||||
|
def buildDesc = (currentBuild.currentResult == 'SUCCESS') ? 'Build successful' : 'Build failed'
|
||||||
|
|
||||||
|
// Send it to Gitea API with secret 'gitea-token'
|
||||||
|
withCredentials([string(credentialsId: 'gitea-token', variable: 'GITEA_TOKEN')]) {
|
||||||
|
// Use \$TOKEN to avoid jenkins to print token in logs
|
||||||
|
sh """
|
||||||
|
curl -f -X POST "${GITEA_API_URL}/repos/${GITEA_REPO_PATH}/statuses/${commitSha}" \
|
||||||
|
-H "Authorization: token \$GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"state": "${buildState}", "target_url": "${env.BUILD_URL}", "description": "${buildDesc}", "context": "jenkins-ci"}'
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "Clean unused image"
|
||||||
|
sh "docker image prune -f"
|
||||||
|
}
|
||||||
|
success { echo "Success !" }
|
||||||
|
failure { echo "Failed." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 434 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 130 KiB |