Compare commits
16
Commits
2026.10.09
...
2026.11.13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bb1884151
|
||
|
|
d95d19cd38
|
||
|
|
355688eaa5 | ||
|
|
21cdd8acc4 | ||
|
|
007a257a20 | ||
|
|
f461e7ef16 | ||
|
|
e05e6a34cd | ||
|
|
dc1c2d2766 | ||
|
|
520cf73c13 | ||
|
|
44f539a9dc | ||
|
|
e056c864ed | ||
|
|
aa0468a219 | ||
|
|
6a3e01e127 | ||
|
|
853103d93d | ||
|
|
866cf4ca50 | ||
|
|
41512c340c
|
No files matched your search
@@ -1,169 +0,0 @@
|
||||
name: Build, Scan & Publish Image
|
||||
|
||||
# Publishing a Gitea release (for example with tag 2026.09.25) builds the image,
|
||||
# scans it with Grype (fails on fixable HIGH/CRITICAL findings), and pushes it to
|
||||
# this repository's registry. A release pushes the release tag plus "latest"
|
||||
# (non-prereleases only). A manual run builds and pushes only the tag supplied
|
||||
# in the input.
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Image tag to build and push when run manually
|
||||
required: false
|
||||
default: latest
|
||||
|
||||
concurrency:
|
||||
group: image-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build-scan-push:
|
||||
runs-on: running-man
|
||||
env:
|
||||
REGISTRY: git.sysmd.uk
|
||||
IMAGE: git.sysmd.uk/mdaleo404/kovi
|
||||
COSIGN_VERSION: v3.0.5
|
||||
GRYPE_VERSION: v0.110.0
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Resolve release tag
|
||||
env:
|
||||
EVENT_TAG: ${{ github.event.release.tag_name }}
|
||||
INPUT_TAG: ${{ github.event.inputs.tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${EVENT_TAG:-}"
|
||||
if [ -z "$TAG" ]; then TAG="${INPUT_TAG:-}"; fi
|
||||
if [ -z "$TAG" ]; then TAG="${GITHUB_REF_NAME:-}"; fi
|
||||
if [ -z "$TAG" ]; then TAG="$(git describe --tags --exact-match 2>/dev/null || echo "")"; fi
|
||||
if [ -z "$TAG" ]; then echo "Could not determine a tag for this run." >&2; exit 1; fi
|
||||
SAFE_TAG="${TAG//\//-}"
|
||||
case "$SAFE_TAG" in
|
||||
[A-Za-z0-9_]*) ;;
|
||||
*) SAFE_TAG="v$SAFE_TAG" ;;
|
||||
esac
|
||||
{
|
||||
echo "TAG=$SAFE_TAG"
|
||||
echo "IMAGE_REF=${IMAGE}:${SAFE_TAG}"
|
||||
} >> "$GITHUB_ENV"
|
||||
if [ -n "${EVENT_TAG:-}" ] && [ "${{ github.event.release.prerelease }}" != "true" ]; then
|
||||
echo "PUSH_LATEST=1" >> "$GITHUB_ENV"
|
||||
fi
|
||||
echo "Resolved image reference: ${IMAGE}:${SAFE_TAG}"
|
||||
|
||||
- name: Login to registry
|
||||
run: |
|
||||
echo "$REGISTRY_TOKEN" | docker login "${REGISTRY}" -u "$REGISTRY_USER" --password-stdin
|
||||
env:
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build image
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAGS=(-t "${IMAGE_REF}")
|
||||
if [ "${PUSH_LATEST:-}" = "1" ]; then TAGS+=(-t "${IMAGE}:latest"); fi
|
||||
docker buildx build \
|
||||
--load \
|
||||
--no-cache \
|
||||
--secret id=gitea_token,env=GITEA_TOKEN \
|
||||
"${TAGS[@]}" \
|
||||
.
|
||||
|
||||
- name: Install Cosign
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fLO "https://github.com/sigstore/cosign/releases/download/${COSIGN_VERSION}/cosign-linux-amd64"
|
||||
chmod +x cosign-linux-amd64
|
||||
mv cosign-linux-amd64 /usr/local/bin/cosign
|
||||
|
||||
- name: Install Grype
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
VERSION_NO_V="${GRYPE_VERSION#v}"
|
||||
FILE="grype_${VERSION_NO_V}_linux_amd64.tar.gz"
|
||||
BASE="https://github.com/anchore/grype/releases/download/${GRYPE_VERSION}"
|
||||
|
||||
curl -fLO "${BASE}/${FILE}"
|
||||
curl -fLO "${BASE}/grype_${VERSION_NO_V}_checksums.txt"
|
||||
curl -fLO "${BASE}/grype_${VERSION_NO_V}_checksums.txt.sig"
|
||||
curl -fLO "${BASE}/grype_${VERSION_NO_V}_checksums.txt.pem"
|
||||
|
||||
cosign verify-blob \
|
||||
--signature "grype_${VERSION_NO_V}_checksums.txt.sig" \
|
||||
--certificate "grype_${VERSION_NO_V}_checksums.txt.pem" \
|
||||
--certificate-identity-regexp "https://github.com/anchore/grype" \
|
||||
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
|
||||
"grype_${VERSION_NO_V}_checksums.txt"
|
||||
|
||||
CHECK=$(grep " ${FILE}$" "grype_${VERSION_NO_V}_checksums.txt")
|
||||
[ -n "$CHECK" ] || { echo "Missing checksum"; exit 1; }
|
||||
|
||||
echo "$CHECK" | sha256sum -c -
|
||||
|
||||
tar -xzf "${FILE}"
|
||||
mv grype /usr/local/bin/
|
||||
|
||||
- name: Scan image with Grype
|
||||
id: grype
|
||||
run: |
|
||||
grype "${IMAGE_REF}" -o json > grype.json
|
||||
|
||||
echo "Fixable HIGH/CRITICAL vulnerabilities:"
|
||||
jq -r '
|
||||
.matches[]
|
||||
| select(
|
||||
(
|
||||
.vulnerability.severity == "High" or
|
||||
.vulnerability.severity == "Critical"
|
||||
)
|
||||
and
|
||||
(
|
||||
(.vulnerability.fix.versions | length) > 0
|
||||
)
|
||||
)
|
||||
| "\(.artifact.name)@\(.artifact.version) -> \(.vulnerability.id) [\(.vulnerability.severity)] | fixed: \(.vulnerability.fix.versions[0])"
|
||||
' grype.json
|
||||
|
||||
# Fail the build on fixable HIGH/CRITICAL vulnerabilities.
|
||||
COUNT=$(jq '
|
||||
[
|
||||
.matches[]
|
||||
| select(
|
||||
(
|
||||
.vulnerability.severity == "High" or
|
||||
.vulnerability.severity == "Critical"
|
||||
)
|
||||
and
|
||||
(
|
||||
(.vulnerability.fix.versions | length) > 0
|
||||
)
|
||||
)
|
||||
]
|
||||
| length
|
||||
' grype.json)
|
||||
echo "Fixable HIGH/CRITICAL count: ${COUNT}"
|
||||
if [ "$COUNT" != "0" ]; then
|
||||
echo "::error::Grype found ${COUNT} fixable HIGH/CRITICAL vulnerabilities."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Push image
|
||||
run: |
|
||||
docker push "${IMAGE_REF}"
|
||||
if [ "${PUSH_LATEST:-}" = "1" ]; then docker push "${IMAGE}:latest"; fi
|
||||
@@ -0,0 +1,91 @@
|
||||
name: Build, Scan & Publish Dev
|
||||
|
||||
# Build, scan, and reconcile on push to main and nightly. Publishes a moving
|
||||
# "dev" tag on real pushes only, once the reconciler gate passes.
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
schedule:
|
||||
- cron: "0 3 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: image-main
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build-scan-push:
|
||||
runs-on: running-man
|
||||
env:
|
||||
REGISTRY: git.sysmd.uk
|
||||
IMAGE: git.sysmd.uk/mdaleo404/kovi
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Resolve dev tag
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "IMAGE_REF=${IMAGE}:dev" >> "$GITHUB_ENV"
|
||||
echo "Dev image: ${IMAGE}:dev"
|
||||
|
||||
- name: Login to registry
|
||||
run: |
|
||||
echo "$REGISTRY_TOKEN" | docker login "${REGISTRY}" -u "$REGISTRY_USER" --password-stdin
|
||||
env:
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
docker buildx build --load --no-cache -t "${IMAGE_REF}" .
|
||||
|
||||
- name: Install Grype
|
||||
uses: https://git.sysmd.uk/mdaleo404/actions/install-grype@v1
|
||||
|
||||
- name: Scan image with Grype
|
||||
id: scan
|
||||
continue-on-error: true
|
||||
uses: https://git.sysmd.uk/mdaleo404/actions/scan-image@v1
|
||||
with:
|
||||
image: ${{ env.IMAGE_REF }}
|
||||
fail-on-fixable: 'false'
|
||||
|
||||
- name: Reconcile Grype ignores
|
||||
id: reconcile
|
||||
continue-on-error: true
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.AUTOUPDATE_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"https://git.sysmd.uk/api/v1/repos/Homelab/renovate-runner/raw/scripts/reconcile-grype.sh?ref=main" \
|
||||
-o /tmp/reconcile-grype.sh
|
||||
bash /tmp/reconcile-grype.sh
|
||||
|
||||
- name: Notify Node-RED on vulnerabilities
|
||||
if: steps.reconcile.outcome == 'failure'
|
||||
run: |
|
||||
jq -n --arg repo "${GITHUB_REPOSITORY,,}" '{ repo: $repo }' \
|
||||
| curl -s -X POST https://nodered.sysmd.uk/vulns-alert \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
|
||||
- name: Fail on actionable vulnerabilities
|
||||
if: steps.reconcile.outcome == 'failure'
|
||||
run: exit 1
|
||||
|
||||
- name: Push dev image
|
||||
if: github.event_name != 'schedule' && steps.reconcile.outcome != 'failure'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
docker push "${IMAGE_REF}"
|
||||
@@ -0,0 +1,62 @@
|
||||
name: Publish Release Image
|
||||
|
||||
# Promote the scanned dev image to the release tag (and latest); never rebuilds.
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
concurrency:
|
||||
group: release-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
promote:
|
||||
runs-on: running-man
|
||||
env:
|
||||
REGISTRY: git.sysmd.uk
|
||||
IMAGE: git.sysmd.uk/mdaleo404/kovi
|
||||
steps:
|
||||
- name: Login to registry
|
||||
run: |
|
||||
echo "$REGISTRY_TOKEN" | docker login "${REGISTRY}" -u "$REGISTRY_USER" --password-stdin
|
||||
env:
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Resolve tags
|
||||
env:
|
||||
EVENT_TAG: ${{ github.event.release.tag_name }}
|
||||
PRERELEASE: ${{ github.event.release.prerelease }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${EVENT_TAG:?release tag missing}"
|
||||
{
|
||||
echo "TAG=${TAG}"
|
||||
echo "SOURCE_REF=${IMAGE}:dev"
|
||||
} >> "$GITHUB_ENV"
|
||||
if [ "${PRERELEASE:-}" != "true" ]; then
|
||||
echo "PUSH_LATEST=1" >> "$GITHUB_ENV"
|
||||
fi
|
||||
echo "Promoting ${IMAGE}:dev -> ${IMAGE}:${TAG}"
|
||||
|
||||
- name: Verify dev image version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION="${TAG#v}"
|
||||
IMAGE_VERSION="$(docker run --rm --network none --entrypoint cat "${SOURCE_REF}" /app/package.json | jq -r '.version')"
|
||||
if [ "${IMAGE_VERSION}" != "${VERSION}" ]; then
|
||||
echo "Refusing to release ${TAG}: the dev image reports ${IMAGE_VERSION}." >&2
|
||||
echo "Wait for the main build to publish a fresh dev image, or set package.json to ${VERSION}." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Dev image reports ${IMAGE_VERSION}; promoting to ${TAG}."
|
||||
|
||||
- name: Promote image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAGS=(-t "${IMAGE}:${TAG}")
|
||||
if [ "${PUSH_LATEST:-}" = "1" ]; then TAGS+=(-t "${IMAGE}:latest"); fi
|
||||
docker buildx imagetools create "${TAGS[@]}" "${SOURCE_REF}"
|
||||
@@ -0,0 +1,2 @@
|
||||
data/
|
||||
tests/fixture-statistics.sqlite3
|
||||
@@ -0,0 +1,3 @@
|
||||
# Managed by renovate-runner/scripts/reconcile-grype.sh - do not edit by hand.
|
||||
# Entries are High,Critical findings with a fix that no base image update provides.
|
||||
ignore: []
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM node:22-trixie-slim@sha256:154ba2f4d6fec323d28e4f4bb86bba4677f1223391a1979cf521304e03a98dfa
|
||||
FROM node:22-trixie-slim@sha256:68c76cfad89921b927eae28ba21407475e29d0ce450afcdbe70c1532db042b64
|
||||
|
||||
# kovi does not vendor or copy Calibre code. The container installs Debian's
|
||||
# unmodified Calibre package and calls its fetch-ebook-metadata CLI as a separate
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { cleanText, nowIso, randomId } from './security.mjs';
|
||||
import { info, warn } from './logger.mjs';
|
||||
import { fetchCoverWithCalibre } from './calibre.mjs';
|
||||
|
||||
const VERSION = '2026.09.25';
|
||||
const VERSION = '2026.11.13';
|
||||
const MATCH_THRESHOLD = 0.72;
|
||||
const NETWORK_RETRIES = 2;
|
||||
const COVER_WORKER_CONCURRENCY = Math.max(1, Math.min(4, Number.parseInt(process.env.COVER_WORKER_CONCURRENCY || '2', 10) || 2));
|
||||
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kovi",
|
||||
"version": "2026.09.25",
|
||||
"version": "2026.11.13",
|
||||
"private": true,
|
||||
"license": "GPL-3.0-only",
|
||||
"type": "module",
|
||||
@@ -12,6 +12,8 @@
|
||||
"start": "node server.mjs",
|
||||
"dev": "node --watch server.mjs",
|
||||
"test": "node --test tests/*.test.mjs",
|
||||
"fixture": "node scripts/make-fixture.mjs"
|
||||
"fixture": "node scripts/make-fixture.mjs",
|
||||
"version:check": "node scripts/version.mjs",
|
||||
"version:write": "node scripts/version.mjs --write"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env node
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { readZipEntries } from './zip.mjs';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const PLUGIN_DIR = path.join(ROOT, 'plugins', 'kovi.koplugin');
|
||||
const PLUGIN_ZIP = path.join(ROOT, 'public', 'kovi-plugin.zip');
|
||||
const CONST_FILE = path.join(PLUGIN_DIR, 'const.lua');
|
||||
const META_FILE = path.join(PLUGIN_DIR, '_meta.lua');
|
||||
const SERVER_FILE = path.join(ROOT, 'server.mjs');
|
||||
const COVERS_FILE = path.join(ROOT, 'lib', 'covers.mjs');
|
||||
const PACKAGE_FILE = path.join(ROOT, 'package.json');
|
||||
const CALVER = /^\d{4}\.\d{2}\.\d{2}$/;
|
||||
const PLUGIN_VERSION_PATTERN = /VERSION\s*=\s*"([^"]+)"/;
|
||||
const META_VERSION_PATTERN = /\(v[\d.]+\)/;
|
||||
|
||||
const read = (file) => fs.readFileSync(file, 'utf8');
|
||||
const firstGroup = (source, pattern) => (pattern.exec(source) || [])[1];
|
||||
const zipName = (name) => name.slice(name.indexOf('/') + 1);
|
||||
|
||||
export function versions() {
|
||||
return {
|
||||
app: JSON.parse(read(PACKAGE_FILE)).version,
|
||||
plugin: firstGroup(read(CONST_FILE), PLUGIN_VERSION_PATTERN),
|
||||
};
|
||||
}
|
||||
|
||||
function versionParts(value) {
|
||||
return String(value || '0').split('.').map((part) => Number.parseInt(part, 10) || 0).slice(0, 3);
|
||||
}
|
||||
|
||||
function versionAtLeast(value, minimum) {
|
||||
const a = versionParts(value);
|
||||
const b = versionParts(minimum);
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
if ((a[i] || 0) > (b[i] || 0)) return true;
|
||||
if ((a[i] || 0) < (b[i] || 0)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkZip(problems) {
|
||||
const entries = new Map([...readZipEntries(PLUGIN_ZIP)]
|
||||
.filter(([name]) => !name.endsWith('/'))
|
||||
.map(([name, data]) => [zipName(name), data]));
|
||||
const source = new Map(fs.readdirSync(PLUGIN_DIR)
|
||||
.filter((name) => fs.statSync(path.join(PLUGIN_DIR, name)).isFile())
|
||||
.map((name) => [name, fs.readFileSync(path.join(PLUGIN_DIR, name))]));
|
||||
for (const [name, data] of source) {
|
||||
const packaged = entries.get(name);
|
||||
if (!packaged) problems.push(`public/kovi-plugin.zip is missing ${name}`);
|
||||
else if (!packaged.equals(data)) problems.push(`public/kovi-plugin.zip has a stale ${name}`);
|
||||
}
|
||||
for (const name of entries.keys()) {
|
||||
if (!source.has(name)) problems.push(`public/kovi-plugin.zip contains stale ${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function check() {
|
||||
const problems = [];
|
||||
const { app, plugin } = versions();
|
||||
const server = read(SERVER_FILE);
|
||||
if (!CALVER.test(app || '')) problems.push(`package.json version "${app}" is not CalVer`);
|
||||
if (!CALVER.test(plugin || '')) problems.push(`plugins/kovi.koplugin/const.lua version "${plugin}" is not CalVer`);
|
||||
|
||||
const serverVersion = firstGroup(server, /const VERSION = '([^']+)'/);
|
||||
if (serverVersion !== app) problems.push(`server.mjs VERSION is ${serverVersion}, expected ${app} from package.json`);
|
||||
const coversVersion = firstGroup(read(COVERS_FILE), /const VERSION = '([^']+)'/);
|
||||
if (coversVersion !== app) problems.push(`lib/covers.mjs VERSION is ${coversVersion}, expected ${app} from package.json`);
|
||||
|
||||
if (/const LATEST_PLUGIN_VERSION = ['"]/.test(server)) problems.push('server.mjs must derive LATEST_PLUGIN_VERSION from plugins/kovi.koplugin/const.lua');
|
||||
for (const name of ['MIN_COVER_PLUGIN_VERSION', 'MIN_INCREMENTAL_PLUGIN_VERSION']) {
|
||||
const floor = firstGroup(server, new RegExp(`const ${name} = '([^']+)'`));
|
||||
if (!floor) problems.push(`server.mjs is missing ${name}`);
|
||||
else if (!versionAtLeast(plugin, floor)) problems.push(`${name} (${floor}) is newer than the plugin version (${plugin})`);
|
||||
}
|
||||
|
||||
if (!read(META_FILE).includes(`(v${plugin})`)) problems.push(`plugins/kovi.koplugin/_meta.lua must describe version v${plugin}`);
|
||||
checkZip(problems);
|
||||
return problems;
|
||||
}
|
||||
|
||||
export function write() {
|
||||
const { app, plugin } = versions();
|
||||
const sync = (file, pattern, value) => {
|
||||
const source = read(file);
|
||||
const next = source.replace(pattern, value);
|
||||
if (next !== source) fs.writeFileSync(file, next);
|
||||
};
|
||||
sync(SERVER_FILE, /const VERSION = '[^']+'/, `const VERSION = '${app}'`);
|
||||
sync(COVERS_FILE, /const VERSION = '[^']+'/, `const VERSION = '${app}'`);
|
||||
sync(META_FILE, META_VERSION_PATTERN, `(v${plugin})`);
|
||||
const result = spawnSync('zip', ['-FSr', path.relative(path.join(ROOT, 'plugins'), PLUGIN_ZIP), 'kovi.koplugin'], {
|
||||
cwd: path.join(ROOT, 'plugins'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
if (result.error) throw new Error(`Cannot rebuild public/kovi-plugin.zip: ${result.error.message}`);
|
||||
if (result.status !== 0) throw new Error('zip failed while rebuilding public/kovi-plugin.zip');
|
||||
}
|
||||
|
||||
const cli = process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url;
|
||||
if (cli) {
|
||||
if (process.argv.includes('--write')) write();
|
||||
const problems = check();
|
||||
if (problems.length) {
|
||||
console.error('kovi version check failed:');
|
||||
for (const problem of problems) console.error(` - ${problem}`);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
const { app, plugin } = versions();
|
||||
console.log(`kovi versions OK · app ${app} · plugin ${plugin}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import fs from 'node:fs';
|
||||
import { inflateRawSync } from 'node:zlib';
|
||||
|
||||
const EOCD_SIGNATURE = 0x06054b50;
|
||||
const CENTRAL_SIGNATURE = 0x02014b50;
|
||||
const LOCAL_SIGNATURE = 0x04034b50;
|
||||
const EOCD_SIZE = 22;
|
||||
const MAX_COMMENT_SIZE = 65535;
|
||||
|
||||
// Minimal ZIP reader for the tracked plugin archive: enough to compare entry
|
||||
// names and bytes without adding a dependency or requiring the zip binary.
|
||||
export function readZipEntries(file) {
|
||||
const buf = fs.readFileSync(file);
|
||||
let eocd = -1;
|
||||
for (let i = buf.length - EOCD_SIZE; i >= Math.max(0, buf.length - EOCD_SIZE - MAX_COMMENT_SIZE); i -= 1) {
|
||||
if (buf.readUInt32LE(i) === EOCD_SIGNATURE) { eocd = i; break; }
|
||||
}
|
||||
if (eocd < 0) throw new Error(`Not a ZIP archive: ${file}`);
|
||||
const count = buf.readUInt16LE(eocd + 10);
|
||||
const entries = new Map();
|
||||
let offset = buf.readUInt32LE(eocd + 16);
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
if (buf.readUInt32LE(offset) !== CENTRAL_SIGNATURE) throw new Error(`Corrupt ZIP central directory: ${file}`);
|
||||
const method = buf.readUInt16LE(offset + 10);
|
||||
const compressedSize = buf.readUInt32LE(offset + 20);
|
||||
const nameLength = buf.readUInt16LE(offset + 28);
|
||||
const extraLength = buf.readUInt16LE(offset + 30);
|
||||
const commentLength = buf.readUInt16LE(offset + 32);
|
||||
const localOffset = buf.readUInt32LE(offset + 42);
|
||||
const name = buf.toString('utf8', offset + 46, offset + 46 + nameLength);
|
||||
if (buf.readUInt32LE(localOffset) !== LOCAL_SIGNATURE) throw new Error(`Corrupt ZIP local header for ${name}: ${file}`);
|
||||
const dataStart = localOffset + 30 + buf.readUInt16LE(localOffset + 26) + buf.readUInt16LE(localOffset + 28);
|
||||
const stored = buf.subarray(dataStart, dataStart + compressedSize);
|
||||
if (method !== 0 && method !== 8) throw new Error(`Unsupported ZIP compression for ${name}: ${file}`);
|
||||
entries.set(name, method === 0 ? Buffer.from(stored) : inflateRawSync(stored));
|
||||
offset += 46 + nameLength + extraLength + commentLength;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
+7
-2
@@ -13,11 +13,11 @@ import { json, randomId, cleanText } from './lib/security.mjs';
|
||||
import { info, warn, error as logError } from './lib/logger.mjs';
|
||||
import { createBackupArchive, sendBooksCsv, sendHighlightsMarkdown } from './lib/exports.mjs';
|
||||
|
||||
const VERSION = '2026.09.25';
|
||||
const LATEST_PLUGIN_VERSION = '2026.09.25';
|
||||
const VERSION = '2026.11.13';
|
||||
const MIN_COVER_PLUGIN_VERSION = '2026.09.25';
|
||||
const MIN_INCREMENTAL_PLUGIN_VERSION = '2026.09.25';
|
||||
const ROOT = path.dirname(fileURLToPath(import.meta.url));
|
||||
const LATEST_PLUGIN_VERSION = readPluginVersion(path.join(ROOT, 'plugins', 'kovi.koplugin', 'const.lua'));
|
||||
const DATA_DIR = path.resolve(process.env.DATA_PATH || path.join(ROOT, 'data'));
|
||||
const PUBLIC_DIR = path.join(ROOT, 'public');
|
||||
const UPLOAD_DIR = path.join(DATA_DIR, 'uploads');
|
||||
@@ -41,6 +41,11 @@ const pairAttempts = new Map();
|
||||
let lastPingLogAt = 0;
|
||||
let backupInFlight = false;
|
||||
|
||||
function readPluginVersion(file){
|
||||
const match = /VERSION\s*=\s*"([^"]+)"/.exec(fs.readFileSync(file, 'utf8'));
|
||||
if (!match) throw new Error(`Cannot read the plugin version from ${file}.`);
|
||||
return match[1];
|
||||
}
|
||||
function versionParts(value){return String(value||'0').split('.').map(x=>Number.parseInt(x,10)||0).slice(0,3)}
|
||||
function versionAtLeast(value,minimum){const a=versionParts(value),b=versionParts(minimum);for(let i=0;i<3;i++){if((a[i]||0)>(b[i]||0))return true;if((a[i]||0)<(b[i]||0))return false}return true}
|
||||
function deviceView(d){return {...d,needs_update:!versionAtLeast(d.plugin_version,LATEST_PLUGIN_VERSION),supports_cover_sync:versionAtLeast(d.plugin_version,MIN_COVER_PLUGIN_VERSION),supports_incremental_sync:versionAtLeast(d.plugin_version,MIN_INCREMENTAL_PLUGIN_VERSION),latest_plugin_version:LATEST_PLUGIN_VERSION,min_cover_plugin_version:MIN_COVER_PLUGIN_VERSION,min_incremental_plugin_version:MIN_INCREMENTAL_PLUGIN_VERSION}}
|
||||
|
||||
@@ -45,9 +45,12 @@ test('server detects plugins too old for embedded-cover requests',()=>{
|
||||
assert.match(server,/update_recommended/);
|
||||
});
|
||||
|
||||
test('packaged plugin version is aligned with kovi 2026.09.25',()=>{
|
||||
test('plugin version is declared once and surfaced in its metadata',()=>{
|
||||
const constants=fs.readFileSync(new URL('../plugins/kovi.koplugin/const.lua', import.meta.url),'utf8');
|
||||
assert.match(constants,/2026\.09\.25/);
|
||||
const meta=fs.readFileSync(new URL('../plugins/kovi.koplugin/_meta.lua', import.meta.url),'utf8');
|
||||
const version=/VERSION\s*=\s*"([^"]+)"/.exec(constants)?.[1];
|
||||
assert.match(version||'',/^\d{4}\.\d{2}\.\d{2}$/);
|
||||
assert.ok(meta.includes(`v${version}`));
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { check, versions } from '../scripts/version.mjs';
|
||||
|
||||
test('app and plugin versions stay consistent across sources and the packaged zip', () => {
|
||||
assert.deepEqual(check(), []);
|
||||
});
|
||||
|
||||
test('app and plugin versions are independent CalVer values', () => {
|
||||
const { app, plugin } = versions();
|
||||
assert.match(app, /^\d{4}\.\d{2}\.\d{2}$/);
|
||||
assert.match(plugin, /^\d{4}\.\d{2}\.\d{2}$/);
|
||||
});
|
||||
Reference in new issue
Block a user