Skip to content

Commit 7c121a5

Browse files
committed
Refactor GitHub Actions workflow for PyPI publishing
- Simplified the workflow by removing the TestPyPI publishing step and associated conditions. - Streamlined the environment input options for manual deployment. - Ensured consistent formatting and indentation across steps for better readability. - Maintained the core functionality for building and publishing to PyPI.
1 parent 117b252 commit 7c121a5

1 file changed

Lines changed: 30 additions & 64 deletions

File tree

.github/workflows/publish.yml

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,54 @@
1-
name: Publish to PyPI (Token)
1+
name: Publish to PyPI
22

33
on:
44
release:
55
types: [published]
6-
push:
7-
tags:
8-
- 'v*-test' # Trigger TestPyPI on tags like v0.1.0-test
96
workflow_dispatch:
10-
inputs:
11-
environment:
12-
description: 'Environment to deploy to'
13-
required: true
14-
default: 'testpypi'
15-
type: choice
16-
options:
17-
- testpypi
18-
- pypi
197

208
jobs:
219
build:
2210
name: Build distribution
2311
runs-on: ubuntu-latest
2412

2513
steps:
26-
- name: Checkout code
27-
uses: actions/checkout@v4
14+
- name: Checkout code
15+
uses: actions/checkout@v4
2816

29-
- name: Set up Python
30-
uses: actions/setup-python@v4
31-
with:
32-
python-version: '3.11'
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.11"
3321

34-
- name: Install build dependencies
35-
run: |
36-
python -m pip install --upgrade pip
37-
pip install build twine
22+
- name: Install build dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build twine
3826
39-
- name: Build package
40-
run: python -m build
27+
- name: Build package
28+
run: python -m build
4129

42-
- name: Check package
43-
run: twine check dist/*
30+
- name: Check package
31+
run: twine check dist/*
4432

45-
- name: Upload artifacts
46-
uses: actions/upload-artifact@v4
47-
with:
48-
name: python-package-distributions
49-
path: dist/
50-
51-
publish-to-testpypi:
52-
name: Publish to TestPyPI
53-
if: |
54-
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'testpypi') ||
55-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && contains(github.ref, '-test'))
56-
needs: [build]
57-
runs-on: ubuntu-latest
58-
59-
steps:
60-
- name: Download artifacts
61-
uses: actions/download-artifact@v4
62-
with:
63-
name: python-package-distributions
64-
path: dist/
65-
66-
- name: Publish to TestPyPI
67-
uses: pypa/gh-action-pypi-publish@release/v1
68-
with:
69-
repository-url: https://test.pypi.org/legacy/
70-
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
33+
- name: Upload artifacts
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: python-package-distributions
37+
path: dist/
7138

7239
publish-to-pypi:
7340
name: Publish to PyPI
74-
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi')
7541
needs: [build]
7642
runs-on: ubuntu-latest
7743

7844
steps:
79-
- name: Download artifacts
80-
uses: actions/download-artifact@v4
81-
with:
82-
name: python-package-distributions
83-
path: dist/
84-
85-
- name: Publish to PyPI
86-
uses: pypa/gh-action-pypi-publish@release/v1
87-
with:
88-
password: ${{ secrets.PYPI_API_TOKEN }}
45+
- name: Download artifacts
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: python-package-distributions
49+
path: dist/
50+
51+
- name: Publish to PyPI
52+
uses: pypa/gh-action-pypi-publish@release/v1
53+
with:
54+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)