Skip to content

Commit 1cd5393

Browse files
committed
ci(workflows): fix duplicate release, and use changelog for release notes
1 parent 0711683 commit 1cd5393

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

.github/workflows/release.yml

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ name: Release
33
on:
44
push:
55
branches: [main]
6+
release:
7+
types: [published]
68
workflow_dispatch:
79

810
# ┌─────────────────────────────────────────────────────────────────┐
911
# │ DRAFT_RELEASE │
1012
# │ │
11-
# │ "true" → GitHub Releases are created as drafts and PyPI
12-
#publishing is skipped (burn-in / review period). │
13-
# │ "false" → GitHub Releases are published immediately and the
14-
#package is uploaded to PyPI.
13+
# │ "true" → GitHub Releases are created as drafts; review them
14+
#on GitHub, then click "Publish" to trigger PyPI. │
15+
# │ "false" → GitHub Releases are published immediately, which
16+
#automatically triggers the PyPI publish job.
1517
# │ │
16-
# │ Flip to "false" once you have verified the release output.
18+
# │ Flip to "false" once you are comfortable with the pipeline.
1719
# └─────────────────────────────────────────────────────────────────┘
1820
env:
1921
DRAFT_RELEASE: "true"
@@ -22,9 +24,7 @@ jobs:
2224
release:
2325
name: Semantic Release
2426
runs-on: ubuntu-latest
25-
if: >-
26-
github.event_name == 'workflow_dispatch' ||
27-
!startsWith(github.event.head_commit.message, 'chore(release):')
27+
if: github.event_name != 'release'
2828
concurrency:
2929
group: release
3030
cancel-in-progress: false
@@ -51,11 +51,21 @@ jobs:
5151
uses: python-semantic-release/python-semantic-release@v9
5252
with:
5353
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
vcs_release: "false"
5455

5556
- name: Build package
5657
if: steps.release.outputs.released == 'true'
5758
run: python -m build
5859

60+
- name: Extract changelog for this release
61+
if: steps.release.outputs.released == 'true'
62+
id: changelog
63+
run: |
64+
TAG="${{ steps.release.outputs.tag }}"
65+
VER="${TAG#v}"
66+
# Extract the section between this version's header and the next
67+
awk "/^## v${VER//./\\.} /{found=1; next} /^## v[0-9]/{if(found) exit} found" CHANGELOG.md > /tmp/release_notes.md
68+
5969
- name: Create GitHub Release
6070
if: steps.release.outputs.released == 'true'
6171
env:
@@ -67,11 +77,39 @@ jobs:
6777
gh release create "${{ steps.release.outputs.tag }}" \
6878
${DRAFT_FLAG:-} \
6979
--title "${{ steps.release.outputs.tag }}" \
70-
--generate-notes \
80+
--notes-file /tmp/release_notes.md \
7181
dist/*
7282
73-
- name: Publish to PyPI
83+
- name: Publish to PyPI (non-draft)
7484
if: steps.release.outputs.released == 'true' && env.DRAFT_RELEASE != 'true'
7585
uses: pypa/gh-action-pypi-publish@release/v1
7686
with:
7787
skip-existing: true
88+
89+
pypi-publish:
90+
name: Publish to PyPI
91+
runs-on: ubuntu-latest
92+
if: github.event_name == 'release' && github.event.action == 'published'
93+
permissions:
94+
id-token: write
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v4
98+
with:
99+
ref: ${{ github.event.release.tag_name }}
100+
101+
- name: Set up Python
102+
uses: actions/setup-python@v5
103+
with:
104+
python-version: '3.12'
105+
106+
- name: Install build tools
107+
run: python -m pip install -U pip build
108+
109+
- name: Build package
110+
run: python -m build
111+
112+
- name: Publish to PyPI
113+
uses: pypa/gh-action-pypi-publish@release/v1
114+
with:
115+
skip-existing: true

0 commit comments

Comments
 (0)