Skip to content

Commit

Permalink
CI: Separate jobs for publishing to TestPyPI and PyPI (#3742)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 authored Jan 9, 2025
1 parent 9e912ba commit 5041384
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,17 @@ on:
# - main

jobs:
publish-pypi:
name: Publish to PyPI
build:
name: Build distribution πŸ“¦
runs-on: ubuntu-latest
permissions:
# This permission is mandatory for OIDC publishing
id-token: write
if: github.repository == 'GenericMappingTools/pygmt'

steps:
- name: Checkout
uses: actions/[email protected]
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0
persist-credentials: false

- name: Set up Python
uses: actions/[email protected]
Expand All @@ -74,11 +71,54 @@ jobs:
echo "Generated files:"
ls -lh dist/
- name: Publish to Test PyPI
- name: Store the distribution packages
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution πŸ“¦ to TestPyPI
if: github.repository == 'GenericMappingTools/pygmt'
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/project/pygmt
permissions:
id-token: write # IMPORTANT: mandatory for trusted OIDC publishing

steps:
- name: Download all the dists
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/

- name: Publish distribution πŸ“¦ to TestPyPI
uses: pypa/[email protected]
with:
repository-url: https://test.pypi.org/legacy/

- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
publish-pypi:
name: Publish Python 🐍 distribution πŸ“¦ to PyPI
if: github.repository == 'GenericMappingTools/pygmt' && startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/pygmt/
permissions:
id-token: write # IMPORTANT: mandatory for trusted OIDC publishing

steps:
- name: Download all the dists
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/

- name: Publish distribution πŸ“¦ to PyPI
uses: pypa/[email protected]

0 comments on commit 5041384

Please sign in to comment.