-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (87 loc) · 3.02 KB
/
python-release.yml
File metadata and controls
100 lines (87 loc) · 3.02 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Python Release
on:
push:
tags:
- 'v*'
jobs:
test:
uses: ./.github/workflows/python-tests.yml
release:
needs: test
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write # Required for PyPI's trusted publishing
contents: write # Required for creating GitHub releases
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
cache: 'pip'
cache-dependency-path: 'poetry.lock'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Extract version from tag
id: get_version
run: |
# Remove 'v' prefix from tag name
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Extract content from CHANGELOG.md for this version
echo "Searching for version: ## [$VERSION]"
# Include the version header in extracted content
CHANGELOG_CONTENT=$(awk -v ver="## \\[$VERSION\\]" '
$0 ~ ver {print; flag=1; next}
/^## \[[0-9]+\.[0-9]+\.[0-9]+\]/ {flag=0}
flag {print}
' CHANGELOG.md)
# Log extracted content for debugging
echo "Extracted changelog content:"
echo "$CHANGELOG_CONTENT"
# Handle empty changelog case
if [ -z "$CHANGELOG_CONTENT" ]; then
CHANGELOG_CONTENT="Release version $VERSION"
fi
# Set the changelog content for GitHub release
echo "CHANGELOG_CONTENT<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG_CONTENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Verify versions match
run: |
# Check version in pyproject.toml
PYPROJECT_VERSION=$(grep -oP '^version = "\K[^"]+' pyproject.toml)
# Check version in __init__.py
INIT_VERSION=$(grep -oP '__version__ = "\K[^"]+' webdown/__init__.py)
if [ "$PYPROJECT_VERSION" != "$VERSION" ] || [ "$INIT_VERSION" != "$VERSION" ]; then
echo "Version mismatch detected:"
echo "Tag version: $VERSION"
echo "pyproject.toml version: $PYPROJECT_VERSION"
echo "__init__.py version: $INIT_VERSION"
exit 1
fi
echo "All versions match: $VERSION"
- name: Build package
run: |
poetry build
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Version ${{ env.VERSION }}
body: ${{ env.CHANGELOG_CONTENT }}
draft: false
prerelease: false
files: |
dist/*.whl
dist/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true