Skip to content

Commit 39f132b

Browse files
committed
Add pypi publish on release action
1 parent a190f27 commit 39f132b

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

.github/workflows/release.yaml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: Publish releases
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
release:
7+
types: [published]
8+
env:
9+
PYTHON_VERSION: "3.12"
10+
11+
jobs:
12+
build-and-publish-pypi:
13+
name: Builds and publishes releases to PyPI
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/[email protected]
17+
- name: Get tag
18+
id: vars
19+
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
20+
- name: Validate version number
21+
run: >-
22+
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
23+
if ! [[ "${tag}" =~ "b" ]]; then
24+
echo "Pre-release: Tag is missing beta suffix (${tag})"
25+
exit 1
26+
fi
27+
else
28+
if [[ "${tag}" =~ "b" ]]; then
29+
echo "Release: Tag must not have a beta suffix (${tag})"
30+
exit 1
31+
fi
32+
fi
33+
- name: Set up Python ${{ env.PYTHON_VERSION }}
34+
uses: actions/[email protected]
35+
with:
36+
python-version: ${{ env.PYTHON_VERSION }}
37+
- name: Install build
38+
run: >-
39+
pip install build tomli tomli-w
40+
- name: Set Python project version from tag
41+
shell: python
42+
run: |-
43+
import tomli
44+
import tomli_w
45+
46+
with open("pyproject.toml", "rb") as f:
47+
pyproject = tomli.load(f)
48+
49+
pyproject["project"]["version"] = "${tag}"
50+
51+
with open("pyproject.toml", "wb") as f:
52+
tomli_w.dump(pyproject, f)
53+
- name: Build python package
54+
run: >-
55+
python3 -m build
56+
- name: Publish release to PyPI
57+
uses: pypa/[email protected]
58+
with:
59+
user: __token__
60+
password: ${{ secrets.PYPI_TOKEN }}
61+
- name: Wait for PyPI
62+
run: sleep 300

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "aiohasupervisor"
7-
version = "0.1.0"
87
license = { text = "Apache-2.0" }
98
description = "Asynchronous python client for Home Assistant Supervisor."
109
readme = "README.md"
@@ -19,6 +18,8 @@ dependencies = [
1918
"orjson>=3.6.1,<4.0.0",
2019
"yarl>=1.6.0,<2.0.0",
2120
]
21+
# The version is set by GH action on release!
22+
version = "0.0.0"
2223

2324
[project.optional-dependencies]
2425
dev = [

0 commit comments

Comments
 (0)