Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Build Docker images for prerelease versions

Jeffrey Chen47d39e528da7
diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml
index be7cf17ccd..7d39481c57 100644
--- a/.github/workflows/dockerimage.yml
+++ b/.github/workflows/dockerimage.yml
@@ -4,14 +4,12 @@ run-name: Release Docker Image ${{ github.event_name == 'workflow_dispatch' && f
on:
push:
tags:
+ # 预发行版(-alpha/-beta/-rc)同样构建镜像,但只发布版本标签,不更新 latest。
- 'v*'
- - '!*alpha*'
- - '!*beta*'
- - '!*rc*'
workflow_dispatch:
inputs:
version:
- description: 'Stable version to build, without the v prefix'
+ description: 'Version to build, without the v prefix; an -alpha/-beta/-rc suffix is allowed'
required: true
type: string
verify_cache:
@@ -20,6 +18,7 @@ on:
type: boolean
concurrency:
+ # 预发行版与正式版共用同一队列串行执行,且不取消进行中的运行,避免同时向镜像仓库推送。
group: siyuan-docker-release
cancel-in-progress: false
queue: max
@@ -73,8 +72,8 @@ jobs:
else
VERSION="${GITHUB_REF_NAME#v}"
fi
- if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
- echo "Expected a stable version without a v prefix, stopping"
+ if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)(\.[0-9A-Za-z]+)*)?$ ]]; then
+ echo "Expected a version without a v prefix, optionally with an -alpha/-beta/-rc suffix, stopping"
exit 1
fi
PACKAGE_VERSION=$(jq -er .version app/package.json)
@@ -96,6 +95,7 @@ jobs:
timeout-minutes: 360
strategy:
# 一个平台失败时保留其他平台的构建结果,支持只重试失败任务。
+ # 预发行版与正式版构建相同的平台集合。
fail-fast: false
matrix:
include:
diff --git a/docs/RELEASE-VERIFICATION.zh-CN.md b/docs/RELEASE-VERIFICATION.zh-CN.md
index 59b8177431..06a7be9dfb 100644
--- a/docs/RELEASE-VERIFICATION.zh-CN.md
+++ b/docs/RELEASE-VERIFICATION.zh-CN.md
@@ -32,7 +32,7 @@ git tag v3.8.7-beta.1
git push origin v3.8.7-beta.1
```
-推送包含 `-alpha`、`-beta` 或 `-rc` 的标签会触发 `CD For SiYuan`。标签去掉开头的 `v` 后必须与 `app/package.json` 版本完全一致,Android 版本也必须匹配,否则准备阶段会失败。
+推送包含 `-alpha`、`-beta` 或 `-rc` 的标签会触发 `CD For SiYuan`,以及 [Release Docker Image](../.github/workflows/dockerimage.yml) 的预发行镜像构建。标签去掉开头的 `v` 后必须与 `app/package.json` 版本完全一致,Android 版本也必须匹配,否则准备阶段会失败。预发行镜像只发布 `v` 加版本号的标签,不更新 `latest`。
### 3. 等待自动构建与发布
@@ -204,7 +204,7 @@ git diff --exit-code $releaseCommit origin/master
在 GitHub 创建 Release 时输入新标签 `v3.8.7`,选择创建新标签,目标分支选择 `master`,核对目标提交。发布 Release 时由 GitHub 创建标签,无需在本地手动打标签或推送标签。已有同名标签时先核对其指向,不覆盖或重复创建。
- 将公开分发的安装包和最终的 `SHA256SUMS.txt` 上传至 `siyuan-note/siyuan` 的 GitHub Release,核对版本、目标提交和文件名后公开正式版
-- 确认正式版标签已创建,并检查 [Release Docker Image](../.github/workflows/dockerimage.yml) 的运行状态;该工作流监听正式版标签的推送事件,仅合并分支不会触发
+- 确认正式版标签已创建,并检查 [Release Docker Image](../.github/workflows/dockerimage.yml) 的运行状态;该工作流监听 `v*` 标签推送,正式版同时更新 `latest`,预发行版只发布版本标签,仅合并分支不会触发
- 通过下载域名下载安装包并核对摘要
- 同步 Gitee
- 上传百度网盘
diff --git a/scripts/test_docker_release.py b/scripts/test_docker_release.py
index ed1c36cc59..92b734c219 100644
--- a/scripts/test_docker_release.py
+++ b/scripts/test_docker_release.py
@@ -70,6 +70,22 @@ class ManifestTests(unittest.TestCase):
release.manifests(index)
+class VersionTests(unittest.TestCase):
+ def test_version_pattern_accepts_stable_and_prerelease_versions(self):
+ for version in ("3.8.7", "3.8.8-alpha", "3.8.8-alpha.1", "3.8.8-beta.2", "3.8.8-rc.3"):
+ with self.subTest(version=version):
+ self.assertTrue(release.VERSION.fullmatch(version), version)
+
+ def test_version_pattern_rejects_other_or_partial_versions(self):
+ for version in ("v3.8.7", "3.8", "3.8.7.1", "3.8.8-alpha.", "3.8.8-preview.1", "latest"):
+ with self.subTest(version=version):
+ self.assertFalse(release.VERSION.fullmatch(version), version)
+
+ def test_release_tags_keep_latest_on_stable_versions_only(self):
+ self.assertEqual(release.release_tags("3.8.7"), [":v3.8.7", ":latest"])
+ self.assertEqual(release.release_tags("3.8.8-alpha.2"), [":v3.8.8-alpha.2"])
+
+
class OCRTests(unittest.TestCase):
def test_recognition_tolerates_layout_whitespace_and_latin_case(self):
release.validate_rows('[{"text":"SiYuan"},{"text":" OCR123"}]', "siyuan ocr 123")
@@ -191,6 +207,20 @@ class PublishTests(unittest.TestCase):
self.assertIn("b3log/siyuan:latest", command)
self.assertEqual(run.call_count, 4)
+ def test_prerelease_publishes_version_tag_without_latest(self):
+ # 预发行版不得更新 latest,否则拉取 latest 的稳定用户会拿到预发行版。
+ value = report()
+ value["version"] = "3.8.8-alpha.2"
+ self.save(value)
+ response = subprocess.CompletedProcess([], 0, json.dumps(manifest()), "")
+ with patch.object(release, "run", return_value=response) as run:
+ release.promote(IMAGE, "3.8.8-alpha.2", self.path)
+ command = run.call_args_list[1].args[0]
+ self.assertEqual(command[-1], IMAGE)
+ self.assertIn("b3log/siyuan:v3.8.8-alpha.2", command)
+ self.assertNotIn("b3log/siyuan:latest", command)
+ self.assertEqual(run.call_count, 3)
+
def test_remote_manifest_difference_is_reported(self):
self.save(report())
changed = manifest()
diff --git a/scripts/verify-docker-release.py b/scripts/verify-docker-release.py
index 065862eed0..d2de3972cd 100644
--- a/scripts/verify-docker-release.py
+++ b/scripts/verify-docker-release.py
@@ -15,6 +15,8 @@ import uuid
PLATFORMS = ("linux/amd64", "linux/arm64", "linux/arm/v7", "linux/arm/v8")
CHECKS = {"licenses", "version", "model-load", "chinese", "latin", "blank", "worker-failure", "notebook"}
DIGEST = re.compile(r"sha256:[0-9a-f]{64}")
+# 与 app/package.json 的版本一致:正式版为 x.y.z,预发行版追加 -alpha.1、-beta.2 或 -rc.3。
+VERSION = re.compile(r"[0-9]+\.[0-9]+\.[0-9]+(?:-(?:alpha|beta|rc)(?:\.[0-9A-Za-z]+)*)?")
def run(arguments, *, input=None, timeout=300, check=True):
@@ -260,6 +262,14 @@ def assemble(repository, tag, version, reports_path, report_path, provenance):
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
+def release_tags(version):
+ """预发行版只发布版本标签,latest 始终指向正式版。"""
+ tags = [":v" + version]
+ if "-" not in version:
+ tags.append(":latest")
+ return tags
+
+
def promote(image, version, report_path):
report = json.loads(report_path.read_text(encoding="utf-8"))
expected = verified_platforms(report, image, version)
@@ -267,9 +277,12 @@ def promote(image, version, report_path):
actual = manifests(json.loads(run(["docker", "buildx", "imagetools", "inspect", image, "--raw"]).stdout))
if actual != expected:
raise ValueError("Candidate manifest differs from the verified image")
- run(["docker", "buildx", "imagetools", "create", "--tag", repository + ":v" + version,
- "--tag", repository + ":latest", image], timeout=900)
- for tag in (":v" + version, ":latest"):
+ tags = release_tags(version)
+ command = ["docker", "buildx", "imagetools", "create"]
+ for tag in tags:
+ command += ["--tag", repository + tag]
+ run(command + [image], timeout=900)
+ for tag in tags:
published = manifests(json.loads(run(["docker", "buildx", "imagetools", "inspect", repository + tag, "--raw"]).stdout))
if published != expected:
raise ValueError(f"Published manifest differs from the verified image: {tag}")
@@ -291,8 +304,8 @@ def main():
parser.add_argument("--configuration-commit")
parser.add_argument("--run-id")
args = parser.parse_args()
- if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", args.version) or args.timeout <= 0:
- parser.error("Expected a stable release version and positive timeout")
+ if not VERSION.fullmatch(args.version) or args.timeout <= 0:
+ parser.error("Expected a release version and positive timeout")
provenance = {"source_commit": args.source_commit, "configuration_commit": args.configuration_commit,
"run_id": args.run_id}
if args.command == "assemble" or args.platform: