Skip to content

Commit 924bd33

Browse files
authored
Merge pull request #624 from ably/release-job
chore: add GitHub Actions workflow for publishing to PyPI and TestPyPI
2 parents 181ae3d + eadfdaa commit 924bd33

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

.github/workflows/release.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Publish Python distribution to PyPI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]+*'
8+
9+
jobs:
10+
build:
11+
name: Build distribution 📦
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: 'recursive'
18+
- name: Set up Python 3.12
19+
uses: actions/setup-python@v5
20+
id: setup-python
21+
with:
22+
python-version: 3.12
23+
24+
- name: Setup poetry
25+
uses: abatilo/actions-poetry@v4
26+
with:
27+
poetry-version: '2.1.4'
28+
29+
- name: Setup a local virtual environment
30+
run: |
31+
poetry env use ${{ steps.setup-python.outputs.python-path }}
32+
poetry run python --version
33+
poetry config virtualenvs.create true --local
34+
poetry config virtualenvs.in-project true --local
35+
36+
- uses: actions/cache@v4
37+
name: Define a cache for the virtual environment based on the dependencies lock file
38+
id: cache
39+
with:
40+
path: ./.venv
41+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
42+
43+
- name: Ensure cache is healthy
44+
if: steps.cache.outputs.cache-hit == 'true'
45+
shell: bash
46+
run: poetry run pip --version >/dev/null 2>&1 || (echo "Cache is broken, skip it" && rm -rf .venv)
47+
48+
- name: Install dependencies
49+
run: poetry install -E crypto
50+
- name: Generate rest sync code and tests
51+
run: poetry run unasync
52+
- name: Build a binary wheel and a source tarball
53+
run: poetry build
54+
- name: Store the distribution packages
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: python-package-distributions
58+
path: dist/
59+
60+
publish-to-pypi:
61+
name: Publish Python distribution to PyPI
62+
if: startsWith(github.ref, 'refs/tags/v') # only publish to PyPI on tag pushes
63+
needs:
64+
- build
65+
runs-on: ubuntu-latest
66+
environment:
67+
name: pypi
68+
url: https://pypi.org/p/ably
69+
permissions:
70+
id-token: write # IMPORTANT: mandatory for trusted publishing
71+
72+
steps:
73+
- name: Extract tag
74+
id: tag
75+
run: |
76+
TAG=${GITHUB_REF#refs/tags/v}
77+
echo "tag=$TAG" >> $GITHUB_OUTPUT
78+
79+
- name: Read VERSION_NAME from pyproject.toml
80+
id: version
81+
run: |
82+
VERSION_NAME=$(grep '^version' pyproject.toml | cut -d'=' -f2 | tr -d '[:space:]')
83+
echo "version=$VERSION_NAME" >> $GITHUB_OUTPUT
84+
85+
- name: Compare version with tag
86+
run: |
87+
if [ "$VERSION" != "$TAG" ]; then
88+
echo "VERSION ($VERSION) does not match tag ($TAG)."
89+
exit 1
90+
fi
91+
env:
92+
VERSION: ${{ steps.version.outputs.version }}
93+
TAG: ${{ steps.tag.outputs.tag }}
94+
- name: Download all the dists
95+
uses: actions/download-artifact@v4
96+
with:
97+
name: python-package-distributions
98+
path: dist/
99+
- name: Publish distribution 📦 to PyPI
100+
uses: pypa/gh-action-pypi-publish@release/v1
101+
102+
publish-to-testpypi:
103+
name: Publish Python distribution to TestPyPI
104+
needs:
105+
- build
106+
runs-on: ubuntu-latest
107+
108+
environment:
109+
name: testpypi
110+
url: https://test.pypi.org/p/ably
111+
112+
permissions:
113+
id-token: write # IMPORTANT: mandatory for trusted publishing
114+
115+
steps:
116+
- name: Download all the dists
117+
uses: actions/download-artifact@v4
118+
with:
119+
name: python-package-distributions
120+
path: dist/
121+
- name: Publish distribution 📦 to TestPyPI
122+
uses: pypa/gh-action-pypi-publish@release/v1
123+
with:
124+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)