Skip to content

Commit 02d0a5a

Browse files
authored
Create GitHub action to automate pypi publish (#1216)
1 parent cfdbf0b commit 02d0a5a

File tree

2 files changed

+70
-52
lines changed

2 files changed

+70
-52
lines changed

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Upload Python Package
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
release-build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
16+
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Build release distributions
21+
run: ./scripts/pip.sh
22+
23+
- name: Upload distributions
24+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
25+
with:
26+
name: release-dists
27+
path: /tmp/mesoprelease-test/
28+
29+
pypi-publish:
30+
runs-on: ubuntu-latest
31+
32+
needs:
33+
- release-build
34+
35+
permissions:
36+
# IMPORTANT: this permission is mandatory for trusted publishing
37+
id-token: write
38+
39+
# Dedicated environments with protections for publishing are strongly recommended.
40+
environment:
41+
name: pypi
42+
url: https://pypi.org/p/mesop
43+
44+
steps:
45+
- name: Retrieve release distributions
46+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
47+
with:
48+
name: release-dists
49+
path: dist/
50+
51+
- name: Publish release distributions to PyPI
52+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4

docs/internal/publishing.md

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
Follow these instructions for releasing a new version of Mesop publicly via PyPI (e.g. `pip install mesop`).
44

5-
If you haven't done this before, follow the [first-time setup](#first-time-upload-setup).
6-
75
## Check main branch
86

97
Before, cutting a release, you'll want to check two things:
108

119
1. The `main` branch should be healthy (e.g. latest commit is green).
1210
2. Check the [snyk dashboard](https://app.snyk.io/org/wwwillchen/project/756c376f-d2e7-44f8-9c20-e4062fdf543f) to review security issues:
13-
- It only runs weekly so you need to click "Retest now". If there's any High security issues for a core Mesop file (e.g. anything in `mesop/*`), then you should address it before publishing a release.
11+
12+
- It only runs weekly so you need to click "Retest now". If there's any High security issues for a core Mesop file (e.g. anything in `mesop/*`), then you should address it before publishing a release.
1413

1514
## Update version to RC
1615

@@ -20,53 +19,41 @@ You want to first create an RC (release candidate) to ensure that it works.
2019

2120
For example, if the current version is: `0.7.0`, then you should increment the version to `0.8.0rc1` which will create an RC, which is treated as a [pre-release by PyPI](https://packaging.python.org/en/latest/specifications/version-specifiers/#pre-releases).
2221

23-
## Install locally
22+
Merge the PR that bumps the version and then go to the next step to publish a GitHub release which will in turn publish to PyPI.
2423

25-
From the workspace root, run the following command:
24+
## Publish GitHub release
2625

27-
```sh
28-
source ./scripts/pip.sh
29-
```
26+
After you've submitted the PR which bumps the version and then [publish a GitHub release](https://github.com/google/mesop/releases/new).
3027

31-
This will build the Mesop pip package and install it locally so you can test it.
28+
1. Click "Choose a tag" and type in the version you just released. This will create a new Git tag.
29+
1. Click "Generate release notes".
30+
1. **If this is a an RC:** Click "Set as a pre-release", **otherwise** leave the "Set as the latest release" checked.
31+
1. If this is a regular (non-RC) release, click "Create a discussion for this release".
32+
1. Click "Publish release".
3233

3334
## Testing locally
3435

35-
> TIP: Double check the Mesop version is expected. It's easy to use the wrong version of Mesop by loading `mesop` or `gunicorn` from a different Python path (i.e. not the venv you just created).
36+
**Pre-requisite:** you will need to [install uv](https://docs.astral.sh/uv/getting-started/installation/) before doing the following steps.
3637

3738
### Dev CLI
3839

39-
The above shell script will tell you to run the following command:
40+
Run the following command but replace `0.1.0rc1` with the version that you just published:
4041

4142
```sh
42-
mesop main.py
43+
uvx mesop==0.1.0rc1 scripts/smoketest_app/main.py
4344
```
4445

45-
This will start the Mesop dev server and you can test that hot reload works.
46+
This will start the Mesop dev server and you can test that hot reload works. Double-check that the version shown is the version that you just released.
4647

4748
### Gunicorn integration
4849

49-
```sh
50-
gunicorn main:me
51-
```
52-
53-
> Note: `gunicorn` should already be installed by the shell script above.
54-
55-
## Upload to PyPI
56-
57-
If the testing above looks good, then continue with uploading to PyPI.
50+
Run the following command but replace `0.1.0rc1` with the version that you just published:
5851

5952
```sh
60-
rm -rf /tmp/mesoprelease-test/venv-twine \
61-
&& virtualenv --python python3 /tmp/mesoprelease-test/venv-twine \
62-
&& source /tmp/mesoprelease-test/venv-twine/bin/activate \
63-
&& pip install --upgrade pip \
64-
&& pip install twine \
65-
&& cd /tmp/mesoprelease-test \
66-
&& twine upload mesop*.whl
53+
cd scripts/smoketest_app/ && uvx --with mesop==0.1.0rc1 gunicorn@latest main:me
6754
```
6855

69-
Visit [https://pypi.org/project/mesop/](https://pypi.org/project/mesop/) to see that the new version has been published.
56+
This will launch Mesop under the Gunicorn server so you can make sure it works as expected.
7057

7158
## Test on Colab
7259

@@ -90,25 +77,4 @@ If all the testing looks good, then you can update [`mesop/version.py`](https://
9077

9178
`0.8.0rc1` -> `0.8.0`
9279

93-
Re-do the steps above to build, test and upload it to PyPI.
94-
95-
## Publish GitHub release
96-
97-
After you've uploaded a new regular release to PyPI, submit the PR which bumps the version and then [publish a GitHub release](https://github.com/google/mesop/releases/new).
98-
99-
1. Click "Choose a tag" and type in the version you just released. This will create a new Git tag.
100-
1. Click "Genereate release notes".
101-
1. Click "Create a discussion for this release".
102-
1. Click "Publish release".
103-
104-
## First-time upload setup
105-
106-
Create a file `~/.pypirc`:
107-
108-
```yaml
109-
[pypi]
110-
username = __token__
111-
password = {{password}}
112-
```
113-
114-
You will need to get a PyPI token generated by one of the project maintainers.
80+
Re-do the steps above to publish and test the release.

0 commit comments

Comments
 (0)