From 84bb085250049c4ac7f4e15b9c418812c773c3d3 Mon Sep 17 00:00:00 2001 From: chendelian <116870791@qq.com> Date: Tue, 2 Jun 2026 10:33:55 +0800 Subject: [PATCH] chore: package env example in skill releases Co-authored-by: Cursor --- .github/workflows/reusable-release-skill.yaml | 8 ++++ tests/test_release_workflow.py | 42 +++++++++++++++++++ tools/release.ps1 | 1 + 3 files changed, 51 insertions(+) create mode 100644 tests/test_release_workflow.py diff --git a/.github/workflows/reusable-release-skill.yaml b/.github/workflows/reusable-release-skill.yaml index b2ade4b..6847a7a 100644 --- a/.github/workflows/reusable-release-skill.yaml +++ b/.github/workflows/reusable-release-skill.yaml @@ -119,6 +119,14 @@ jobs: " shutil.copy2(req_src, req_dst)" \ " print('Copied requirements.txt')" \ '' \ + "env_example_src = os.path.abspath('.env.example')" \ + "env_example_dst = os.path.join(PACKAGE, '.env.example')" \ + 'if os.path.isfile(env_example_src):' \ + " shutil.copy2(env_example_src, env_example_dst)" \ + " print('Copied .env.example')" \ + 'if os.path.isfile(env_example_src) and not os.path.isfile(env_example_dst):' \ + " raise RuntimeError('.env.example exists in skill root but was not packaged')" \ + '' \ "print('Package top-level entries:')" \ 'for name in sorted(os.listdir(PACKAGE)):' \ " print(' -', name)" \ diff --git a/tests/test_release_workflow.py b/tests/test_release_workflow.py new file mode 100644 index 0000000..a482838 --- /dev/null +++ b/tests/test_release_workflow.py @@ -0,0 +1,42 @@ +"""Text-level checks that reusable-release-skill packages .env.example at package root.""" + +from __future__ import annotations + +import os +import re + +import pytest + +_REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +_WORKFLOW_PATH = os.path.join( + _REPO_ROOT, ".github", "workflows", "reusable-release-skill.yaml" +) + + +@pytest.fixture(scope="module") +def workflow_text() -> str: + with open(_WORKFLOW_PATH, encoding="utf-8") as f: + return f.read() + + +def test_workflow_packages_env_example_at_root(workflow_text: str) -> None: + assert ".env.example" in workflow_text + assert "Copied .env.example" in workflow_text + assert "env_example_src = os.path.abspath('.env.example')" in workflow_text + assert "env_example_dst = os.path.join(PACKAGE, '.env.example')" in workflow_text + assert ( + "raise RuntimeError('.env.example exists in skill root but was not packaged')" + in workflow_text + ) + + +def test_workflow_does_not_package_dot_env(workflow_text: str) -> None: + # Must not copy live .env to package root (only .env.example). + assert not re.search( + r"shutil\.copy2\([^)]*['\"]\.env['\"]", + workflow_text, + ) + assert not re.search( + r"os\.path\.join\(PACKAGE,\s*['\"]\.env['\"]\)", + workflow_text, + ) diff --git a/tools/release.ps1 b/tools/release.ps1 index baa4c95..1632aab 100644 --- a/tools/release.ps1 +++ b/tools/release.ps1 @@ -33,6 +33,7 @@ - 复制 tests/ - 复制 evals/(除 scripts 外均为明文;若目录不存在则跳过;复制时排除常见缓存与运行产物) - 若根目录存在 requirements.txt,则复制到包根(明文,不 PyArmor) + - 若根目录存在 .env.example,则复制到包根(明文,不 PyArmor,用于首次运行时落盘用户 .env) 本脚本在打 tag 前会做一次 scripts/ 结构自检,避免子目录未提交却仍发布。 #>