-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (73 loc) · 2.43 KB
/
Copy pathrelease.yml
File metadata and controls
82 lines (73 loc) · 2.43 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
76
77
78
79
80
81
82
# Release workflow for the python-sdk.
#
# Triggered by tag-release.yml (workflow_dispatch at the new tag) or by a
# manually pushed `v*` tag. Builds the sdist/wheel, publishes to PyPI (only if
# a PYPI_API_TOKEN secret is configured), and creates a GitHub Release whose
# body is the matching section from CHANGELOG.md with auto-generated commit
# notes appended.
#
# To enable PyPI publishing, add a `PYPI_API_TOKEN` secret (a PyPI API token)
# to this repository. Without it, the build still runs and the GitHub Release is
# still created; only the upload step is skipped.
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build sdist and wheel
run: |
python -m pip install --upgrade pip
pip install build twine
python -m build
twine check dist/*
- name: Detect PyPI token
id: token
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
if [ -n "$PYPI_API_TOKEN" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
else
echo "present=false" >> "$GITHUB_OUTPUT"
echo "PYPI_API_TOKEN not set - skipping PyPI upload." >&2
fi
- name: Publish to PyPI
if: steps.token.outputs.present == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload --non-interactive dist/*
- name: Extract changelog section for this version
id: changelog
run: |
VERSION="${GITHUB_REF_NAME#v}"
if [ -f CHANGELOG.md ]; then
awk -v ver="$VERSION" '
$0 ~ ("^## \\[" ver "\\]") { capture = 1; next }
capture && /^## \[/ { exit }
capture { print }
' CHANGELOG.md > release-notes.md
fi
if [ ! -s release-notes.md ]; then
echo "Release v${VERSION}. See the full changelog in CHANGELOG.md." > release-notes.md
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: release-notes.md
generate_release_notes: true