-
Notifications
You must be signed in to change notification settings - Fork 8
54 lines (51 loc) · 1.65 KB
/
publish-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
name: PyPI release
on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
jobs:
build-and-publish:
# Skip job on forks
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
name: Build and publish to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-publish-pypi-${{ hashFiles('poetry.lock') }}
- name: Setup poetry environment
run: |
poetry install
- name: Inject package versions to action env
run: make inject-version
- name: Set Python package version for release
if: startsWith(github.ref, 'refs/tags/v')
run: poetry version "${PYVERSION}"
- name: Set Python package version
if: "!startsWith(github.ref, 'refs/tags/v')"
run: |
poetry version "${PYVERSION}.dev${GITHUB_RUN_NUMBER}"
- name: Build Python package
run: poetry build
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/v')
run: poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }}
- name: Publish to TestPyPI
if: "!startsWith(github.ref, 'refs/tags/v')"
run: |
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish -r test-pypi -u __token__ -p ${{ secrets.TEST_PYPI_TOKEN }}