Skip to content

Commit 1d8934b

Browse files
committed
feat(ci): update publish workflow to trigger on version tags
- Remove branch trigger and replace with tag trigger for versioning - Simplify release creation by using softprops/action-gh-release - Extract changelog based on version from tags
1 parent fa8fdfa commit 1d8934b

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

.github/workflows/publish.yml

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,24 @@ name: Publish to PyPI
22

33
on:
44
push:
5-
branches: [main]
5+
tags:
6+
- 'v*'
67

78
jobs:
89
publish:
910
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
id-token: write
1014

1115
steps:
1216
- uses: actions/checkout@v4
13-
with:
14-
fetch-depth: 0
1517

1618
- name: Set up Python
1719
uses: actions/setup-python@v5
1820
with:
1921
python-version: '3.11'
2022

21-
- name: Get version from pyproject.toml
22-
id: get_version
23-
run: |
24-
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
25-
echo "version=v$VERSION" >> $GITHUB_OUTPUT
26-
27-
- name: Create Release
28-
id: create_release
29-
uses: actions/create-release@v1
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
with:
33-
tag_name: ${{ steps.get_version.outputs.version }}
34-
release_name: Release ${{ steps.get_version.outputs.version }}
35-
body: |
36-
## What's Changed
37-
${{ github.event.head_commit.message }}
38-
39-
**Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.get_version.outputs.version }}
40-
draft: false
41-
prerelease: false
42-
4323
- name: Install build dependencies
4424
run: |
4525
python -m pip install --upgrade pip
@@ -48,6 +28,21 @@ jobs:
4828
- name: Build package
4929
run: python -m build
5030

31+
- name: Extract changelog
32+
id: changelog
33+
run: |
34+
VERSION=${GITHUB_REF#refs/tags/v}
35+
CHANGELOG=$(awk '/## \['$VERSION'\]/,/## \[/' CHANGELOG.md | sed '$d' | tail -n +2)
36+
echo "content<<EOF" >> $GITHUB_OUTPUT
37+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
38+
echo "EOF" >> $GITHUB_OUTPUT
39+
40+
- name: Create Release
41+
uses: softprops/action-gh-release@v1
42+
with:
43+
body: ${{ steps.changelog.outputs.content }}
44+
generate_release_notes: false
45+
5146
- name: Publish to PyPI
5247
env:
5348
TWINE_USERNAME: __token__

0 commit comments

Comments
 (0)