-
Notifications
You must be signed in to change notification settings - Fork 2
75 lines (62 loc) · 1.99 KB
/
publish.yml
File metadata and controls
75 lines (62 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# GitHub Actions CI/CD - PyPI Publish Workflow
# Publishes package to PyPI when a new tag is created
name: Publish to PyPI
on:
push:
tags:
- 'v*' # Trigger on version tags (e.g., v0.1.0, v1.2.3)
jobs:
build-and-publish:
name: Build and Publish to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write # Required for trusted publishing
contents: write # Required for creating GitHub releases
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build distribution packages
run: |
python -m build
- name: Check distribution packages
run: |
twine check dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true
- name: Extract release notes from CHANGELOG
id: extract-release-notes
run: |
# Extract version from tag (remove 'v' prefix)
VERSION="${GITHUB_REF#refs/tags/v}"
# Extract changelog section for this version
awk -v ver="$VERSION" '
/^## \['"$VERSION"'\]/ { flag=1; next }
/^## \[/ && flag { exit }
flag { print }
' CHANGELOG.md > release-notes.md
# If no release notes found, use a default message
if [ ! -s release-notes.md ]; then
echo "Release $VERSION" > release-notes.md
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
body_path: release-notes.md
draft: false
prerelease: false
files: |
dist/*.tar.gz
dist/*.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}