|
1 | | -# workflow automates the Python package publishing process |
| 1 | +# workflow automates the Python package publishing process |
2 | 2 | # to PyPI upon pushes to the main branch or manual triggers, |
3 | | -# incrementing version if needed. |
| 3 | +# auto-bumps version before publishing. |
4 | 4 |
|
5 | 5 | name: Publish to PyPI |
6 | 6 | on: |
7 | 7 | push: |
8 | 8 | branches: |
9 | 9 | - main |
10 | 10 | paths-ignore: |
11 | | - - '**.md' # Ignore changes to Markdown files to prevent infinite loop |
| 11 | + - '**.md' |
12 | 12 | workflow_dispatch: |
13 | 13 | jobs: |
14 | 14 | deploy: |
15 | 15 | runs-on: ubuntu-latest |
16 | | - if: github.actor != 'github-actions[bot]' # This line prevents the loop |
| 16 | + if: github.actor != 'github-actions[bot]' |
17 | 17 | steps: |
18 | | - - uses: actions/checkout@v2 |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + token: ${{ secrets.GH_TOKEN }} |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Get current version |
| 24 | + run: | |
| 25 | + current_version=$(grep 'version =' pyproject.toml | cut -d'"' -f2) |
| 26 | + echo "CURRENT_VERSION=$current_version" >> $GITHUB_ENV |
| 27 | +
|
| 28 | + - name: Bump version |
| 29 | + run: | |
| 30 | + IFS=. read -r major minor patch <<< "${CURRENT_VERSION}" |
| 31 | + patch=$((patch + 1)) |
| 32 | + new_version="${major}.${minor}.${patch}" |
| 33 | + echo "NEW_VERSION=$new_version" >> $GITHUB_ENV |
| 34 | +
|
| 35 | + - name: Update version in setup.py |
| 36 | + run: | |
| 37 | + sed -i "s/version='.*'/version='$NEW_VERSION'/" setup.py |
| 38 | +
|
| 39 | + - name: Update version in pyproject.toml |
| 40 | + run: | |
| 41 | + sed -i "s/version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml |
| 42 | +
|
| 43 | + - name: Commit version bump |
| 44 | + run: | |
| 45 | + git config --global user.name "github-actions[bot]" |
| 46 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 47 | + git add . |
| 48 | + git commit -m "Auto bump version to $NEW_VERSION" |
| 49 | + git push origin main |
| 50 | +
|
19 | 51 | - name: Set up Python |
20 | | - uses: actions/setup-python@v2 |
| 52 | + uses: actions/setup-python@v5 |
21 | 53 | with: |
22 | | - python-version: '3.x' |
| 54 | + python-version: '3.12' |
| 55 | + |
23 | 56 | - name: Install dependencies |
24 | 57 | run: | |
25 | 58 | python -m pip install --upgrade pip |
26 | 59 | pip install poetry |
27 | | - - name: re run poetry lockfile |
28 | | - run: poetry lock --no-update |
| 60 | +
|
| 61 | + - name: Re-run poetry lockfile |
| 62 | + run: poetry lock |
| 63 | + |
29 | 64 | - name: Install project dependencies |
30 | 65 | run: poetry install |
| 66 | + |
31 | 67 | - name: Build package |
32 | 68 | run: poetry build |
| 69 | + |
33 | 70 | - name: Publish to PyPI |
34 | 71 | uses: pypa/gh-action-pypi-publish@release/v1 |
35 | 72 | with: |
|
0 commit comments