diff --git a/.github/workflows/build-ubuntu20.yml b/.github/workflows/build-ubuntu20.yml index 2298d6c..455a5a4 100644 --- a/.github/workflows/build-ubuntu20.yml +++ b/.github/workflows/build-ubuntu20.yml @@ -1,22 +1,39 @@ name: Build Ubuntu 20.04 binaries - -# Triggered manually for binary releases; see OPEN_SOURCE_AUDIT.md. - on: workflow_dispatch: inputs: ref: - description: Git ref to build + description: Existing annotated vX.Y.Z tag from the selected Forge line required: true - default: v2.0.1 + type: string version: - description: Release version without the v prefix + description: Exact node version in the tag and source manifest (not the Forge line) required: true - default: 2.0.1 - + type: string + release_line: + description: Forge compatibility line + required: true + type: choice + options: + - 1.x + - 2.x + default: 2.x + workflow_call: + inputs: + ref: + description: Existing annotated vX.Y.Z tag from the selected Forge line + required: true + type: string + version: + description: Exact node version in the tag and source manifest (not the Forge line) + required: true + type: string + release_line: + description: Forge compatibility line + required: true + type: string permissions: contents: read - jobs: build: runs-on: ubuntu-latest @@ -24,62 +41,71 @@ jobs: image: ubuntu:20.04 env: RELEASE_VERSION: ${{ inputs.version }} + RELEASE_TAG: ${{ inputs.ref }} + RELEASE_LINE: ${{ inputs.release_line }} steps: - - name: Install system tools - run: | - apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y \ - binutils \ - ca-certificates \ - curl \ - file \ - git - rm -rf /var/lib/apt/lists/* - - - uses: actions/checkout@v6 - with: - ref: ${{ inputs.ref }} - - - name: Install uv and Python 3.12 - run: | - curl -LsSf https://astral.sh/uv/0.12.5/install.sh | - env UV_INSTALL_DIR=/usr/local/bin sh - uv python install 3.12 - uv --version - uv run --no-project --python 3.12 python --version - - - name: Build with PyInstaller - run: ./scripts/build_pyinstaller.sh - - - name: Verify and package binaries - run: | - test "${{ inputs.ref }}" = "v${RELEASE_VERSION}" - ./dist/joint_trajectory_controller --help >/dev/null - ./dist/gripper_action_controller --help >/dev/null - ./dist/fake_joint_plant --help >/dev/null - file ./dist/joint_trajectory_controller ./dist/gripper_action_controller ./dist/fake_joint_plant - ldd --version | sed -n '1p' - archive="forge-controls-v${RELEASE_VERSION}-ubuntu20.04-x86_64.tar.gz" - tar \ - --sort=name \ - --mtime='UTC 1970-01-01' \ - --owner=0 \ - --group=0 \ - --numeric-owner \ - -C dist \ - -czf "${archive}" \ - joint_trajectory_controller \ - gripper_action_controller \ - fake_joint_plant - sha256sum "${archive}" > "${archive}.sha256" - tar -tzf "${archive}" - sha256sum --check "${archive}.sha256" - - - uses: actions/upload-artifact@v6 - with: - name: forge-controls-v${{ inputs.version }}-ubuntu20.04-x86_64 - path: | - forge-controls-v${{ inputs.version }}-ubuntu20.04-x86_64.tar.gz - forge-controls-v${{ inputs.version }}-ubuntu20.04-x86_64.tar.gz.sha256 - if-no-files-found: error - retention-days: 30 + - name: Install system tools + run: | + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + binutils \ + ca-certificates \ + curl \ + file \ + git + rm -rf /var/lib/apt/lists/* + - uses: actions/checkout@v6 + with: + ref: refs/tags/${{ inputs.ref }} + fetch-depth: 0 + persist-credentials: false + - name: Check out release tooling from the workflow commit + uses: actions/checkout@v6 + with: + ref: ${{ github.workflow_sha }} + path: .release-tools + persist-credentials: false + - name: Install uv and Python 3.12 + run: | + curl -LsSf https://astral.sh/uv/0.12.5/install.sh | + env UV_INSTALL_DIR=/usr/local/bin sh + uv python install 3.12 + uv --version + uv run --no-project --python 3.12 python --version + - name: Validate Forge release line and source version + run: | + git config --global --add safe.directory "$(pwd -P)" + uv run --no-project --python 3.12 python .release-tools/scripts/check_release_line.py --line "$RELEASE_LINE" --tag "$RELEASE_TAG" --version "$RELEASE_VERSION" --default-branch main + - name: Build with PyInstaller + run: ./scripts/build_pyinstaller.sh + - name: Verify and package binaries + run: | + test "${RELEASE_TAG}" = "v${RELEASE_VERSION}" + ./dist/joint_trajectory_controller --help >/dev/null + ./dist/gripper_action_controller --help >/dev/null + ./dist/fake_joint_plant --help >/dev/null + file ./dist/joint_trajectory_controller ./dist/gripper_action_controller ./dist/fake_joint_plant + ldd --version | sed -n '1p' + archive="forge-controls-v${RELEASE_VERSION}-ubuntu20.04-x86_64.tar.gz" + tar \ + --sort=name \ + --mtime='UTC 1970-01-01' \ + --owner=0 \ + --group=0 \ + --numeric-owner \ + -C dist \ + -czf "${archive}" \ + joint_trajectory_controller \ + gripper_action_controller \ + fake_joint_plant + sha256sum "${archive}" > "${archive}.sha256" + tar -tzf "${archive}" + sha256sum --check "${archive}.sha256" + - uses: actions/upload-artifact@v6 + with: + name: forge-controls-v${{ inputs.version }}-ubuntu20.04-x86_64 + path: | + forge-controls-v${{ inputs.version }}-ubuntu20.04-x86_64.tar.gz + forge-controls-v${{ inputs.version }}-ubuntu20.04-x86_64.tar.gz.sha256 + if-no-files-found: error + retention-days: 30 diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml new file mode 100644 index 0000000..dfdb687 --- /dev/null +++ b/.github/workflows/release-checks.yml @@ -0,0 +1,24 @@ +name: Release line checks +on: + pull_request: + paths: + - '.github/workflows/**' + - 'scripts/check_release_line.py' + - 'scripts/test_release_line.py' + push: + paths: + - '.github/workflows/**' + - 'scripts/check_release_line.py' + - 'scripts/test_release_line.py' +permissions: + contents: read +jobs: + release-line-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: '3.12' + - name: Test source selection, versions and Forge/Dora compatibility + run: python -m unittest discover -s scripts -p test_release_line.py -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..24751bd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,131 @@ +name: Build versioned release + +on: + workflow_dispatch: + inputs: + release_line: + description: Forge compatibility line (independent of the node version) + type: choice + options: [1.x, 2.x] + default: 2.x + required: true + tag: + description: Existing annotated vX.Y.Z tag on the selected release line + type: string + required: true + build_binaries: + description: Include the existing Ubuntu binary build where available + type: boolean + default: false + +permissions: + contents: read + +concurrency: + group: release-${{ inputs.tag }} + cancel-in-progress: false + +jobs: + packages: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.release.outputs.version }} + steps: + - uses: actions/checkout@v6 + with: + ref: refs/tags/${{ inputs.tag }} + fetch-depth: 0 + persist-credentials: false + - name: Check out release tooling from the workflow commit + uses: actions/checkout@v6 + with: + ref: ${{ github.workflow_sha }} + path: .release-tools + persist-credentials: false + - uses: actions/setup-python@v6 + with: + python-version: '3.12' + - name: Validate release line and immutable source + id: release + env: + RELEASE_LINE: ${{ inputs.release_line }} + RELEASE_TAG: ${{ inputs.tag }} + run: >- + python .release-tools/scripts/check_release_line.py + --line "$RELEASE_LINE" --tag "$RELEASE_TAG" + --default-branch main + - name: Build source archive and Python distributions when supported + env: + RELEASE_TAG: ${{ inputs.tag }} + RELEASE_LINE: ${{ inputs.release_line }} + PACKAGE_KIND: ${{ steps.release.outputs.package_kind }} + run: | + set -euo pipefail + mkdir -p release-assets + name="${GITHUB_REPOSITORY#*/}" + git archive --format=tar.gz --prefix="${name}-${RELEASE_TAG}/" \ + --output="release-assets/${name}-forge-${RELEASE_LINE}-${RELEASE_TAG}-source.tar.gz" HEAD + if [ "$PACKAGE_KIND" = python ]; then + python -m pip install uv==0.13.7 + uv build --no-sources --out-dir release-assets + python -m pip install twine==7.0.0 + python -m twine check release-assets/*.whl release-assets/*[0-9].tar.gz + fi + python .release-tools/scripts/check_release_line.py \ + --line "$RELEASE_LINE" --tag "$RELEASE_TAG" \ + --default-branch main > release-assets/release-metadata.json + (cd release-assets && sha256sum ./* > source-SHA256SUMS.txt) + - uses: actions/upload-artifact@v6 + with: + name: release-source-${{ inputs.release_line }}-${{ inputs.tag }} + path: release-assets/* + if-no-files-found: error + + binaries: + needs: packages + if: ${{ inputs.build_binaries }} + permissions: + contents: read + uses: ./.github/workflows/build-ubuntu20.yml + with: + ref: ${{ inputs.tag }} + version: ${{ needs.packages.outputs.version }} + release_line: ${{ inputs.release_line }} + + draft: + needs: [packages, binaries] + if: ${{ always() && needs.packages.result == 'success' && (needs.binaries.result == 'success' || needs.binaries.result == 'skipped') }} + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v6 + with: + path: release-assets + merge-multiple: true + - name: Verify assets and attach to a draft without replacing published files + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ inputs.tag }} + RELEASE_LINE: ${{ inputs.release_line }} + run: | + set -euo pipefail + cd release-assets + sha256sum --check source-SHA256SUMS.txt + for checksum in ./*.sha256; do + [ -e "$checksum" ] || continue + sha256sum --check "$checksum" + done + if gh release view "$RELEASE_TAG" --json isDraft --jq .isDraft > /tmp/release-draft-state 2>/tmp/release-lookup-error; then + test "$(cat /tmp/release-draft-state)" = true + elif grep -qi 'release not found' /tmp/release-lookup-error; then + printf 'Forge %s release candidate from %s.\n\nUse peers and Dora from the same compatibility line. Build success does not establish hardware, model, sustained-run or rollback acceptance. Review the workflow results before publishing.\n' \ + "$RELEASE_LINE" "$RELEASE_TAG" > /tmp/release-notes + gh release create "$RELEASE_TAG" --verify-tag --draft --latest=false \ + --title "$RELEASE_TAG (Forge $RELEASE_LINE)" --notes-file /tmp/release-notes + else + cat /tmp/release-lookup-error >&2 + exit 1 + fi + gh release upload "$RELEASE_TAG" ./* diff --git a/README.md b/README.md index 9c2f896..d5eb14c 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,30 @@ Review the complete bundled artifact before publishing standalone executables. This branch prepares node version `2.0.0` for Dora 1.x, frozen to Dora `1.0.1` for migration validation. It uses the official Forge 2.x distributions; Common is at least `2.1.0`. Regenerated locks and all executable entrypoints are part of the change. Every change report must list repository, changes and test evidence, including per-node `dora run` records and a chained test containing `adapter-forge-gateway`. Unavailable hardware/model checks remain pending. Source PRs do not publish stable releases or synchronize GitLab; synchronization follows full acceptance. + +## Versioned releases + +**Mandatory tag-first release rule:** merge the version/lock change, create an annotated version tag on that reviewed commit, build that exact tag, validate the artifacts, then publish. Moving branch names, untagged commit IDs and replacement of published tags are not release inputs. + +| Release line | Source | Node/package version | Runtime | +| --- | --- | --- | --- | +| Forge 1.x | `stable/1.x` | `1.x`, tag `v1.X.Y` | Forge 1.x / Dora 0.4.x | +| Forge 2.x | `main` | `2.x`, tag `v2.X.Y` | Forge 2.x / Dora 1.x | + +**Legacy normalization:** nodes previously at 0.x on `stable/1.x` release as **1.0.0**, retaining Forge 1.x / Dora 0.4.x dependencies and runtime behavior. Existing 1.x package versions are retained. Node/package majors now follow the Forge compatibility line; a 0.x tag is rejected. + +Run **Build versioned release** from `main` for either line. First merge the version/lock changes into the selected source branch, then create an unused **annotated** tag on that reviewed commit. The tag must match package metadata. Never move existing tags or reuse a published version. Dispatch uses the workflow's reviewed tooling with the exact tagged source, so legacy tags need not contain the new release helper. + +```bash +# Replace with an existing, reviewed and unpublished tag matching source metadata. +TAG=v1.X.Y +gh workflow run release.yml --ref main -f release_line=1.x -f tag="$TAG" +TAG=v2.X.Y +gh workflow run release.yml --ref main -f release_line=2.x -f tag="$TAG" +``` + +The workflow verifies tag type, source commit, branch ancestry, source version and locked Forge/Dora compatibility. It builds source archives and wheel/sdist where supported, checks Python distribution metadata and SHA-256, and creates or attaches to a **draft GitHub Release**. Published releases/assets are not overwritten; review all build results and acceptance evidence before publishing. This workflow does not publish node packages to PyPI. + +Set `build_binaries=true` to call the existing Ubuntu 20.04 binary workflow; its existing architecture, CLI and archive checks remain in force. You can also run `build-ubuntu20.yml` directly with `ref`, `version` and `release_line`; `ref` must be an annotated tag, not a moving branch. Binary artifacts are attached only after all selected jobs succeed. + +The source archive preserves the tagged tree; external SDKs/submodules, model downloads and site configuration remain separate prerequisites. A dependency or SDK build failure is not successful release acceptance. Build success does not establish single-node or Gateway-chain `dora run`, hardware, real-model, sustained-run or rollback acceptance. Every acceptance chain must include `adapter-forge-gateway` from the same compatibility line. Forge 2.x is a **breaking change**: align Forge libraries, node versions and Dora across the entire deployment; keep 1.x on its maintenance branch. diff --git a/README_zh.md b/README_zh.md index 1b03ddb..c89322a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -27,3 +27,30 @@ 本分支准备节点版本 `2.0.0`,适配 Dora 1.x,迁移验证锁定 Dora `1.0.1`。使用正式 Forge 2.x 分发包;Common 至少为 `2.1.0`。此次更新包括依赖锁文件与各独立可执行入口。 每轮报告必须列出仓库、改动和测试证据,包括各节点的 `dora run` 记录,以及包含 `adapter-forge-gateway` 的串联测试。缺少硬件或模型的验收项保持待验证。源码 PR 不等于正式发布;整体验收通过后再同步 GitLab。 + +## 分版本发布 + +**发布规则(强制):** 合并版本/锁文件修改 → 在已审查提交上创建 annotated 版本标签 → 从该标签精确构建 → 校验产物 → 发布。禁止使用移动分支、未打标签的提交构建 Release,禁止覆盖已发布标签。 + +| 维护线 | 源码 | 节点/包版本 | 运行时 | +| --- | --- | --- | --- | +| Forge 1.x | `stable/1.x` | `1.x`,标签 `v1.X.Y` | Forge 1.x / Dora 0.4.x | +| Forge 2.x | `main` | `2.x`,标签 `v2.X.Y` | Forge 2.x / Dora 1.x | + +**旧版版本号统一:** `stable/1.x` 原为 0.x 的节点以 **1.0.0** 发布,保留 Forge 1.x / Dora 0.4.x 依赖与运行行为。已有 1.x 版本保留。节点/包主版本与 Forge 兼容线一致,不再接受 0.x 发布标签。 + +两条线均从 `main` 运行 **Build versioned release**。先将版本和锁文件修改通过 PR 合并至对应源码分支,再在已审查提交上创建未占用的 **annotated** 标签,标签必须匹配包元数据。禁止移动已有标签或复用已发布版本。工作流使用自身已审查的发布工具与精确标签源码,旧标签无需包含新发布脚本。 + +```bash +# 替换为已存在、已审查、未发布且与源码元数据一致的标签。 +TAG=v1.X.Y +gh workflow run release.yml --ref main -f release_line=1.x -f tag="$TAG" +TAG=v2.X.Y +gh workflow run release.yml --ref main -f release_line=2.x -f tag="$TAG" +``` + +流水线校验标签类型、源码提交、分支归属、源码版本及锁定的 Forge/Dora 兼容性;构建源码归档及项目支持的 wheel/sdist,检查 Python 分发元数据与 SHA-256,并创建或附加至 **GitHub Release 草稿**。不覆盖已发布 Release 或产物;发布前检查全部构建结果与验收依据。该流程不发布节点包至 PyPI。 + +设置 `build_binaries=true` 复用已有 Ubuntu 20.04 二进制工作流,保留原架构、CLI 和归档校验。也可直接运行 `build-ubuntu20.yml`,传入 `ref`、`version`、`release_line`;`ref` 必须为 annotated 标签,不能为移动分支。仅在所有选定任务通过后附加二进制产物。 + +源码归档保留标签中的文件;外部 SDK/submodule、模型下载与现场配置仍是独立前置条件。依赖或 SDK 构建失败不能视为发布验收通过。构建成功不代表单节点或串联 `dora run`、真机、真实模型、长稳态或回滚验收通过;每条验收链必须包含相同兼容线的 `adapter-forge-gateway`。Forge 2.x 属于 **breaking change**,整个部署的 Forge 库、节点版本与 Dora 必须对齐;1.x 保留在维护分支。 diff --git a/migration/release-lines-report.json b/migration/release-lines-report.json new file mode 100644 index 0000000..7f1218d --- /dev/null +++ b/migration/release-lines-report.json @@ -0,0 +1,66 @@ +{ + "repository": "PhyAgentOS/operator-controls", + "target": "main", + "scope": "Build and document Forge 1.x and 2.x releases", + "release_line_unit_tests": { + "command": "python -m unittest discover -s scripts -p test_release_line.py -v", + "passed": 12 + }, + "workflow_validation": { + "tool": "actionlint 1.7.12", + "result": "passed" + }, + "distribution_checks": { + "result": "source-only project or separately checked core package families", + "artifacts": [] + }, + "source_profile_scope": "Local candidate worktrees; proposed maintenance changes are not deployed or merged yet. Full checksums and raw logs remain in the local workspace.", + "source_profiles": [ + { + "repo": "PhyAgentOS/operator-controls", + "line": "1.x", + "version": "1.0.0", + "forge_majors": [ + 1 + ], + "dora_versions": [ + [ + 0, + 4 + ] + ], + "kind": "source", + "ready": true + }, + { + "repo": "PhyAgentOS/operator-controls", + "line": "2.x", + "version": "2.0.0", + "forge_majors": [ + 2 + ], + "dora_versions": [ + [ + 1, + 0 + ] + ], + "kind": "source", + "ready": true + } + ], + "dora_run": { + "single_node": { + "status": "not-run", + "reason": "This change verifies release tooling and version metadata; no current node runtime acceptance is claimed." + }, + "gateway_chain": { + "status": "not-run", + "reason": "Fresh integration acceptance remains required; every such chain must include adapter-forge-gateway from the same Forge line." + } + }, + "linux_binary_release_build": "not-run in this change; existing binary workflow checks are preserved", + "hardware_model_sustained_rollback_acceptance": "pending", + "published_tags_releases_modified": false, + "gitlab_sync": false +} diff --git a/scripts/check_release_line.py b/scripts/check_release_line.py new file mode 100644 index 0000000..aafcdcc --- /dev/null +++ b/scripts/check_release_line.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python3 +"""Validate a release tag, its source branch, metadata and Forge/Dora line.""" + +import argparse +import json +import os +import re +import subprocess +import tomllib +from pathlib import Path + +CORE_PACKAGES = { + "forge-common", + "forge-msgs", + "forge-robot", + "forge-policy", + "forge-tool", + "forge-kinematics", + "forge_msgs", + "forgelab_common", +} +SEMVER = r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)" + + +def git(*args): + return subprocess.check_output(["git", *args], text=True).strip() + + +def load(path): + return tomllib.loads(path.read_text()) + + +def metadata(root, family=None): + if family: + versions = load(root / "versions.toml")["packages"] + version = versions[family] + project = load(root / "packages" / family / "pyproject.toml")["project"] + if project["version"] != version: + raise ValueError("Family metadata differs from versions.toml") + return version, {int(version.split(".")[0])}, set(), "family" + manifest = root / "pyproject.toml" + rust = not manifest.exists() + doc = load(root / "Cargo.toml") if rust else load(manifest) + version = doc["package" if rust else "project"]["version"] + lock = load(root / ("Cargo.lock" if rust else "uv.lock")) + forge = { + int(p["version"].split(".")[0]) + for p in lock["package"] + if p["name"] in CORE_PACKAGES + } + dora = { + tuple(map(int, p["version"].split(".")[:2])) + for p in lock["package"] + if p["name"] in {"dora-rs", "dora-node-api"} + } + kind = ( + "python" + if not rust + and "build-system" in doc + and doc.get("tool", {}).get("uv", {}).get("package") is not False + else "source" + ) + return version, forge, dora, kind + + +def validate(root, line, tag, default_branch, requested_version=None): + match = re.fullmatch( + r"(?:forge-(common|msgs|robot|policy|kinematics|tool)-)?v" + SEMVER, tag + ) + if not match: + raise ValueError( + "Use an existing annotated vX.Y.Z or forge--vX.Y.Z tag" + ) + family = match[1] + version = ".".join(match.groups()[1:]) + if requested_version is not None and version != requested_version: + raise ValueError("Tag and requested version differ") + tag_ref = "refs/tags/" + tag + if git("cat-file", "-t", tag_ref) != "tag": + raise ValueError("An annotated release tag is required") + commit = git("rev-parse", tag_ref + "^{commit}") + if commit != git("rev-parse", "HEAD"): + raise ValueError("Checkout differs from the release tag") + branch = "stable/1.x" if line == "1.x" else default_branch + parent = "refs/remotes/origin/" + branch + ancestry = subprocess.run( + ["git", "merge-base", "--is-ancestor", commit, parent], check=False + ) + if ancestry.returncode != 0: + raise ValueError("Release tag must belong to " + branch) + actual, forge, dora, kind = metadata(root, family) + if actual != version: + raise ValueError("Tag version differs from source metadata: " + actual) + major = int(line[0]) + if not version.startswith(str(major) + "."): + raise ValueError( + f"Forge {line} requires node/package version {major}.x; " + "normalize legacy 0.x nodes to 1.0.0 on stable/1.x" + ) + if forge != {major}: + raise ValueError( + f"Forge {line} requires resolved Forge major {major}; found {sorted(forge)}. " + "Finish the migration before releasing." + ) + expected_dora = (0, 4) if line == "1.x" else (1, 0) + if not family and ( + not dora + or any(v[0] != expected_dora[0] or (v[0] == 0 and v[1] != 4) for v in dora) + ): + raise ValueError( + f"Forge {line} requires Dora {expected_dora[0]}.{expected_dora[1]}.x; " + f"found {sorted(dora)}" + ) + return dict( + tag=tag, + version=version, + release_line=line, + commit=commit, + source_branch=branch, + package_kind=kind, + ) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--line", choices=["1.x", "2.x"], required=True) + parser.add_argument("--tag", required=True) + parser.add_argument("--default-branch", required=True) + parser.add_argument("--version") + args = parser.parse_args() + try: + result = validate( + Path.cwd(), args.line, args.tag, args.default_branch, args.version + ) + except (ValueError, KeyError, OSError, subprocess.CalledProcessError) as error: + raise SystemExit(str(error)) from error + if os.environ.get("GITHUB_OUTPUT"): + with open(os.environ["GITHUB_OUTPUT"], "a") as output: + for key, value in result.items(): + output.write(f"{key}={value}\n") + print(json.dumps(result, indent=2)) + + +if __name__ == "__main__": + main() diff --git a/scripts/test_release_line.py b/scripts/test_release_line.py new file mode 100644 index 0000000..26f6b4d --- /dev/null +++ b/scripts/test_release_line.py @@ -0,0 +1,142 @@ +"""Exercise the release boundary without installing or starting a robot node.""" + +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +if __package__: + from .check_release_line import validate +else: + from check_release_line import validate + + +class ReleaseLineTests(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + old = Path.cwd() + os.chdir(self.root) + self.addCleanup(os.chdir, old) + self.git("init", "-b", "main") + self.git("config", "user.name", "Release test") + self.git("config", "user.email", "release-test@example.invalid") + self.write(1, "1.0.0") + self.git("add", ".") + self.git("commit", "-qm", "legacy line") + self.git("tag", "-a", "v1.0.0", "-m", "legacy") + self.git("update-ref", "refs/remotes/origin/stable/1.x", "HEAD") + self.legacy = self.git("rev-parse", "HEAD") + self.write(2, "2.0.0") + self.git("add", ".") + self.git("commit", "-qm", "current line") + self.git("tag", "-a", "v2.0.0", "-m", "current") + self.git("update-ref", "refs/remotes/origin/main", "HEAD") + + def git(self, *args): + return subprocess.check_output( + ["git", *args], text=True, stderr=subprocess.DEVNULL + ).strip() + + def write(self, major, version): + (self.root / "pyproject.toml").write_text( + f'[project]\nname="node"\nversion="{version}"\n[build-system]\nrequires=["hatchling"]\nbuild-backend="hatchling.build"\n' + ) + dora = "0.4.1" if major == 1 else "1.0.1" + (self.root / "uv.lock").write_text( + f'[[package]]\nname="forge-msgs"\nversion="{major}.0.0"\n[[package]]\nname="dora-rs"\nversion="{dora}"\n' + ) + + def test_current_line(self): + self.assertEqual( + validate(self.root, "2.x", "v2.0.0", "main")["package_kind"], "python" + ) + + def test_legacy_line(self): + self.git("checkout", "-q", "v1.0.0") + self.assertEqual( + validate(self.root, "1.x", "v1.0.0", "main")["version"], "1.0.0" + ) + + def test_wrong_ancestry(self): + with self.assertRaisesRegex(ValueError, "belong to stable"): + validate(self.root, "1.x", "v2.0.0", "main") + + def test_incomplete_migration(self): + self.git("checkout", "-q", "v1.0.0") + with self.assertRaisesRegex(ValueError, "requires node/package version 2.x"): + validate(self.root, "2.x", "v1.0.0", "main") + + def test_zero_version_needs_normalization(self): + self.git("checkout", "-q", "v1.0.0") + self.write(1, "0.1.0") + self.git("add", ".") + self.git("commit", "-qm", "legacy zero version") + self.git("tag", "-a", "v0.1.0", "-m", "zero") + self.git("update-ref", "refs/remotes/origin/stable/1.x", "HEAD") + with self.assertRaisesRegex(ValueError, "normalize legacy 0.x"): + validate(self.root, "1.x", "v0.1.0", "main") + + def test_unrelated_tag(self): + self.git("checkout", "--orphan", "unrelated") + self.git("commit", "-qm", "unreviewed source") + self.git("tag", "-a", "v2.0.1", "-m", "unrelated") + with self.assertRaisesRegex(ValueError, "belong to main"): + validate(self.root, "2.x", "v2.0.1", "main") + + def test_lightweight_tag(self): + self.git("tag", "v2.0.1") + with self.assertRaisesRegex(ValueError, "annotated"): + validate(self.root, "2.x", "v2.0.1", "main") + + def test_wrong_checkout(self): + with self.assertRaisesRegex(ValueError, "Checkout differs"): + validate(self.root, "2.x", "v1.0.0", "main") + + def test_version_mismatch(self): + with self.assertRaisesRegex(ValueError, "requested version"): + validate(self.root, "2.x", "v2.0.0", "main", "2.0.1") + (self.root / "pyproject.toml").write_text('[project]\nversion="2.0.1"\n') + with self.assertRaisesRegex(ValueError, "source metadata"): + validate(self.root, "2.x", "v2.0.0", "main") + + def test_wrong_dora_and_missing_forge(self): + (self.root / "uv.lock").write_text( + '[[package]]\nname="forge-msgs"\nversion="2.0.0"\n[[package]]\nname="dora-rs"\nversion="0.4.1"\n' + ) + with self.assertRaisesRegex(ValueError, "requires Dora"): + validate(self.root, "2.x", "v2.0.0", "main") + (self.root / "uv.lock").write_text("package=[]\n") + with self.assertRaisesRegex(ValueError, "resolved Forge"): + validate(self.root, "2.x", "v2.0.0", "main") + + def test_rust_metadata(self): + (self.root / "pyproject.toml").unlink() + (self.root / "Cargo.toml").write_text( + '[package]\nname="node"\nversion="2.0.0"\n' + ) + (self.root / "Cargo.lock").write_text( + '[[package]]\nname="forge_msgs"\nversion="2.0.0"\n[[package]]\nname="dora-node-api"\nversion="1.0.1"\n' + ) + self.assertEqual( + validate(self.root, "2.x", "v2.0.0", "main")["package_kind"], "source" + ) + + def test_core_family(self): + path = self.root / "packages/msgs" + path.mkdir(parents=True) + (path / "pyproject.toml").write_text('[project]\nversion="2.1.0"\n') + (self.root / "versions.toml").write_text('[packages]\nmsgs="2.1.0"\n') + self.git("tag", "-a", "forge-msgs-v2.1.0", "-m", "msgs") + self.assertEqual( + validate(self.root, "2.x", "forge-msgs-v2.1.0", "main")["package_kind"], + "family", + ) + with self.assertRaisesRegex(ValueError, "Use an existing"): + validate(self.root, "2.x", "forge-unknown-v2.1.0", "main") + + +if __name__ == "__main__": + unittest.main()