-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (93 loc) · 3.04 KB
/
pypi-release.yml
File metadata and controls
104 lines (93 loc) · 3.04 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
name: Publish Python 🐍 distributions 📦 to PyPI
# name: Bump Version and Create PR
on:
push:
branches:
- master
workflow_dispatch:
inputs:
release_type:
description: 'Release type (patch, minor, major)'
required: true
default: patch
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install bump2version
run: pip install bump2version
- name: Determine bump type
id: set_bump_type
run: |
# Set the bump type based on input or default to patch
if [[ "${{ github.event.inputs.bump_type }}" != "" ]]; then
echo "bump_type=${{ github.event.inputs.bump_type }}" >> $GITHUB_ENV
else
echo "bump_type=patch" >> $GITHUB_ENV
fi
shell: bash
- name: Bump the version
id: bump_version
run: |
echo "Current version: $(cat VERSION)"
bump2version ${{ env.bump_type }} --allow-dirty --current-version $(cat VERSION) VERSION
echo "New version: $(cat VERSION)"
echo "version=$(cat VERSION)" >> $GITHUB_ENV
- name: Commit version bump
run: |
git config user.name "GitHub Actions Bot"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add VERSION
git commit -m "Bump version to ${{ env.version }}"
git push origin HEAD:${GITHUB_REF#refs/heads/}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Publish to PyPI (Optional)
# if: ${{ github.ref_name == 'master' }}
# uses: pypa/gh-action-pypi-publish@v1
# with:
# username: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
build-and-publish-test-pypi:
needs: bump-version
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: pip install setuptools wheel twine
- name: Build and publish to TestPyPI
run: |
python setup.py sdist bdist_wheel
twine upload --repository-url https://test.pypi.org/legacy/ dist/* -u __token__ -p ${{ secrets.TEST_PYPI_API_TOKEN }}
build-and-publish-pypi:
needs: build-and-publish-test-pypi
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: pip install setuptools wheel twine
- name: Build and publish to PyPI
run: |
python setup.py sdist bdist_wheel
twine upload dist/* -u __token__ -p ${{ secrets.PYPI_API_TOKEN }}