-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (58 loc) · 1.97 KB
/
pypi.yml
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
name: Publish Python Package
on:
push:
branches:
- main
paths:
- 'setup.py'
jobs:
check-version-changed:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.version-change.outputs.version_changed }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Fetch all history for all tags and branches
run: git fetch --unshallow
- name: Check if version changed
id: version-change
run: |
# Get the latest commit on main before the merge
MAIN_COMMIT=$(git rev-parse origin/main^1)
# Get the version from the main branch before the merge
MAIN_VERSION=$(git show "$MAIN_COMMIT:setup.py" | grep -Po "version='\K.*?(?=')")
# Get the version from the latest commit on the incoming branch
HEAD_VERSION=$(grep -Po "version='\K.*?(?=')" setup.py)
echo "Main version: $MAIN_VERSION"
echo "Head version: $HEAD_VERSION"
# Compare versions
if [ "$MAIN_VERSION" != "$HEAD_VERSION" ]; then
echo "Version changed"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version not changed"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
publish:
needs: check-version-changed
if: needs.check-version-changed.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*