From 96d482651fdae916b4163ec8137e97c67a337f50 Mon Sep 17 00:00:00 2001 From: nik-localstack Date: Wed, 27 May 2026 10:54:47 +0300 Subject: [PATCH] chore: switch to tag-based releases --- .github/workflows/{tests.yml => build.yml} | 50 ++++++++++++++++++---- .gitignore | 3 ++ Makefile | 18 +++++--- postgresql_proxy/__init__.py | 1 + pyproject.toml | 26 +++++++++++ setup.py | 20 --------- 6 files changed, 85 insertions(+), 33 deletions(-) rename .github/workflows/{tests.yml => build.yml} (58%) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/tests.yml b/.github/workflows/build.yml similarity index 58% rename from .github/workflows/tests.yml rename to .github/workflows/build.yml index 95e7159..82a235e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,14 @@ -name: Run Tests +name: CI on: - pull_request: push: - branches: - - master + branches: [ master ] + paths-ignore: + - "README.md" + tags: + - "v*.*" + pull_request: + branches: [ master ] jobs: lint: @@ -33,8 +37,6 @@ jobs: POSTGRES_DB: postgres ports: - 5432:5432 - # The official postgres image does not expose a default Docker HEALTHCHECK, - # so we define one explicitly for the GitHub Actions service container. options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s @@ -63,5 +65,37 @@ jobs: make install-test - name: Run tests - run: | - make test + run: make test + + release: + needs: tests + runs-on: ubuntu-24.04 + + environment: + name: pypi + url: https://pypi.org/p/postgresql-proxy + + permissions: + id-token: write + + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Build release + run: make dist + + - name: List artifacts + run: ls -lah dist/ + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1b23d83..61f365c 100644 --- a/.gitignore +++ b/.gitignore @@ -111,3 +111,6 @@ venv.bak/ # private config information config.yml + +# Hatch VCS hook generates this file during build +postgresql_proxy/version.py diff --git a/Makefile b/Makefile index 10e70d6..37d83b5 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,18 @@ install: ## Install dependencies in local virtualenv folder (test `which virtualenv` || $(PIP_CMD) install virtualenv) && \ (test -e $(VENV_DIR) || virtualenv $(VENV_OPTS) $(VENV_DIR)) && \ ($(VENV_RUN) && $(PIP_CMD) install --upgrade pip) && \ - (test ! -e requirements.txt || ($(VENV_RUN); $(PIP_CMD) install -r requirements.txt)) + (test ! -e requirements.txt || ($(VENV_RUN); $(PIP_CMD) install -r requirements.txt)) && \ + ($(VENV_RUN); $(PIP_CMD) install -e .) -publish: ## Publish the library to the central PyPi repository - ($(VENV_RUN); pip install twine; python ./setup.py sdist && twine upload dist/*) +dist: clean ## Build distribution packages + python -m pip install -U build hatchling hatch-vcs + python -m build + +clean: ## Remove build artifacts + rm -rf dist build *.egg-info postgresql_proxy/version.py + +publish: dist ## Publish the library to the central PyPi repository + ($(VENV_RUN); pip install twine; twine upload dist/*) install-test: install ## Install test dependencies in local virtualenv ($(VENV_RUN); $(PIP_CMD) install -r $(TEST_REQS)) @@ -85,7 +93,7 @@ start-pg-and-test: ## Start local PostgreSQL container, run all tests, and clean exit $$status ACT_CMD ?= act -ACT_WORKFLOW ?= .github/workflows/tests.yml +ACT_WORKFLOW ?= .github/workflows/build.yml ACT_JOB ?= tests ACT_PULL ?= false ACT_CONTAINER_ARCH ?= linux/arm64 @@ -93,4 +101,4 @@ ACT_CONTAINER_ARCH ?= linux/arm64 test-act: ## Run the CI test workflow locally with act $(ACT_CMD) -W $(ACT_WORKFLOW) -j $(ACT_JOB) --pull=$(ACT_PULL) --container-architecture $(ACT_CONTAINER_ARCH) -.PHONY: usage install install-test install-lint clean publish lint start-postgres stop-postgres test test-act start-pg-and-test +.PHONY: usage install install-test install-lint dist clean publish lint start-postgres stop-postgres test test-act start-pg-and-test diff --git a/postgresql_proxy/__init__.py b/postgresql_proxy/__init__.py index e69de29..3e1c053 100644 --- a/postgresql_proxy/__init__.py +++ b/postgresql_proxy/__init__.py @@ -0,0 +1 @@ +from postgresql_proxy.version import __version__ # noqa diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b2fca16 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "postgresql-proxy" +dynamic = ["version"] +description = "Postgresql Proxy" +readme = "README.md" +requires-python = ">=3.10" +license = { text = "Apache-2.0" } +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.13", + "License :: OSI Approved :: Apache Software License", + "Topic :: Software Development :: Testing", +] + +[tool.ruff] +exclude = ["postgresql_proxy/version.py"] + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "postgresql_proxy/version.py" diff --git a/setup.py b/setup.py deleted file mode 100644 index 2221783..0000000 --- a/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from setuptools import find_packages, setup - -install_requires = [] - - -if __name__ == "__main__": - setup( - name="postgresql-proxy", - version="0.3.3", - description="Postgresql Proxy", - packages=find_packages(exclude=("tests", "tests.*")), - install_requires=install_requires, - zip_safe=False, - classifiers=[ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.13", - "License :: OSI Approved :: Apache Software License", - "Topic :: Software Development :: Testing", - ], - )