Skip to content

Commit 32dfb3a

Browse files
committed
Updated CI/CD pipeline
1 parent 2cb0fcb commit 32dfb3a

1 file changed

Lines changed: 53 additions & 5 deletions

File tree

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
# .github/workflows/python-package.yml
2+
13
name: CI
24

35
on:
46
push:
5-
branches: [ main ]
7+
# run on every branch – test job will always run, publish only on main
8+
branches: ['*']
69
pull_request:
7-
branches: [ main ]
10+
branches: ['*']
11+
workflow_dispatch:
12+
inputs:
13+
publish_to:
14+
description: 'Where to publish package'
15+
required: true
16+
default: 'pypi'
17+
type: choice
18+
options:
19+
- pypi
20+
- testpypi
821

922
jobs:
10-
build:
23+
test:
24+
name: Run tests
1125
runs-on: ubuntu-latest
1226
steps:
1327
- uses: actions/checkout@v4
@@ -19,6 +33,40 @@ jobs:
1933
run: |
2034
python -m pip install --upgrade pip
2135
pip install -r requirements.txt
22-
- name: Run tests
36+
- name: Run pytest
37+
run: python -m pytest -q
38+
39+
publish:
40+
name: Build & publish
41+
needs: test
42+
runs-on: ubuntu-latest
43+
# only run automatically when main is updated, or when the workflow
44+
# is manually dispatched (for dev/test uploads)
45+
if: >
46+
github.ref == 'refs/heads/main' ||
47+
github.event_name == 'workflow_dispatch'
48+
environment:
49+
# optional: create a "production" / "dev" environment in repo settings
50+
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'dev' }}
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Set up Python
54+
uses: actions/setup-python@v4
55+
with:
56+
python-version: '3.11'
57+
- name: Build wheel/sdist
58+
run: |
59+
python -m pip install --upgrade build
60+
python -m build
61+
- name: Publish to PyPI/TestPyPI
2362
run: |
24-
python -m pytest -q
63+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && \
64+
[ "${{ github.event.inputs.publish_to }}" = "testpypi" ]; then
65+
repo="https://test.pypi.org/legacy/"
66+
token="${{ secrets.TEST_PYPI_API_TOKEN }}"
67+
else
68+
repo="https://upload.pypi.org/legacy/"
69+
token="${{ secrets.PYPI_API_TOKEN }}"
70+
fi
71+
python -m pip install --upgrade twine
72+
python -m twine upload --repository-url "$repo" -u __token__ -p "$token" dist/*

0 commit comments

Comments
 (0)