Skip to content

Commit ddce994

Browse files
committed
Update python-publish.yml
1 parent ac7480f commit ddce994

1 file changed

Lines changed: 42 additions & 35 deletions

File tree

.github/workflows/python-publish.yml

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
1-
# This workflow will upload a Python Package using Twine when a release is created
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
9-
name: Upload Python Package
1+
name: Publish Python Package
102

113
on:
12-
release:
13-
types: [published]
4+
push:
5+
branches:
6+
- main
147

158
permissions:
169
contents: write # Needed to push changes back to the repository
1710

1811
jobs:
19-
deploy:
20-
12+
release:
2113
runs-on: ubuntu-latest
22-
2314
steps:
2415
- uses: actions/checkout@v4
25-
26-
- name: Extract version from tag
27-
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
28-
29-
- name: Update version in setup.py
30-
uses: jacobtomlinson/gha-find-replace@v2
31-
with:
32-
find: "version='[0-9]+\\.[0-9]+\\.[0-9]+'"
33-
replace: "version='${{ env.VERSION }}'"
34-
regex: true
35-
include: 'setup.py'
36-
37-
- name: Commit version bump
38-
uses: stefanzweifel/git-auto-commit-action@v4
3916
with:
40-
commit_message: 'Version bump in setup.py to ${{ env.VERSION }} [skip ci]'
41-
file_pattern: setup.py
17+
fetch-depth: 0 # Fetch all history for tags and branches
4218

4319
- name: Set up Python
4420
uses: actions/setup-python@v3
@@ -48,14 +24,45 @@ jobs:
4824
- name: Install dependencies
4925
run: |
5026
python -m pip install --upgrade pip
51-
pip install build
27+
pip install bump2version
28+
29+
- name: Bump version
30+
run: |
31+
bump2version patch --allow-dirty --list | grep new_version= | cut -d'=' -f2 > version.txt
32+
shell: bash
33+
34+
- name: Get new version
35+
id: vars
36+
run: |
37+
echo "VERSION=$(cat version.txt)" >> $GITHUB_ENV
38+
39+
- name: Commit version bump
40+
uses: stefanzweifel/git-auto-commit-action@v4
41+
with:
42+
commit_message: 'Version bump to ${{ env.VERSION }} [skip ci]'
43+
file_pattern: |
44+
setup.py
45+
setup.cfg # Include if you have it
46+
your_package/__init__.py # If version is specified here
47+
48+
- name: Create GitHub Release
49+
id: create_release
50+
uses: softprops/action-gh-release@v1
51+
with:
52+
tag_name: "v${{ env.VERSION }}"
53+
name: "v${{ env.VERSION }}"
54+
draft: false
55+
prerelease: false
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Install build tool
60+
run: pip install build
5261

5362
- name: Build package
5463
run: python -m build
5564

56-
- name: Publish package
57-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
65+
- name: Publish package to PyPI
66+
uses: pypa/gh-action-pypi-publish@master
5867
with:
59-
user: simpleanalytics
6068
password: ${{ secrets.PYPI_API_TOKEN }}
61-

0 commit comments

Comments
 (0)