-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (136 loc) · 4.5 KB
/
python-publish.yml
File metadata and controls
162 lines (136 loc) · 4.5 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Publish Python Package to PyPI
on:
push:
branches:
- main
paths:
- "flowquery-py/src/**"
release:
types: [published]
workflow_dispatch:
inputs:
target:
description: "Publish target"
required: true
default: "testpypi"
type: choice
options:
- testpypi
- pypi
permissions:
contents: write
jobs:
bump-version:
name: Bump version
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
concurrency:
group: flowquery-pypi-${{ github.ref_name }}
cancel-in-progress: false
outputs:
new_version: ${{ steps.bump.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
- name: Bump Python package version
id: bump
working-directory: flowquery-py
run: |
# Get current version from pyproject.toml
CURRENT=$(grep -Po '(?<=^version = ")[^"]+' pyproject.toml)
echo "Current version: $CURRENT"
# Parse and bump patch version
IFS='.' read -r major minor patch <<< "$CURRENT"
NEW_VERSION="$major.$minor.$((patch + 1))"
echo "New version: $NEW_VERSION"
# Update pyproject.toml
sed -i "s/^version = \"$CURRENT\"/version = \"$NEW_VERSION\"/" pyproject.toml
# Commit and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore(py): bump version to $NEW_VERSION [skip ci]"
for attempt in 1 2 3; do
git fetch origin main:refs/remotes/origin/main
if ! git rebase origin/main; then
git rebase --abort || true
elif git push origin HEAD:main; then
break
fi
if [ "$attempt" -eq 3 ]; then
echo "Failed to push Python version bump after 3 attempts."
exit 1
fi
sleep 5
done
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
build:
name: Build distribution
needs: [bump-version]
if: always() && (needs.bump-version.result == 'success' || needs.bump-version.result == 'skipped')
runs-on: ubuntu-latest
defaults:
run:
working-directory: flowquery-py
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Pull latest changes
if: needs.bump-version.result == 'success'
run: git pull origin main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build dependencies
run: pip install build
- name: Build package
run: python -m build
- name: Upload distribution artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: flowquery-py/dist/
publish-testpypi:
name: Publish to TestPyPI
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi'
needs: build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/flowquery
steps:
- name: Download distribution artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
trusted-publisher: false
publish-pypi:
name: Publish to PyPI
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'pypi')
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/flowquery
steps:
- name: Download distribution artifacts
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
trusted-publisher: false