Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pypi publish on release action #3

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
name: Publish releases

# yamllint disable-line rule:truthy
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version for release on TestPyPI"
required: true
env:
PYTHON_VERSION: "3.12"

jobs:
build:
name: Builds and publishes releases to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Store version from inputs
if: github.event_name == 'workflow_dispatch'
run: echo "tag=${{ inputs.version }}"
- name: Get version from tag
if: github.event_name == 'release'
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Validate version number
if: github.event_name == 'release'
run: >-
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
if ! [[ "${tag}" =~ "b" ]]; then
echo "Pre-release: Tag is missing beta suffix (${tag})"
exit 1
fi
else
if [[ "${tag}" =~ "b" ]]; then
echo "Release: Tag must not have a beta suffix (${tag})"
exit 1
fi
fi
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install build
run: >-
pip install build tomli tomli-w
- name: Set Python project version from tag
shell: python
run: |-
import tomli
import tomli_w

with open("pyproject.toml", "rb") as f:
pyproject = tomli.load(f)

pyproject["project"]["version"] = "${tag}"

with open("pyproject.toml", "wb") as f:
tomli_w.dump(pyproject, f)
- name: Build python package
run: >-
python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-pypi:
name: Publishes releases to PyPI
runs-on: ubuntu-latest
if: github.event_name == 'release'
needs:
- build
environment:
name: pypi
url: https://pypi.org/p/aiohasupervisor
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-test-pypi:
name: Publishes releases to Test-PyPI
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
needs:
- build
environment:
name: testpypi
url: https://test.pypi.org/p/aiohasupervisor
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build-backend = "setuptools.build_meta"

[project]
name = "aiohasupervisor"
version = "0.1.0"
license = { text = "Apache-2.0" }
description = "Asynchronous python client for Home Assistant Supervisor."
readme = "README.md"
Expand All @@ -19,6 +18,8 @@ dependencies = [
"orjson>=3.6.1,<4.0.0",
"yarl>=1.6.0,<2.0.0",
]
# The version is set by GH action on release!
version = "0.0.0"

[project.optional-dependencies]
dev = [
Expand Down
Loading