-
Notifications
You must be signed in to change notification settings - Fork 224
124 lines (110 loc) · 3.6 KB
/
publish-to-pypi.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Publish archives to PyPI and TestPyPI using GitHub Actions
#
# This workflow is ran to publish PyGMT archives (source and binary distributions)
# to TestPyPI (for testing only) and PyPI.
#
# Archives will be pushed to TestPyPI for every commit to the main branch and
# tagged releases, and to PyPI for tagged releases only.
#
# Note that authentication to TestPyPI/PyPI is done via OpenID Connect, see also
# https://github.com/pypa/gh-action-pypi-publish/tree/release/v1#publishing-with-openid-connect
#
# Important: this workflow filename must be publish-to-pypi.yml to match the
# settings in PyPI and TestPyPI so that OIDC publishing works.
#
name: Publish to PyPI
# Only run for pushes to the main branch and releases.
on:
push:
branches: [ main ]
paths:
- 'pygmt/**'
- '!pygmt/tests/**'
- 'Makefile'
- 'MANIFEST.in'
- 'pyproject.toml'
- 'README.md'
- '.github/workflows/publish-to-pypi.yml'
release:
types:
- published
# Runs for pull requests should be disabled other than for testing purposes
#pull_request:
# branches:
# - main
jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest
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
with:
python-version: '3.13'
- name: Install dependencies
run: python -m pip install build
# This step is only necessary for testing purposes and for TestPyPI
- name: Fix up version string for TestPyPI
if: ${{ !startsWith(github.ref, 'refs/tags') }}
run: |
# Change setuptools-scm local_scheme to "no-local-version" so the
# local part of the version isn't included, making the version string
# compatible with PyPI.
sed --in-place "s/node-and-date/no-local-version/g" pyproject.toml
- name: Build source and wheel distributions
run: |
make package
echo ""
echo "Generated files:"
ls -lh dist/
- 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/
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