-
Notifications
You must be signed in to change notification settings - Fork 1
66 lines (56 loc) · 1.88 KB
/
deploy.yml
File metadata and controls
66 lines (56 loc) · 1.88 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
name: Deploy to PyPI
on:
workflow_run:
workflows: ["Bump Version"]
types:
- completed
workflow_dispatch:
permissions:
contents: write
jobs:
build-and-deploy:
if: >
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine toml
- name: Clean previous builds
run: |
rm -rf dist/ build/ *.egg-info
python -m pip uninstall -y your-package-name || true
- name: Build the package
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*
- name: Create Git tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
git config user.name "github-actions"
git config user.email "github-actions@github.com"
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "Tag v$VERSION already exists"
else
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
fi
if gh release view "v$VERSION" >/dev/null 2>&1; then
echo "Release v$VERSION already exists"
else
gh release create "v$VERSION" --title "Release v$VERSION" --notes "Automated release for version v$VERSION" dist/*
fi