Skip to content

Commit e40ad2b

Browse files
committed
feat: auto-publish to PyPI and npm on push to main
- CI workflow now auto-bumps patch version and publishes on every push - Publishes to PyPI (trusted publisher), npm (npx support), and GitHub Releases - CLI version is now read dynamically from package metadata
1 parent 34560ae commit e40ad2b

File tree

2 files changed

+150
-22
lines changed

2 files changed

+150
-22
lines changed

.github/workflows/publish.yml

Lines changed: 144 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
name: Publish to PyPI
1+
name: Auto Publish
22

33
on:
44
push:
5-
tags:
6-
- 'v*.*.*'
5+
branches: [main]
6+
paths-ignore:
7+
- '*.md'
8+
- 'LICENSE'
9+
- '.gitignore'
710

811
jobs:
912
test:
@@ -12,43 +15,163 @@ jobs:
1215
matrix:
1316
python-version: ['3.10', '3.12', '3.13']
1417
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v4
18+
- uses: actions/checkout@v4
1719

18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v5
20+
- uses: actions/setup-python@v5
2021
with:
2122
python-version: ${{ matrix.python-version }}
2223

23-
- name: Install uv
24-
uses: astral-sh/setup-uv@v4
24+
- uses: astral-sh/setup-uv@v4
2525

2626
- name: Install dependencies
2727
run: uv pip install --system -e ".[dev]" 2>/dev/null || uv pip install --system -e .
2828

2929
- name: Run tests
30-
run: python -m pytest tests/ -x -q --tb=short 2>/dev/null || echo "No test suite configured"
30+
run: python -m pytest tests/ -x -q --tb=short
3131

32-
publish:
32+
bump-and-publish:
3333
needs: test
3434
runs-on: ubuntu-latest
35-
environment: pypi
3635
permissions:
36+
contents: write
3737
id-token: write
3838
steps:
39-
- name: Checkout code
40-
uses: actions/checkout@v4
39+
- uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 0
42+
token: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- uses: actions/setup-python@v5
45+
with:
46+
python-version: '3.12'
4147

42-
- name: Set up Python
43-
uses: actions/setup-python@v5
48+
- uses: astral-sh/setup-uv@v4
49+
50+
- uses: actions/setup-node@v4
4451
with:
45-
python-version: '3.10'
52+
node-version: '20'
53+
registry-url: 'https://registry.npmjs.org'
54+
55+
# --- Auto bump version ---
56+
- name: Bump version
57+
id: bump
58+
run: |
59+
# Read current version from pyproject.toml
60+
CURRENT=$(grep '^version' pyproject.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
61+
echo "Current version: $CURRENT"
62+
63+
# Bump patch version
64+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
65+
NEW_PATCH=$((PATCH + 1))
66+
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
67+
echo "New version: $NEW_VERSION"
4668
47-
- name: Install uv
48-
uses: astral-sh/setup-uv@v4
69+
# Update pyproject.toml
70+
sed -i "s/^version = \"$CURRENT\"/version = \"$NEW_VERSION\"/" pyproject.toml
4971
50-
- name: Build package
72+
# Update version in cli.py
73+
sed -i "s/%(prog)s $CURRENT/%(prog)s $NEW_VERSION/" paper_search/cli.py 2>/dev/null || true
74+
75+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
76+
77+
- name: Commit version bump
78+
run: |
79+
git config user.name "github-actions[bot]"
80+
git config user.email "github-actions[bot]@users.noreply.github.com"
81+
git add pyproject.toml paper_search/cli.py
82+
git diff --cached --quiet || git commit -m "chore: bump version to ${{ steps.bump.outputs.version }}"
83+
git tag "v${{ steps.bump.outputs.version }}"
84+
git push && git push --tags
85+
86+
# --- Publish to PyPI ---
87+
- name: Build Python package
5188
run: uv build
5289

5390
- name: Publish to PyPI
54-
uses: pypa/gh-action-pypi-publish@release/v1
91+
uses: pypa/gh-action-pypi-publish@release/v1
92+
93+
# --- Publish to npm ---
94+
- name: Prepare npm package
95+
run: |
96+
VERSION="${{ steps.bump.outputs.version }}"
97+
mkdir -p npm-pkg/bin
98+
99+
# Create the npm wrapper script
100+
cat > npm-pkg/bin/paper-search <<'SCRIPT'
101+
#!/usr/bin/env node
102+
const { execFileSync } = require("child_process");
103+
const args = process.argv.slice(2);
104+
105+
// Try system-installed paper-search first, then fall back to uvx
106+
try {
107+
execFileSync("paper-search", args, { stdio: "inherit" });
108+
} catch {
109+
try {
110+
execFileSync("uvx", ["paper-search-cli", ...args], { stdio: "inherit" });
111+
} catch {
112+
console.error(
113+
"paper-search-cli is not installed.\n" +
114+
"Install with: pip install paper-search-cli OR uv tool install paper-search-cli"
115+
);
116+
process.exit(1);
117+
}
118+
}
119+
SCRIPT
120+
chmod +x npm-pkg/bin/paper-search
121+
122+
# Create package.json
123+
cat > npm-pkg/package.json <<EOF
124+
{
125+
"name": "paper-search-cli",
126+
"version": "$VERSION",
127+
"description": "CLI tool for searching and downloading academic papers from 20+ sources",
128+
"bin": { "paper-search": "bin/paper-search" },
129+
"keywords": ["academic", "papers", "search", "arxiv", "cli", "claude-skill"],
130+
"license": "MIT",
131+
"repository": {
132+
"type": "git",
133+
"url": "https://github.com/openags/paper-search-cli"
134+
},
135+
"author": "P.S Zhang <pengsongzhang96@gmail.com>"
136+
}
137+
EOF
138+
139+
# Create README for npm
140+
cat > npm-pkg/README.md <<'EOF'
141+
# paper-search-cli
142+
143+
CLI tool for searching and downloading academic papers from 20+ sources.
144+
145+
## Usage via npx
146+
147+
```bash
148+
npx paper-search-cli search "transformer architecture"
149+
npx paper-search-cli sources
150+
```
151+
152+
## Prerequisite
153+
154+
Requires Python 3.10+ with `paper-search-cli` installed:
155+
156+
```bash
157+
pip install paper-search-cli
158+
# or
159+
uv tool install paper-search-cli
160+
```
161+
162+
See https://github.com/openags/paper-search-cli for full documentation.
163+
EOF
164+
165+
- name: Publish to npm
166+
working-directory: npm-pkg
167+
run: npm publish --access public
168+
env:
169+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
170+
171+
# --- GitHub Release ---
172+
- name: Create GitHub Release
173+
uses: softprops/action-gh-release@v2
174+
with:
175+
tag_name: "v${{ steps.bump.outputs.version }}"
176+
generate_release_notes: true
177+
files: dist/*

paper_search/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import sys
88
import textwrap
9+
from importlib.metadata import version as pkg_version
910
from typing import Any, Dict, List
1011

1112
from . import engine
@@ -154,7 +155,11 @@ def build_parser() -> argparse.ArgumentParser:
154155
paper-search sources
155156
"""),
156157
)
157-
parser.add_argument("--version", action="version", version="%(prog)s 1.0.0")
158+
try:
159+
_version = pkg_version("paper-search-cli")
160+
except Exception:
161+
_version = "dev"
162+
parser.add_argument("--version", action="version", version=f"%(prog)s {_version}")
158163
sub = parser.add_subparsers(dest="command", required=True)
159164

160165
# search

0 commit comments

Comments
 (0)