Python CI/CD #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bump Version and Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_part: | |
| description: 'Part of the version to bump (major, minor, patch)' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/namecheap-python | |
| permissions: | |
| contents: write # Needed for creating tags and releases | |
| id-token: write # Needed for PyPI trusted publishing | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install poetry build | |
| - name: Configure Git | |
| run: | | |
| git config user.name github-actions | |
| git config user.email github-actions@github.com | |
| - name: Bump version | |
| id: bump_version | |
| run: | | |
| # Bump version using Poetry (single source of truth) | |
| poetry version ${{ github.event.inputs.version_part }} | |
| NEW_VERSION=$(poetry version -s) | |
| echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV | |
| echo "Bumped version to ${NEW_VERSION}" | |
| - name: Commit version changes | |
| run: | | |
| git add pyproject.toml | |
| git commit -m "Bump version to ${NEW_VERSION}" | |
| git push | |
| - name: Create and push tag | |
| run: | | |
| git tag -a "v${NEW_VERSION}" -m "Release version ${NEW_VERSION}" | |
| git push origin "v${NEW_VERSION}" | |
| - name: Build package | |
| run: python -m build | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ env.NEW_VERSION }} | |
| release_name: Release v${{ env.NEW_VERSION }} | |
| draft: false | |
| prerelease: false | |
| body: | | |
| Release version ${{ env.NEW_VERSION }} | |
| ## How to install | |
| ``` | |
| pip install namecheap-python==${{ env.NEW_VERSION }} | |
| ``` | |
| - name: Publish package to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true |