diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index d7c1441..bced339 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -49,6 +49,9 @@ jobs: exit 1 fi + - name: Check template metadata + run: python scripts/check_template_ready.py + - name: Build run: | python -m pip install --upgrade pip diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e759812..f371fa9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,13 +12,13 @@ permissions: contents: read jobs: checks: - uses: starter-series/.github/.github/workflows/reusable-python-ci.yml@main + uses: starter-series/.github/.github/workflows/reusable-python-ci.yml@fdacdbce9d1dd18a573e7c57c482bb07ab1f2954 ci: if: ${{ always() }} needs: - checks runs-on: ubuntu-latest steps: - - uses: starter-series/.github/.github/actions/require-checks@main + - uses: starter-series/.github/.github/actions/require-checks@fdacdbce9d1dd18a573e7c57c482bb07ab1f2954 with: results: ${{ toJSON(needs) }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8fabe52..662642b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,6 +12,6 @@ permissions: security-events: write jobs: analyze: - uses: starter-series/.github/.github/workflows/reusable-codeql.yml@main + uses: starter-series/.github/.github/workflows/reusable-codeql.yml@fdacdbce9d1dd18a573e7c57c482bb07ab1f2954 with: language: python diff --git a/README.ko.md b/README.ko.md index e635963..ac318c7 100644 --- a/README.ko.md +++ b/README.ko.md @@ -236,3 +236,5 @@ pip-audit . --strict # 의존성 audit ## 라이선스 MIT + +게시 전에 패키지 이름·저자·프로젝트 URL·콘솔 명령을 수정하고 실행하세요: `python scripts/check_template_ready.py`. diff --git a/README.md b/README.md index 4d03c9e..0ed6e74 100644 --- a/README.md +++ b/README.md @@ -256,3 +256,5 @@ pip-audit . --strict # Dependency audit ## License MIT + +Before publishing, customize the package name, author, project URLs, and console command, then run `python scripts/check_template_ready.py`. diff --git a/scripts/check_template_ready.py b/scripts/check_template_ready.py new file mode 100644 index 0000000..853692e --- /dev/null +++ b/scripts/check_template_ready.py @@ -0,0 +1,50 @@ +"""Reject uncustomized package metadata before publishing to PyPI.""" + +import re +import sys +import tomllib +from pathlib import Path +from typing import Any + + +def find_issues(project: dict[str, Any]) -> list[str]: + issues = [] + name = project.get("name", "") + if not name or re.sub(r"[-_.]+", "-", name).lower() == "my-mcp-server": + issues.append("project.name: replace my-mcp-server with your package name") + authors = project.get("authors", []) + if not authors or any(not a.get("name") or a["name"] == "Your Name" for a in authors): + issues.append("project.authors: set the package author") + urls = project.get("urls", {}) + for field in ("Homepage", "Repository", "Issues"): + value = urls.get(field, "") + if ( + not value + or "starter-series/python-mcp-server-starter" in value.lower() + or "YOUR_" in value + ): + issues.append(f"project.urls.{field}: set your project's URL") + if "my-mcp-server" in project.get("scripts", {}): + issues.append("project.scripts: rename the my-mcp-server console command") + return issues + + +def main() -> int: + path = ( + Path(sys.argv[1]) + if len(sys.argv) > 1 + else Path(__file__).resolve().parents[1] / "pyproject.toml" + ) + with path.open("rb") as stream: + issues = find_issues(tomllib.load(stream).get("project", {})) + if issues: + print("Template metadata is not ready to publish:", file=sys.stderr) + for issue in issues: + print(f"- {issue}", file=sys.stderr) + return 1 + print("Template metadata is ready to publish.") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/test_template_ready.py b/tests/test_template_ready.py new file mode 100644 index 0000000..fae2bbc --- /dev/null +++ b/tests/test_template_ready.py @@ -0,0 +1,36 @@ +import runpy +from pathlib import Path + +find_issues = runpy.run_path( + str(Path(__file__).resolve().parents[1] / "scripts/check_template_ready.py") +)["find_issues"] + + +def test_rejects_template_metadata(): + issues = find_issues( + { + "name": "my_mcp_server", + "authors": [{"name": "Your Name"}], + "urls": {"Repository": "https://github.com/starter-series/python-mcp-server-starter"}, + "scripts": {"my-mcp-server": "sample.__main__:run"}, + } + ) + assert len(issues) == 6 + + +def test_accepts_customized_metadata(): + assert ( + find_issues( + { + "name": "sample-mcp", + "authors": [{"name": "Heznpc"}], + "urls": { + "Homepage": "https://github.com/sample/sample-mcp", + "Repository": "https://github.com/sample/sample-mcp", + "Issues": "https://github.com/sample/sample-mcp/issues", + }, + "scripts": {"sample-mcp": "sample.__main__:run"}, + } + ) + == [] + )