Skip to content

Commit

Permalink
CI: Separate jobs for publishing to TestPyPI and PyPI (#3742) (#3772)
Browse files Browse the repository at this point in the history
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
  • Loading branch information
seisman and weiji14 authored Jan 17, 2025
1 parent 2a84b5e commit dd66477
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/checkout@v4.2.2
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5.3.0
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/upload-artifact@v4.5.0
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/download-artifact@v4.1.8
with:
name: python-package-distributions
path: dist/

- name: Publish distribution πŸ“¦ to TestPyPI
uses: pypa/gh-action-pypi-publish@v1.12.3
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/download-artifact@v4.1.8
with:
name: python-package-distributions
path: dist/

- name: Publish distribution πŸ“¦ to PyPI
uses: pypa/gh-action-pypi-publish@v1.12.3

0 comments on commit dd66477

Please sign in to comment.