-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (68 loc) · 2.13 KB
/
python-package.yml
File metadata and controls
72 lines (68 loc) · 2.13 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
# .github/workflows/python-package.yml
name: CI
on:
push:
# run tests on every branch and publish only when a tag is created
branches: ['*']
tags: ['*'] # trigger on any tag push (e.g. v0.1.5)
pull_request:
branches: ['*']
workflow_dispatch:
inputs:
publish_to:
description: 'Where to publish package'
required: true
default: 'pypi'
type: choice
options:
- pypi
- testpypi
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run pytest
run: python -m pytest -q
publish:
name: Build & publish
needs: test
runs-on: ubuntu-latest
# only run automatically when a tag is pushed, or when manually dispatched
if: >
startsWith(github.ref, 'refs/tags/') ||
github.event_name == 'workflow_dispatch'
environment:
# optional: use a production environment for real releases
name: ${{ startsWith(github.ref, 'refs/tags/') && 'production' || 'dev' }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Build wheel/sdist
run: |
python -m pip install --upgrade build
python -m build
- name: Publish to PyPI/TestPyPI
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && \
[ "${{ github.event.inputs.publish_to }}" = "testpypi" ]; then
repo="https://test.pypi.org/legacy/"
token="${{ secrets.TEST_PYPI_API_TOKEN }}"
else
repo="https://upload.pypi.org/legacy/"
token="${{ secrets.PYPI_API_TOKEN }}"
fi
python -m pip install --upgrade twine
python -m twine upload --repository-url "$repo" -u __token__ -p "$token" dist/*