This repository was archived by the owner on Apr 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (95 loc) · 3.44 KB
/
publish.yml
File metadata and controls
114 lines (95 loc) · 3.44 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# This workflow will upload a Python Package to PyPI when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Upload Python Package
on:
workflow_run:
workflows: ["Auto Release"]
types:
- completed
permissions:
contents: read
jobs:
check-workflow:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
version: ${{ steps.get-version.outputs.version }}
should_publish: ${{ steps.check-release.outputs.should_publish }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_branch }}
- name: Get version from pyproject.toml
id: get-version
run: |
VERSION=$(grep -m 1 "^version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Check if release should be published
id: check-release
run: |
# Check if most recent commit was a version bump
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" =~ [Bb][Uu][Mm][Pp]\ [Vv][Ee][Rr][Ss][Ii][Oo][Nn] ]]; then
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "Version bump detected, should publish to PyPI"
else
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "Not a version bump commit, skipping PyPI publishing"
fi
- name: Debug workflow info
run: |
echo "Auto-Release workflow completed successfully"
echo "Version to publish: ${{ steps.get-version.outputs.version }}"
echo "Should publish: ${{ steps.check-release.outputs.should_publish }}"
release-build:
runs-on: ubuntu-latest
needs: check-workflow
if: ${{ needs.check-workflow.outputs.should_publish == 'true' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Build release distributions
run: |
uv build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
pypi-publish:
runs-on: ubuntu-latest
needs:
- check-workflow
- release-build
if: ${{ needs.check-workflow.outputs.should_publish == 'true' }}
environment:
name: pypi
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: dist/
verbose: true
- name: Publish success
run: |
echo "✅ Successfully published version ${{ needs.check-workflow.outputs.version }} to PyPI"