Skip to content

Commit 18642d8

Browse files
committed
ci: streamline release workflow
1 parent 143b496 commit 18642d8

File tree

1 file changed

+10
-62
lines changed

1 file changed

+10
-62
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ jobs:
2626
fetch-depth: 0
2727
ref: ${{ env.RELEASE_REF }}
2828

29-
- name: Ensure tag is published from main
29+
- name: Ensure tag points to default branch
3030
run: |
31-
git fetch origin main
32-
if ! git merge-base --is-ancestor "$(git rev-parse HEAD)" origin/main; then
33-
echo "::error::Release tag must point to a commit reachable from main"
31+
git fetch origin
32+
TARGET_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
33+
if [ -z "$TARGET_BRANCH" ]; then
34+
TARGET_BRANCH=master
35+
fi
36+
if ! git merge-base --is-ancestor "$(git rev-parse HEAD)" "origin/${TARGET_BRANCH}"; then
37+
echo "::error::Release tag must point to a commit reachable from ${TARGET_BRANCH}"
3438
exit 1
3539
fi
3640
@@ -55,64 +59,8 @@ jobs:
5559
- name: Install dependencies
5660
run: uv sync --frozen
5761

58-
- name: Verify version matches tag
59-
run: |
60-
TAG_VERSION="${RELEASE_TAG#v}"
61-
if [ "$TAG_VERSION" = "$RELEASE_TAG" ]; then
62-
echo "::error::Release tag must start with the letter 'v' (e.g. v1.2.3)"
63-
exit 1
64-
fi
65-
66-
PYPROJECT_VERSION=$(python - <<'PY'
67-
import pathlib, re
68-
text = pathlib.Path("pyproject.toml").read_text()
69-
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.MULTILINE)
70-
if not match:
71-
raise SystemExit("Could not read version from pyproject.toml")
72-
print(match.group(1))
73-
PY
74-
)
75-
76-
INIT_VERSION=$(python - <<'PY'
77-
import pathlib, re
78-
text = pathlib.Path("src/code_index_mcp/__init__.py").read_text()
79-
match = re.search(r'__version__\s*=\s*"([^"]+)"', text)
80-
if not match:
81-
raise SystemExit("Could not read __version__ from src/code_index_mcp/__init__.py")
82-
print(match.group(1))
83-
PY
84-
)
85-
86-
LOCK_VERSION=$(python - <<'PY'
87-
version = None
88-
with open("uv.lock", "r", encoding="utf-8") as fh:
89-
lines = fh.readlines()
90-
for idx, line in enumerate(lines):
91-
if line.strip() == 'name = "code-index-mcp"':
92-
for follower in lines[idx:idx+6]:
93-
if follower.strip().startswith("version ="):
94-
version = follower.split("=", 1)[1].strip().strip('"')
95-
break
96-
break
97-
if version is None:
98-
raise SystemExit("Could not find code-index-mcp in uv.lock")
99-
print(version)
100-
PY
101-
)
102-
103-
for entry in "pyproject.toml:$PYPROJECT_VERSION" "src/code_index_mcp/__init__.py:$INIT_VERSION" "uv.lock:$LOCK_VERSION"; do
104-
FILE=${entry%%:*}
105-
VERSION=${entry#*:}
106-
if [ "$VERSION" != "$TAG_VERSION" ]; then
107-
echo "::error file=$FILE::Expected version $TAG_VERSION but found $VERSION"
108-
exit 1
109-
fi
110-
done
111-
112-
- name: Run tests
113-
run: |
114-
uv run pytest
115-
uv run code-index-mcp --help
62+
- name: Install build tooling
63+
run: uv pip install build twine
11664

11765
- name: Build distributions
11866
run: uv run python -m build

0 commit comments

Comments
 (0)