Skip to content

v0.37.2

v0.37.2 #71

name: Build and Upload CLI Python Package
on:
release:
types: [published]
permissions:
contents: read
jobs:
build-release-distributions:
runs-on: ubuntu-latest
defaults:
run:
working-directory: cli
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Ensure version is set in pyproject.toml
run: |
set -euo pipefail
PYPROJECT_VERSION=$(awk -F '"' '/^\s*version\s*=\s*"/ {print $2; exit}' pyproject.toml)
if [ -z "${PYPROJECT_VERSION:-}" ]; then
echo "ERROR: Unable to read cli [project].version from cli/pyproject.toml"
exit 1
fi
echo "CLI version in pyproject.toml: $PYPROJECT_VERSION"
- name: Check if version already exists on PyPI
run: |
set -euo pipefail
PKG_NAME=$(grep -E '^name\s*=\s*' pyproject.toml | head -1 | sed 's/name\s*=\s*"\(.*\)"/\1/')
PKG_VERSION=$(grep -E '^version\s*=\s*' pyproject.toml | head -1 | sed 's/version\s*=\s*"\(.*\)"/\1/')
echo "Package name: $PKG_NAME"
echo "Package version: $PKG_VERSION"
echo "Checking if version exists on PyPI..."
EXISTS=$(curl -s "https://pypi.org/pypi/$PKG_NAME/json" | grep -F "\"$PKG_VERSION\"" || true)
if [ -n "$EXISTS" ]; then
echo "Error: Version $PKG_VERSION of $PKG_NAME already exists on PyPI." >&2
exit 1
fi
- name: Build release distributions
run: |
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: cli/dist/
pypi-publish:
runs-on: ubuntu-latest
needs:
- build-release-distributions
environment:
name: pypi
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
password: ${{ secrets.PYPI_API_TOKEN }}