Skip to content

Commit 328bf9e

Browse files
authored
Merge pull request ckan#8520 from ckan/automate-pypi
Automate publication of ckan package to PyPI
2 parents 4d5c4f6 + 89c2b5b commit 328bf9e

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Publish to PyPI and TestPyPI
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
name: Build distribution
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Set up Python
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.9"
16+
- name: Install pypa/build
17+
run: >-
18+
python3 -m
19+
pip install
20+
build
21+
--user
22+
- name: Build a binary wheel and a source tarball
23+
run: python3 -m build
24+
- name: Store the distribution packages
25+
uses: actions/upload-artifact@v3
26+
with:
27+
name: python-package-distributions
28+
path: dist/
29+
30+
publish-to-pypi:
31+
name: Publish Python distribution on PyPI
32+
# Publish to PyPI when pushing a tag
33+
if: startsWith(github.ref, 'refs/tags/')
34+
needs:
35+
- build
36+
runs-on: ubuntu-latest
37+
environment:
38+
name: pypi
39+
url: https://pypi.org/p/ckan
40+
permissions:
41+
id-token: write
42+
steps:
43+
- name: Download all the dists
44+
uses: actions/download-artifact@v3
45+
with:
46+
name: python-package-distributions
47+
path: dist/
48+
- name: Publish distribution to PyPI
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
51+
publish-to-testpypi:
52+
name: Publish Python distribution on TestPyPI
53+
# Publish to Test PyPI when a pull request is merged
54+
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
55+
needs:
56+
- build
57+
runs-on: ubuntu-latest
58+
environment:
59+
name: pypi
60+
url: https://test.pypi.org/p/ckan
61+
permissions:
62+
id-token: write
63+
steps:
64+
- name: Download all the dists
65+
uses: actions/download-artifact@v3
66+
with:
67+
name: python-package-distributions
68+
path: dist/
69+
- name: Publish distribution to PyPI
70+
uses: pypa/gh-action-pypi-publish@release/v1
71+
with:
72+
repository-url: https://test.pypi.org/legacy/

changes/8520.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Automate publishing CKAN package to PyPI

doc/contributing/maintenance-tools.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,29 @@ When creating a new PAT, make sure to select the following settings:
6060
* Repository permissions: Select *Content* (Read and Write) and *Pull Requests* (Read and Write)
6161

6262
Once generated the token, it will have to be approved by someone with permissions in the *@ckan* organization (by going to Settings > Third-party Access > Personal access tokens > Pending requests).
63+
64+
65+
----------------------------
66+
Automatic publishing to PyPI
67+
----------------------------
68+
69+
70+
.. note:: Automatic publishing to PyPI was added on November 2024
71+
72+
The main CKAN repo has a GitHub workflow that allows to publish to
73+
74+
* PyPI when a tag is pushed
75+
* Test PyPI when a PR is merged (Using test.pypi.org allows us to check that
76+
the workflow is healthy).
77+
78+
Besides the workflow file there are two additional configurations needed:
79+
80+
* `GitHub Actions environmnents`_: This allows us to define additional rules
81+
and limit how actions are run.
82+
* `Trusted Publishers`_ on PyPI: This allows the actions to authenticate
83+
without having to share API tokens around
84+
85+
86+
.. _GitHub Actions environmnents: https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/managing-environments-for-deployment
87+
.. _Trusted Publishers: https://docs.pypi.org/trusted-publishers/
88+

0 commit comments

Comments
 (0)