diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7a3536e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,79 @@ +// Jenkins pipeline mirroring .gitea/workflows/deploy.yml +// Build + lint + optimize + test on every branch; deploy to production on master. +pipeline { + agent { label 'linux' } + + options { timestamps() } + + stages { + stage('Build site') { + steps { + sh ''' + docker run --rm -v "$PWD:/site" -w /site node:22 bash -c ' + npm install -g hexo-cli >/dev/null && + yarn install --frozen-lockfile && + hexo generate && + npx markdownlint-cli2 + ' + ''' + } + } + + stage('Optimize images') { + steps { + sh ''' + cat > /tmp/optimize.sh <<'EOS' +#!/bin/bash +set -eu +apt-get update -qq && apt-get install -y -qq pngquant jpegoptim +find public -type f -name '*.png' -exec sh -c 'pngquant --quality=80-95 --strip --force --skip-if-larger --output "$1" "$1"' _ {} \; +find public -type f \( -name '*.jpg' -o -name '*.jpeg' \) -exec jpegoptim --max=90 --strip-all --threshold=5 -q {} \; +echo "site size after optimization: $(du -sh public | cut -f1)" +EOS + docker run --rm -v "$PWD:/site" -w /site -v /tmp/optimize.sh:/optimize.sh node:22 bash /optimize.sh + ''' + } + } + + stage('Test site') { + steps { + sh ''' + cat > /tmp/smoke.py <<'EOS' +import http.server, socketserver, os, threading, urllib.request +os.chdir("public") +with socketserver.TCPServer(("127.0.0.1", 8080), http.server.SimpleHTTPRequestHandler) as httpd: + threading.Thread(target=httpd.serve_forever, daemon=True).start() + def get(path): + with urllib.request.urlopen(f"http://127.0.0.1:8080{path}") as r: + return r.read().decode() + assert os.path.isfile("index.html"), "missing index.html" + n = sum(len(files) for _, _, files in os.walk(".")) + assert n > 100, f"too few files: {n}" + assert os.path.isfile("css/index.css"), "missing css/index.css" + assert os.path.isfile("js/utils.js"), "missing js/utils.js" + assert "