@@ -13,16 +13,37 @@ jobs:
1313 python-version : ["3.10", "3.11", "3.12", "3.13", "3.14"]
1414 steps :
1515 - uses : actions/checkout@v4
16+
1617 - name : Set up Python ${{ matrix.python-version }}
1718 uses : actions/setup-python@v5
1819 with :
1920 python-version : ${{ matrix.python-version }}
21+
22+ - name : Cache pip dependencies
23+ uses : actions/cache@v4
24+ with :
25+ path : ~/.cache/pip
26+ key : ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
27+ restore-keys : |
28+ ${{ runner.os }}-pip-${{ matrix.python-version }}-
29+ ${{ runner.os }}-pip-
30+
2031 - name : Install dependencies
2132 run : |
2233 python -m pip install --upgrade pip
2334 pip install -e .[dev]
24- - name : Run tests
25- run : pytest
35+
36+ - name : Lint with Ruff
37+ run : ruff check mcp_documents_reader.py tests
38+
39+ - name : Check formatting with Ruff
40+ run : ruff format --check mcp_documents_reader.py tests
41+
42+ - name : Type check with Basedpyright
43+ run : basedpyright mcp_documents_reader.py
44+
45+ - name : Run tests with coverage
46+ run : pytest --cov-report=xml
2647
2748 build :
2849 needs : test
@@ -32,44 +53,32 @@ jobs:
3253 with :
3354 fetch-depth : 0
3455 fetch-tags : true
56+
3557 - name : Set up Python
3658 uses : actions/setup-python@v5
3759 with :
3860 python-version : " 3.10"
61+
62+ - name : Cache pip dependencies
63+ uses : actions/cache@v4
64+ with :
65+ path : ~/.cache/pip
66+ key : ${{ runner.os }}-pip-build-${{ hashFiles('pyproject.toml') }}
67+ restore-keys : |
68+ ${{ runner.os }}-pip-build-
69+ ${{ runner.os }}-pip-
70+
3971 - name : Install dependencies
4072 run : |
4173 python -m pip install --upgrade pip
42- pip install build twine toml
43- - name : Sync version to server.json
44- run : |
45- python -c "
46- import toml
47- import json
48- import re
49-
50- # 从 pyproject.toml 读取版本
51- with open('pyproject.toml', 'r') as f:
52- pyproject = toml.load(f)
53- version = pyproject['project']['version']
54- print(f'Version from pyproject.toml: {version}')
55-
56- # 更新 server.json
57- with open('server.json', 'r') as f:
58- server = json.load(f)
74+ pip install build twine
5975
60- server['version'] = version
61- server['packages'][0]['version'] = version
62-
63- with open('server.json', 'w') as f:
64- json.dump(server, f, indent=2)
65- f.write('\n')
66-
67- print(f'Updated server.json to version {version}')
68- "
6976 - name : Build package
7077 run : python -m build
78+
7179 - name : Check distribution
7280 run : python -m twine check --strict dist/*
81+
7382 - name : Upload Artifacts
7483 uses : actions/upload-artifact@v4
7584 with :
@@ -102,27 +111,31 @@ jobs:
102111 contents : read
103112 steps :
104113 - uses : actions/checkout@v4
114+
115+ - name : Get version from tag
116+ id : get_version
117+ run : echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
118+
119+ - name : Update server.json version
120+ run : |
121+ VERSION=${{ steps.get_version.outputs.VERSION }}
122+ python -c "
123+ import json
124+ with open('server.json', 'r') as f:
125+ data = json.load(f)
126+ data['version'] = '$VERSION'
127+ for pkg in data.get('packages', []):
128+ pkg['version'] = '$VERSION'
129+ with open('server.json', 'w') as f:
130+ json.dump(data, f, indent=2)
131+ "
132+
105133 - name : Download mcp-publisher
106134 run : |
107135 curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
136+
108137 - name : Authenticate to MCP Registry
109138 run : ./mcp-publisher login github-oidc
110- - name : Check if version exists in MCP Registry
111- id : check-version
112- run : |
113- VERSION=$(grep -oP '^version\s*=\s*"\K[^"]+' pyproject.toml || grep -oP 'version\s*=\s*"\K[^"]+' pyproject.toml | head -1)
114- echo "version=$VERSION" >> $GITHUB_OUTPUT
115-
116- # 检查版本是否已存在于 MCP Registry
117- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.modelcontextprotocol.io/v0/servers/io.github.xt765/mcp_documents_reader/versions/$VERSION")
118-
119- if [ "$HTTP_CODE" = "200" ]; then
120- echo "exists=true" >> $GITHUB_OUTPUT
121- echo "::warning::Version $VERSION already exists in MCP Registry, skipping publish"
122- else
123- echo "exists=false" >> $GITHUB_OUTPUT
124- echo "Version $VERSION does not exist in MCP Registry, will publish"
125- fi
139+
126140 - name : Publish server to MCP Registry
127- if : steps.check-version.outputs.exists == 'false'
128141 run : ./mcp-publisher publish
0 commit comments