Skip to content

Commit aa254df

Browse files
Added separate distinction code for prereleases
- Releases will bei uploaded to PyPi Test and Prod - Prereleases will only be uploaded to PyPi Test
1 parent 11a87a0 commit aa254df

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

publish-to-pypi.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@
4343

4444
name: Upload Python Package
4545

46+
# Note: This job will be triggered for both releases and prereleases
47+
# Releases will be pushed to both PyPi Test AND Prod whereas
48+
# prereleases will only be pushed to PyPi Test
49+
# Github Actions offers only ONE trigger for releases, meaning that
50+
# the decision on to which site will be uploaded to will be made at
51+
# the respective sub branch.
52+
4653
on:
4754
release:
4855
types: [published]
49-
# push:
5056

5157
#
5258
# Configuration section - change values if necessary
@@ -75,7 +81,7 @@ jobs:
7581
# new release. Check if Github release version is equal to the one
7682
# extracted from the Python file. Ultimately, forward version information
7783
# to next Github Actions job in line.
78-
update-version:
84+
get-python-version-info:
7985
runs-on: ubuntu-latest
8086

8187
# Output which is passed to the PyPi publication job
@@ -147,7 +153,7 @@ jobs:
147153
#
148154
deploy-to-pypi:
149155
runs-on: ubuntu-latest
150-
needs: update-version
156+
needs: get-python-version-info
151157

152158
steps:
153159

@@ -166,21 +172,19 @@ jobs:
166172
# Build the package. The export MUST be part of THIS step
167173
# Otherwise, the Python setup job will not see this information
168174
- name: Build package
169-
run: export GITHUB_PROGRAM_VERSION='${{ needs.update-version.outputs.my-program-version }}';python -m build
175+
run: export GITHUB_PROGRAM_VERSION='${{ needs.get-python-version-info.outputs.my-program-version }}';python -m build
170176
# Publish everything to Test PyPi
177+
# Unlike for the Prod branch, we will push both releases and prerelease to PyPi Test
171178
- name: Publish package to Test PyPi
179+
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags')
172180
uses: pypa/gh-action-pypi-publish@release/v1
173181
with:
174182
user: __token__
175183
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
176184
repository_url: https://test.pypi.org/legacy/
177-
# Publish everything to Prod PyPi
178-
# If you use job action 'on -> release -> types[published]' at the
179-
# beginning of this file, then the 'if' statement is not really
180-
# necessary. I'll keep this one as safeguard for testing in
181-
# case this Github action is triggered via 'on -> push'
185+
# Publish everything to Prod PyPi but only if it is not a prerelease
182186
- name: Publish package to Prod PyPi
183-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
187+
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags') && !github.event.release.prerelease
184188
uses: pypa/gh-action-pypi-publish@release/v1
185189
with:
186190
user: __token__

0 commit comments

Comments
 (0)