|
1 | | -name: Upload Python Package to PyPI |
| 1 | +name: CI - Auto-release & upload to PyPI |
2 | 2 |
|
3 | 3 | on: |
| 4 | + push: |
| 5 | + branches: [main] # bump version & create Release |
4 | 6 | release: |
5 | | - types: [published] |
| 7 | + types: [published] # build & upload to PyPI |
6 | 8 |
|
7 | 9 | permissions: |
8 | | - contents: read |
| 10 | + contents: write |
9 | 11 | id-token: write |
10 | 12 |
|
11 | 13 | jobs: |
| 14 | +# ────────────────────────────────────── |
| 15 | +# 1. Job A: bump version & make Release |
| 16 | +# ────────────────────────────────────── |
| 17 | + auto-release: |
| 18 | + if: github.event_name == 'push' |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + |
| 23 | + with: { fetch-depth: 0 } |
| 24 | + |
| 25 | + - name: Set up Python |
| 26 | + |
| 27 | + with: { python-version: '3.x' } |
| 28 | + |
| 29 | + # Read current version (default 0.0.0 if file missing) |
| 30 | + - name: Get current version |
| 31 | + id: ver |
| 32 | + run: | |
| 33 | + cur=$(cat src/veedb/VERSION 2>/dev/null || echo "0.0.0") |
| 34 | + echo "current=$cur" >> "$GITHUB_OUTPUT" |
| 35 | +
|
| 36 | + # Bump patch (1.2.3 ➜ 1.2.4) |
| 37 | + - name: Bump patch version |
| 38 | + id: bump |
| 39 | + run: | |
| 40 | + IFS='.' read -r MAJ MIN PAT <<< "${{ steps.ver.outputs.current }}" |
| 41 | + PAT=$((PAT + 1)) |
| 42 | + NEW="$MAJ.$MIN.$PAT" |
| 43 | + echo "$NEW" > src/veedb/VERSION |
| 44 | + echo "new=$NEW" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + # Commit VERSION bump, tag & push |
| 47 | + - name: Commit & tag |
| 48 | + env: |
| 49 | + NEW_VERSION: ${{ steps.bump.outputs.new }} |
| 50 | + run: | |
| 51 | + git config user.name "github-actions" |
| 52 | + git config user.email "[email protected]" |
| 53 | + git add src/veedb/VERSION |
| 54 | + git commit -m "chore: bump version to v$NEW_VERSION [skip ci]" || true |
| 55 | + git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION" |
| 56 | + git push origin HEAD |
| 57 | + git push origin "v$NEW_VERSION" |
| 58 | +
|
| 59 | + # --------------------------- |
| 60 | + # Generate markdown changelog |
| 61 | + # --------------------------- |
| 62 | + - name: Generate changelog |
| 63 | + id: changelog |
| 64 | + run: | |
| 65 | + # Find previous tag (ignore errors if first release) |
| 66 | + prev=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 67 | + if [ -z "$prev" ]; then |
| 68 | + range="HEAD" |
| 69 | + else |
| 70 | + range="$prev..HEAD" |
| 71 | + fi |
| 72 | +
|
| 73 | + # Collect commit messages *except* the autobump commit |
| 74 | + git log $range --pretty=format:"- %s (%h)" --invert-grep --grep "bump version" > CHANGELOG_GH_ACTION.md |
| 75 | +
|
| 76 | + # Fallback message if no commits make it through the filter |
| 77 | + if [ ! -s CHANGELOG_GH_ACTION.md ]; then |
| 78 | + echo "- Version bump only" > CHANGELOG_GH_ACTION.md |
| 79 | + fi |
| 80 | +
|
| 81 | + echo "body_path=CHANGELOG_GH_ACTION.md" >> "$GITHUB_OUTPUT" |
| 82 | +
|
| 83 | + # Create GitHub Release with the changelog as body |
| 84 | + - name: Create GitHub Release |
| 85 | + |
| 86 | + with: |
| 87 | + tag_name: v${{ steps.bump.outputs.new }} |
| 88 | + body_path: ${{ steps.changelog.outputs.body_path }} |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + |
| 92 | +# ──────────────────────────────────────── |
| 93 | +# 2. Job B: build & publish when Release fires |
| 94 | +# ──────────────────────────────────────── |
12 | 95 | deploy: |
| 96 | + if: github.event_name == 'release' |
13 | 97 | runs-on: ubuntu-latest |
14 | 98 | environment: pypi |
| 99 | + |
15 | 100 | steps: |
16 | | - - uses: actions/checkout@v4 |
17 | | - |
18 | | - - name: Update VERSION file |
19 | | - run: | |
20 | | - echo "${{ github.event.release.tag_name }}" > src/veedb/VERSION |
21 | | - git config --local user.email "[email protected]" |
22 | | - git config --local user.name "GitHub Action" |
23 | | - git add src/veedb/VERSION |
24 | | - git commit -m "Update version to ${{ github.event.release.tag_name }}" || exit 0 |
25 | | -
|
26 | | - - name: Set up Python |
27 | | - uses: actions/setup-python@v5 |
28 | | - with: |
29 | | - python-version: '3.x' |
30 | | - |
31 | | - - name: Install dependencies |
32 | | - run: | |
33 | | - python -m pip install --upgrade pip |
34 | | - pip install build twine |
35 | | -
|
36 | | - - name: Build package |
37 | | - run: python -m build |
38 | | - |
39 | | - - name: Publish package to PyPI |
40 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
41 | | - with: |
42 | | - user: __token__ |
43 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 101 | + - uses: actions/[email protected] # exact tagged commit |
| 102 | + |
| 103 | + - name: Set up Python |
| 104 | + |
| 105 | + with: { python-version: '3.x' } |
| 106 | + |
| 107 | + - name: Install build deps |
| 108 | + run: | |
| 109 | + python -m pip install --upgrade pip |
| 110 | + pip install build twine |
| 111 | +
|
| 112 | + - name: Build wheel & sdist |
| 113 | + run: python -m build |
| 114 | + |
| 115 | + - name: Publish to PyPI |
| 116 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 117 | + with: |
| 118 | + user: __token__ |
| 119 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments