Restructure pipeline: deps-cache -> check -> lint -> build -> test -> deploy
Hexo-Butterfly/pipeline/head This commit looks good
Hexo-Butterfly/pipeline/head This commit looks good
This commit is contained in:
1 parent
95113316a6
commit
6832dffa97
1 file changed
+53
-16
Vendored
+53
-16
@@ -1,6 +1,7 @@
|
|||||||
// Jenkins pipeline for the Hexo site.
|
// Jenkins pipeline for the Hexo site.
|
||||||
// yarn/npm caches live on the agent and are reused across builds;
|
// Stage flow: dependencies (cached) -> check -> lint -> build -> test -> deploy.
|
||||||
// if the cache goes unused for 7 days the next build resets it.
|
// yarn/npm caches live on the agent and are reused across builds; the cache
|
||||||
|
// is deleted if no build has used it for 7 days, and rebuilt on the next build.
|
||||||
pipeline {
|
pipeline {
|
||||||
agent { label 'linux' }
|
agent { label 'linux' }
|
||||||
|
|
||||||
@@ -11,12 +12,17 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Site cache: refresh or reset (7-day rule)') {
|
stage('Dependencies (cached, 7-day rule)') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
mkdir -p "$SITE_CACHE"
|
mkdir -p "$SITE_CACHE"
|
||||||
docker run --rm -v "$SITE_CACHE:/cache" node:22 bash -c '
|
docker run --rm -v "$PWD:/site" -w /site -v "$SITE_CACHE:/cache" \\
|
||||||
|
-e YARN_CACHE_FOLDER=/cache/yarn \\
|
||||||
|
-e npm_config_prefix=/cache/npm-global \\
|
||||||
|
-e npm_config_cache=/cache/npm-cache \\
|
||||||
|
node:22 bash -c '
|
||||||
set -eu
|
set -eu
|
||||||
|
# 7-day rule: reset the cache if the last build using it is over a week old
|
||||||
if [ -f /cache/last-used ] && [ -z "$(find /cache/last-used -mtime +7 2>/dev/null)" ]; then
|
if [ -f /cache/last-used ] && [ -z "$(find /cache/last-used -mtime +7 2>/dev/null)" ]; then
|
||||||
echo "site cache fresh (last used $(cat /cache/last-used))"
|
echo "site cache fresh (last used $(cat /cache/last-used))"
|
||||||
else
|
else
|
||||||
@@ -29,6 +35,47 @@ pipeline {
|
|||||||
mkdir -p /cache/yarn /cache/npm-global /cache/npm-cache
|
mkdir -p /cache/yarn /cache/npm-global /cache/npm-cache
|
||||||
fi
|
fi
|
||||||
date -u +%Y-%m-%dT%H:%M:%SZ > /cache/last-used
|
date -u +%Y-%m-%dT%H:%M:%SZ > /cache/last-used
|
||||||
|
|
||||||
|
export PATH=/cache/npm-global/bin:$PATH
|
||||||
|
npm install -g hexo-cli >/dev/null
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
echo "dependencies ready (node_modules installed from cache)"
|
||||||
|
'
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Check config files') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
docker run --rm -v "$PWD:/site" -w /site -v "$SITE_CACHE:/cache" \\
|
||||||
|
-e npm_config_prefix=/cache/npm-global \\
|
||||||
|
-e npm_config_cache=/cache/npm-cache \\
|
||||||
|
node:22 bash -c '
|
||||||
|
set -eu
|
||||||
|
export PATH=/cache/npm-global/bin:$PATH
|
||||||
|
for f in _config.yml _config.butterfly.yml; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
npx --no-install js-yaml "$f" > /dev/null
|
||||||
|
echo "$f: valid YAML"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Lint markdown') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
docker run --rm -v "$PWD:/site" -w /site -v "$SITE_CACHE:/cache" \\
|
||||||
|
-e npm_config_prefix=/cache/npm-global \\
|
||||||
|
-e npm_config_cache=/cache/npm-cache \\
|
||||||
|
node:22 bash -c '
|
||||||
|
set -eu
|
||||||
|
export PATH=/cache/npm-global/bin:$PATH
|
||||||
|
npx --no-install markdownlint-cli2
|
||||||
|
echo "markdown lint passed"
|
||||||
'
|
'
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
@@ -38,23 +85,13 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
docker run --rm -v "$PWD:/site" -w /site -v "$SITE_CACHE:/cache" \\
|
docker run --rm -v "$PWD:/site" -w /site -v "$SITE_CACHE:/cache" \\
|
||||||
-e YARN_CACHE_FOLDER=/cache/yarn \\
|
|
||||||
-e npm_config_prefix=/cache/npm-global \\
|
-e npm_config_prefix=/cache/npm-global \\
|
||||||
-e npm_config_cache=/cache/npm-cache \\
|
-e npm_config_cache=/cache/npm-cache \\
|
||||||
node:22 bash -c '
|
node:22 bash -c '
|
||||||
|
set -eu
|
||||||
export PATH=/cache/npm-global/bin:$PATH
|
export PATH=/cache/npm-global/bin:$PATH
|
||||||
npm install -g hexo-cli >/dev/null &&
|
hexo generate
|
||||||
yarn install --frozen-lockfile &&
|
|
||||||
hexo generate &&
|
|
||||||
npx markdownlint-cli2
|
|
||||||
'
|
'
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Optimize images') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
cat > /tmp/optimize.sh <<'EOS'
|
cat > /tmp/optimize.sh <<'EOS'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|||||||
Reference in new issue
Block a user