"""Text-level checks for release-related GitHub Actions workflows.""" from __future__ import annotations import os import re import pytest _REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) _SKILL_WORKFLOW_PATH = os.path.join( _REPO_ROOT, ".github", "workflows", "reusable-release-skill.yaml" ) _PUBLISH_WORKFLOW_PATH = os.path.join( _REPO_ROOT, ".github", "workflows", "publish.yml" ) @pytest.fixture(scope="module") def workflow_text() -> str: with open(_SKILL_WORKFLOW_PATH, encoding="utf-8") as f: return f.read() @pytest.fixture(scope="module") def publish_workflow_text() -> str: with open(_PUBLISH_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, ) def test_publish_workflow_triggers_on_main_only(publish_workflow_text: str) -> None: assert "branches:" in publish_workflow_text assert "- main" in publish_workflow_text assert "tags:" not in publish_workflow_text def test_publish_workflow_uses_pyproject_version_only(publish_workflow_text: str) -> None: assert "ci_set_package_version" not in publish_workflow_text assert "GITHUB_RUN_NUMBER" not in publish_workflow_text assert "GITHUB_RUN_ID" not in publish_workflow_text assert ".post" not in publish_workflow_text assert "python3.12 -m build" in publish_workflow_text assert "twine upload" in publish_workflow_text