Skip to content

Commit 913ed97

Browse files
author
Alex J Lennon
committed
Separate build and publish workflows, create PyPI environment
1 parent eeb5cad commit 913ed97

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ name: Build Package
22

33
on:
44
push:
5+
branches: [main]
56
tags:
67
- 'v*'
8+
pull_request:
9+
branches: [main]
710
workflow_dispatch:
811

912
jobs:
@@ -34,14 +37,6 @@ jobs:
3437
- name: Upload artifacts
3538
uses: actions/upload-artifact@v4
3639
with:
37-
name: dist
40+
name: python-package-distributions
3841
path: dist/
3942

40-
- name: Publish to PyPI (on tag)
41-
if: startsWith(github.ref, 'refs/tags/v')
42-
env:
43-
TWINE_USERNAME: __token__
44-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
45-
run: |
46-
python -m twine upload dist/*
47-

.github/workflows/publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version tag (e.g., v0.1.0)'
10+
required: true
11+
type: string
12+
13+
jobs:
14+
publish-pypi:
15+
runs-on: ubuntu-latest
16+
environment:
17+
name: pypi
18+
url: https://pypi.org/p/lab-testing
19+
permissions:
20+
id-token: write # IMPORTANT: this permission is needed for trusted publishing
21+
22+
steps:
23+
- name: Download all dists
24+
uses: actions/download-artifact@v4
25+
with:
26+
name: python-package-distributions
27+
path: dist/
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Publish package to PyPI
31+
uses: pypa/gh-action-pypi-publish@release/v1
32+

0 commit comments

Comments
 (0)