|
1 | | -name: Publish Python Package |
| 1 | +name: Bump Version and Publish |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: |
6 | | - - published |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_type: |
| 7 | + description: "Version bump type" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
7 | 14 |
|
8 | 15 | jobs: |
9 | | - pypi-publish: |
10 | | - name: upload release to PyPI |
| 16 | + bump-version-and-publish: |
| 17 | + name: Bump version, release, and publish to PyPI |
11 | 18 | runs-on: ubuntu-latest |
12 | 19 | permissions: |
13 | | - contents: read |
| 20 | + contents: write |
14 | 21 | id-token: write |
15 | 22 | steps: |
16 | 23 | - uses: actions/checkout@v4 |
17 | 24 | with: |
18 | | - ref: ${{ github.event.release.tag_name }} |
| 25 | + fetch-depth: 0 |
19 | 26 |
|
20 | 27 | - uses: actions/setup-python@v5 |
21 | 28 | with: |
|
24 | 31 | - name: Install uv |
25 | 32 | uses: astral-sh/setup-uv@v5 |
26 | 33 | with: |
27 | | - # Install a specific version of uv. |
28 | 34 | version: "0.6.14" |
29 | 35 |
|
| 36 | + - name: Bump version |
| 37 | + id: bump |
| 38 | + run: | |
| 39 | + CURRENT_VERSION=$(python -c "import re; content=open('src/unstract/llmwhisperer/__init__.py').read(); print(re.search(r'__version__\s*=\s*\"(.+?)\"', content).group(1))") |
| 40 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" |
| 41 | +
|
| 42 | + case "${{ github.event.inputs.version_type }}" in |
| 43 | + major) |
| 44 | + MAJOR=$((MAJOR + 1)) |
| 45 | + MINOR=0 |
| 46 | + PATCH=0 |
| 47 | + ;; |
| 48 | + minor) |
| 49 | + MINOR=$((MINOR + 1)) |
| 50 | + PATCH=0 |
| 51 | + ;; |
| 52 | + patch) |
| 53 | + PATCH=$((PATCH + 1)) |
| 54 | + ;; |
| 55 | + esac |
| 56 | +
|
| 57 | + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 58 | + echo "old_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" |
| 59 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + sed -i "s/__version__ = \"$CURRENT_VERSION\"/__version__ = \"$NEW_VERSION\"/" src/unstract/llmwhisperer/__init__.py |
| 62 | +
|
| 63 | + - name: Commit and tag |
| 64 | + run: | |
| 65 | + git config user.name "github-actions[bot]" |
| 66 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 67 | + git add src/unstract/llmwhisperer/__init__.py |
| 68 | + git commit -m "Bump version to v${{ steps.bump.outputs.new_version }}" |
| 69 | + git tag "v${{ steps.bump.outputs.new_version }}" |
| 70 | + git push origin main --tags |
| 71 | +
|
| 72 | + - name: Create GitHub Release |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ github.token }} |
| 75 | + run: gh release create "v${{ steps.bump.outputs.new_version }}" --generate-notes |
| 76 | + |
30 | 77 | - name: Build package |
31 | 78 | run: uv build |
32 | 79 |
|
|
0 commit comments