-
Notifications
You must be signed in to change notification settings - Fork 36
81 lines (67 loc) · 2.15 KB
/
publish-to-pypi.yml
File metadata and controls
81 lines (67 loc) · 2.15 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
# workflow automates the Python package publishing process
# to PyPI upon pushes to the main branch or manual triggers,
# auto-bumps version before publishing.
name: Publish to PyPI
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'pyproject.toml'
- 'setup.py'
workflow_dispatch:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Get current version from PyPI
run: |
current_version=$(pip index versions VedAstro 2>/dev/null | head -1 | grep -oP '\(\K[^)]+' || echo "0.0.0")
echo "CURRENT_VERSION=$current_version" >> $GITHUB_ENV
- name: Bump version
run: |
IFS=. read -r major minor patch <<< "${CURRENT_VERSION}"
patch=$((patch + 1))
new_version="${major}.${minor}.${patch}"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: Update version in pyproject.toml
run: |
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
- name: Update version in setup.py
run: |
sed -i "s/version='.*'/version='$NEW_VERSION'/" setup.py
- name: Re-run poetry lockfile
run: poetry lock
- name: Install project dependencies
run: poetry install
- name: Build package
run: poetry build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- name: Commit version bump
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml setup.py
git commit -m "Auto bump version to $NEW_VERSION"
git push origin main