Skip to content

Commit e5c9636

Browse files
committed
fix: update workflow triggers
1 parent a436859 commit e5c9636

1 file changed

Lines changed: 37 additions & 16 deletions

File tree

.github/workflows/publish-to-pypi.yml

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
# PyPI Trusted Publishing: https://docs.pypi.org/trusted-publishers/
33
name: Publish Python distribution to PyPI and TestPyPI
44

5-
on: push
5+
on:
6+
push:
7+
branches: ["**"] # run tests on any branch push
8+
release:
9+
types: [published] # publish to PyPI when a GitHub release is published
610

711
jobs:
8-
build:
9-
name: Build distribution
12+
test:
13+
name: Run tests
1014
runs-on: ubuntu-latest
1115

1216
steps:
@@ -28,6 +32,22 @@ jobs:
2832
- name: Run tests
2933
run: pytest tests/ -v
3034

35+
build:
36+
name: Build distribution
37+
needs: [test]
38+
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
persist-credentials: false
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: "3.12"
50+
3151
- name: Install pypa/build
3252
run: pip install build
3353

@@ -40,14 +60,14 @@ jobs:
4060
name: python-package-distributions
4161
path: dist/
4262

43-
publish-to-pypi:
44-
name: Publish to PyPI
45-
if: startsWith(github.ref, 'refs/tags/')
63+
publish-to-testpypi:
64+
name: Publish to TestPyPI
65+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
4666
needs: [build]
4767
runs-on: ubuntu-latest
4868
environment:
49-
name: pypi
50-
url: https://pypi.org/project/ratemyprofessors-client/
69+
name: testpypi
70+
url: https://test.pypi.org/project/ratemyprofessors-client/
5171
permissions:
5272
id-token: write
5373

@@ -57,16 +77,19 @@ jobs:
5777
with:
5878
name: python-package-distributions
5979
path: dist/
60-
- name: Publish distribution to PyPI
80+
- name: Publish distribution to TestPyPI
6181
uses: pypa/gh-action-pypi-publish@release/v1
82+
with:
83+
repository-url: https://test.pypi.org/legacy/
6284

63-
publish-to-testpypi:
64-
name: Publish to TestPyPI
85+
publish-to-pypi:
86+
name: Publish to PyPI
87+
if: github.event_name == 'release'
6588
needs: [build]
6689
runs-on: ubuntu-latest
6790
environment:
68-
name: testpypi
69-
url: https://test.pypi.org/project/ratemyprofessors-client/
91+
name: pypi
92+
url: https://pypi.org/project/ratemyprofessors-client/
7093
permissions:
7194
id-token: write
7295

@@ -76,7 +99,5 @@ jobs:
7699
with:
77100
name: python-package-distributions
78101
path: dist/
79-
- name: Publish distribution to TestPyPI
102+
- name: Publish distribution to PyPI
80103
uses: pypa/gh-action-pypi-publish@release/v1
81-
with:
82-
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)