-
Notifications
You must be signed in to change notification settings - Fork 47
79 lines (65 loc) · 2.26 KB
/
release.yml
File metadata and controls
79 lines (65 loc) · 2.26 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
name: Create Release and Publish
on:
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
environment: pypi
outputs:
version: ${{ steps.changelog.outputs.version }}
released: ${{ steps.check_tag.outputs.exists == 'false' }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Extract version and notes from CHANGELOG
id: changelog
run: |
# Extract version from first ## [x.x.x] header
VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md)
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Extract release notes (content between first and second ## headers)
NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
# Handle multiline output
{
echo "notes<<EOF"
echo "$NOTES"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Check if tag already exists
id: check_tag
run: |
if git rev-parse "v${{ steps.changelog.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
if: steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.changelog.outputs.version }}
name: v${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.notes }}
draft: false
prerelease: false
- name: Skip release (tag exists)
if: steps.check_tag.outputs.exists == 'true'
run: |
echo "⚠️ Tag v${{ steps.changelog.outputs.version }} already exists. Skipping release creation."
exit 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1