From ca70b6184417835a3e4e93287f9b45eacbc1d121 Mon Sep 17 00:00:00 2001 From: Miles Ward Date: Thu, 10 Sep 2026 17:04:16 -0400 Subject: [PATCH] Build npm next too; release generator with upstream notes + provenance; tags cleanup - CI plan: candidates are npm latest AND next (release candidates), plus an optional workflow_dispatch 'version' input for any exact version. This is what was holding back 0.1.5-rc.2 (published as next, not latest). - Upstream dsh-v* tags are no longer mirrored into this repo (deleted the existing ones); master stays an exact branch mirror and every release links to its upstream tag. This repo's tags are now exclusively v. - Dockerfile: build-provenance labels (org.opencontainers.image.revision / .created, dev.milesward.ci-run) so releases cite the commit and CI run that actually built the image instead of whatever HEAD is at publish time. - Releases: shell template replaced by .gitea/scripts/publish-releases.js, run on the node:22 base image (no runner deps). It pulls the upstream GitHub release's English notes, adds version-dependent caveats (launch token from 0.1.2, Session format V3 from 0.1.5), image facts and Unraid deploy steps. Existing v* tags re-pointed to 2d033c3 (the commit that built those images); their releases are regenerated in this format. - README: dynamic badges (shields Gitea release, Gitea workflow status), 0.1.5-rc.2 row, pipeline/tag-namespace docs updated. Co-Authored-By: Claude Fable 5 --- .gitea/scripts/publish-releases.js | 267 +++++++++++++++++++++++++++++ .gitea/workflows/sync-upstream.yml | 151 ++++++---------- Dockerfile | 10 +- README.md | 42 +++-- 4 files changed, 354 insertions(+), 116 deletions(-) create mode 100644 .gitea/scripts/publish-releases.js diff --git a/.gitea/scripts/publish-releases.js b/.gitea/scripts/publish-releases.js new file mode 100644 index 0000000000..881a2306d2 --- /dev/null +++ b/.gitea/scripts/publish-releases.js @@ -0,0 +1,267 @@ +// Publish a `v` git tag and Gitea release for every container image +// tag in the registry that has no release yet. Idempotent; safe to run every +// CI cycle. Runs on plain Node 22 (the image base) with no dependencies: +// docker run --rm -i -e ... node:22-bookworm-slim node - < publish-releases.js +// +// Env: GITEA (default https://gitea.milesward.dev), OWNER, REPO (owner/name), +// IMAGE (owner/name in the registry), GITEA_TOKEN (repo write), +// REG_TOKEN (read:package), MAIN_SHA, RUN_NUMBER, DRY_RUN=1 (print only). +// +// Provenance: the release points at the image's org.opencontainers.image.revision +// label (the main commit CI built from). Images built before that label existed +// fall back to a pre-existing tag's commit, then to MAIN_SHA — and say so. + +'use strict'; + +const env = (k, d) => { + const v = process.env[k]; + if (v !== undefined && v !== '') return v; + if (d !== undefined) return d; + throw new Error(`missing env ${k}`); +}; + +const GITEA = env('GITEA', 'https://gitea.milesward.dev').replace(/\/$/, ''); +const OWNER = env('OWNER'); +const REPO = env('REPO'); +const IMAGE = env('IMAGE'); +const GITEA_TOKEN = env('GITEA_TOKEN'); +const REG_TOKEN = env('REG_TOKEN'); +const MAIN_SHA = env('MAIN_SHA'); +const RUN_NUMBER = env('RUN_NUMBER', ''); +const DRY_RUN = process.env.DRY_RUN === '1'; +const REGISTRY = new URL(GITEA).host; +const UPSTREAM = 'deepseek-ai/deepseek-harness'; +const UA = 'deepseek-harness-release-bot/1.0'; + +const MANIFEST_ACCEPT = [ + 'application/vnd.docker.distribution.manifest.v2+json', + 'application/vnd.oci.image.manifest.v1+json', +].join(','); + +async function gitea(method, path, body) { + const res = await fetch(`${GITEA}/api/v1${path}`, { + method, + headers: { + Authorization: `token ${GITEA_TOKEN}`, + 'Content-Type': 'application/json', + 'User-Agent': UA, + }, + body: body === undefined ? undefined : JSON.stringify(body), + }); + const text = await res.text(); + let json = null; + try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON error body */ } + return { status: res.status, json, text }; +} + +async function registry(path, accept) { + const auth = Buffer.from(`${OWNER}:${REG_TOKEN}`).toString('base64'); + return fetch(`https://${REGISTRY}/v2/${IMAGE}/${path}`, { + headers: { Authorization: `Basic ${auth}`, Accept: accept, 'User-Agent': UA }, + }); +} + +// --- versions ------------------------------------------------------------- + +/** Sort key for "0.1.5-rc.2" / "0.1.5-alpha.1" / "0.1.1-rc.2-r57". */ +function versionKey(tag) { + const m = /^(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d+))?(?:-r(\d+))?$/.exec(tag); + if (!m) return [Infinity]; + const pre = { alpha: 0, beta: 1, rc: 2 }[m[4]] ?? 3; + return [+m[1], +m[2], +m[3], pre, +(m[5] ?? 0), +(m[6] ?? 0)]; +} +const compareVersions = (a, b) => { + const ka = versionKey(a), kb = versionKey(b); + for (let i = 0; i < Math.max(ka.length, kb.length); i++) { + const d = (ka[i] ?? 0) - (kb[i] ?? 0); + if (d) return d; + } + return 0; +}; +const dshVersionOf = (tag) => tag.replace(/-r\d+$/, ''); +const isRevision = (tag) => /-r\d+$/.test(tag); +const atLeast = (ver, target) => compareVersions(ver.split('-')[0], target) >= 0; + +// --- upstream release notes ------------------------------------------------ + +async function upstreamNotes(ver) { + const res = await fetch(`https://api.github.com/repos/${UPSTREAM}/releases/tags/dsh-v${ver}`, { + headers: { 'User-Agent': UA, Accept: 'application/vnd.github+json' }, + }); + if (!res.ok) return null; + const rel = await res.json(); + const body = rel.body || ''; + // Notes are bilingual; keep the English half, demote its headings under ours. + // Upstream mixes HTML

(the anchored first heading) with markdown ###. + const i = body.search(/