-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (57 loc) · 1.66 KB
/
publish.yml
File metadata and controls
71 lines (57 loc) · 1.66 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
name: Publish to PyPI
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Extract changelog
id: changelog
env:
TAG_NAME: ${{ github.ref_name }}
run: |
python <<'PY'
import os
import pathlib
import re
tag = os.environ["TAG_NAME"]
version = tag[1:] if tag.startswith("v") else tag
changelog_path = pathlib.Path("CHANGELOG.md")
if changelog_path.exists():
changelog = changelog_path.read_text()
pattern = re.compile(rf"^## \[{re.escape(version)}\][^\n]*\n(.*?)(?=\n## \[|\Z)", re.DOTALL | re.MULTILINE)
section = pattern.search(changelog)
body = section.group(1).strip() if section else f"Release {version}"
else:
body = f"Release {version}"
if not body:
body = f"Release {version}"
output = pathlib.Path("release_notes.md")
output.write_text(body + "\n")
print(body)
PY
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body_path: release_notes.md
generate_release_notes: false
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}