From fcbd32b895be7cabf2b921d065f8793246fa998c Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 13 Feb 2023 15:04:32 +0100 Subject: [PATCH 1/5] Docker: Use more recent baseline image `python:3.11-slim-bullseye` --- CHANGES.rst | 2 ++ Dockerfile | 2 +- Dockerfile.full | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index eea1322b..d1569838 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,8 @@ mqttwarn changelog in progress =========== +- Modernize Docker configuration, now using Debian bullseye and Python 3.11. + 2022-11-21 0.31.0 ================= diff --git a/Dockerfile b/Dockerfile index 8ea61450..46e81571 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ # # docker build --tag=mqttwarn-local . # -FROM python:3.9-slim-buster +FROM python:3.11-slim-bullseye # Create /etc/mqttwarn RUN mkdir -p /etc/mqttwarn diff --git a/Dockerfile.full b/Dockerfile.full index c30f0c40..b9fd9f79 100644 --- a/Dockerfile.full +++ b/Dockerfile.full @@ -5,7 +5,7 @@ # # docker build --tag=mqttwarn-local-full --file=Dockerfile.full . # -FROM python:3.9-slim-buster +FROM python:3.11-slim-bullseye # Install additional requirements # FIXME: Skip all packages needing compilation From 6217dc98985ec5debc7ffc735e8f47c9666ee051 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 13 Feb 2023 15:05:57 +0100 Subject: [PATCH 2/5] Docker: Adjust image builder configuration - Use semver tagging for releases. - Build and publish images on pull requests. --- .github/workflows/release-docker-full.yml | 7 ++++--- .github/workflows/release-docker-standard.yml | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release-docker-full.yml b/.github/workflows/release-docker-full.yml index 425df2ca..7ce38fbb 100644 --- a/.github/workflows/release-docker-full.yml +++ b/.github/workflows/release-docker-full.yml @@ -44,7 +44,9 @@ jobs: # Generate Docker tags based on the following events/attributes tags: | type=schedule,pattern=nightly - type=ref,event=tag + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} - name: Inspect meta run: | @@ -75,7 +77,6 @@ jobs: echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - name: Login to GHCR - if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: registry: ghcr.io @@ -90,7 +91,7 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - push: ${{ github.event_name != 'pull_request' }} + push: true cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new diff --git a/.github/workflows/release-docker-standard.yml b/.github/workflows/release-docker-standard.yml index 59178211..fb40a00c 100644 --- a/.github/workflows/release-docker-standard.yml +++ b/.github/workflows/release-docker-standard.yml @@ -44,7 +44,9 @@ jobs: # Generate Docker tags based on the following events/attributes tags: | type=schedule,pattern=nightly - type=ref,event=tag + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} - name: Inspect meta run: | @@ -75,7 +77,6 @@ jobs: echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - name: Login to GHCR - if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: registry: ghcr.io @@ -90,7 +91,7 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - push: ${{ github.event_name != 'pull_request' }} + push: true cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new From 8b8341a20f5bbfcf1a8bcf09cb2d02587199ef67 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 13 Feb 2023 14:09:24 +0100 Subject: [PATCH 3/5] CI: Downgrade runner OS to retain support for Python 3.6 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 01d533d0..0e509677 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-20.04, macos-latest, windows-latest] python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] exclude: From 643de58b0e1708352c312b037d31a986ecbaacc2 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 13 Feb 2023 14:59:26 +0100 Subject: [PATCH 4/5] CI: Disable testing on Python 3.12 --- .github/workflows/tests.yml | 2 +- setup.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0e509677..78f7353c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: os: [ubuntu-20.04, macos-latest, windows-latest] - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] # "3.12-dev" exclude: # Breaks on building `winsdk` diff --git a/setup.py b/setup.py index db23bf7c..01a3944a 100644 --- a/setup.py +++ b/setup.py @@ -197,7 +197,6 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", "Topic :: Communications", "Topic :: Education", "Topic :: Internet", From 734710cfa67b19c6384061b59b40ec79f507405e Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 13 Feb 2023 15:37:57 +0100 Subject: [PATCH 5/5] Project metadata: Add versioning based on Git tags, using `versioningit` --- .bumpversion.cfg | 15 --------------- .dockerignore | 2 ++ .github/workflows/release-docker-full.yml | 2 ++ .github/workflows/release-docker-standard.yml | 2 ++ .github/workflows/tests.yml | 2 +- CHANGES.rst | 4 ++++ Dockerfile | 5 ++++- Dockerfile.full | 4 +++- Makefile | 5 +++-- mqttwarn/__init__.py | 11 ++++++++--- pyproject.toml | 19 +++++++++++++++++++ requirements-release.txt | 2 +- setup.py | 6 ++++-- 13 files changed, 53 insertions(+), 26 deletions(-) delete mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index e2f7a208..00000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,15 +0,0 @@ -[bumpversion] -current_version = 0.31.0 -files = setup.py mqttwarn/__init__.py -commit = True -tag = True -tag_name = {new_version} -allow_dirty = False - -[bumpversion:file:setup.py] -search = version="{current_version}" -replace = version="{new_version}" - -[bumpversion:file:mqttwarn/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" diff --git a/.dockerignore b/.dockerignore index 0d1c2b3e..5a3047e7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,9 @@ * +!.git !etc !mqttwarn !tests +!pyproject.toml !setup.py !MANIFEST.in !*.ini diff --git a/.github/workflows/release-docker-full.yml b/.github/workflows/release-docker-full.yml index 7ce38fbb..b20f94b5 100644 --- a/.github/workflows/release-docker-full.yml +++ b/.github/workflows/release-docker-full.yml @@ -33,6 +33,8 @@ jobs: - name: Acquire sources uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Docker meta id: meta diff --git a/.github/workflows/release-docker-standard.yml b/.github/workflows/release-docker-standard.yml index fb40a00c..41ce1bb7 100644 --- a/.github/workflows/release-docker-standard.yml +++ b/.github/workflows/release-docker-standard.yml @@ -33,6 +33,8 @@ jobs: - name: Acquire sources uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Docker meta id: meta diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 78f7353c..a8b7320c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -61,7 +61,7 @@ jobs: - name: Setup project run: | # Install package in editable mode. - pip install wheel + pip install versioningit wheel pip install --editable=.[test,develop] - name: Check code style diff --git a/CHANGES.rst b/CHANGES.rst index d1569838..085ff7d2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,10 @@ in progress =========== - Modernize Docker configuration, now using Debian bullseye and Python 3.11. +- Improve nightly and on-PR Docker builds. +- Add versioning based on Git tags, using ``versioningit``. This will aid in + telling PR- and nightly releases apart from GA releases when running + ``mqttwarn --version``. 2022-11-21 0.31.0 diff --git a/Dockerfile b/Dockerfile index 46e81571..07293132 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,9 @@ # FROM python:3.11-slim-bullseye +# Install additional requirements +RUN apt-get update && apt-get install --yes git + # Create /etc/mqttwarn RUN mkdir -p /etc/mqttwarn WORKDIR /etc/mqttwarn @@ -17,7 +20,7 @@ RUN chown -R mqttwarn:mqttwarn /etc/mqttwarn # Install mqttwarn COPY . /src -RUN pip install wheel +RUN pip install versioningit wheel RUN pip install /src # Make process run as "mqttwarn" user diff --git a/Dockerfile.full b/Dockerfile.full index b9fd9f79..47aff4d5 100644 --- a/Dockerfile.full +++ b/Dockerfile.full @@ -8,6 +8,8 @@ FROM python:3.11-slim-bullseye # Install additional requirements +RUN apt-get update && apt-get install --yes git + # FIXME: Skip all packages needing compilation #RUN apt-get update && apt-get install --yes librrd-dev @@ -21,7 +23,7 @@ RUN chown -R mqttwarn:mqttwarn /etc/mqttwarn # Install mqttwarn COPY . /src -RUN pip install wheel +RUN pip install versioningit wheel RUN pip install /src[all] # Make process run as "mqttwarn" user diff --git a/Makefile b/Makefile index 313fa453..66b619d9 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ $(eval venvpath := .venv) $(eval pip := $(venvpath)/bin/pip) $(eval python := $(venvpath)/bin/python) $(eval pytest := $(venvpath)/bin/pytest) -$(eval bumpversion := $(venvpath)/bin/bumpversion) +$(eval minibump := $(venvpath)/bin/minibump) $(eval twine := $(venvpath)/bin/twine) $(eval sphinx := $(venvpath)/bin/sphinx-build) $(eval isort := $(venvpath)/bin/isort) @@ -21,6 +21,7 @@ $(eval poe := $(venvpath)/bin/poe) # Setup Python virtualenv setup-virtualenv: @test -e $(python) || python3 -m venv $(venvpath) + $(pip) install versioningit # ------- @@ -71,7 +72,7 @@ docs-html: install-doctools # Utility targets # =============== bumpversion: install-releasetools - @$(bumpversion) $(bump) + @$(minibump) bump --relax $(bump) push: git push && git push --tags diff --git a/mqttwarn/__init__.py b/mqttwarn/__init__.py index 433ee844..8cce348b 100644 --- a/mqttwarn/__init__.py +++ b/mqttwarn/__init__.py @@ -1,8 +1,13 @@ # -*- coding: utf-8 -*- -# (c) 2014-2018 The mqttwarn developers - -__version__ = "0.31.0" +# (c) 2014-2023 The mqttwarn developers __author__ = "Jan-Piet Mens , Ben Jones " __copyright__ = "Copyright 2014-2022 Jan-Piet Mens" __license__ = "Eclipse Public License - v 2.0 (http://www.eclipse.org/legal/epl-2.0/)" + +try: + from importlib.metadata import version +except ImportError: + from importlib_metadata import version # type: ignore[no-redef] + +__version__ = version("mqttwarn") diff --git a/pyproject.toml b/pyproject.toml index d89f17f8..f0ec95d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,22 @@ +# ================== +# Build system setup +# ================== + +[build-system] +requires = [ + "setuptools>=42", # At least v42 of setuptools required! + "versioningit", +] +build-backend = "setuptools.build_meta" + + +[tool.versioningit] + +[tool.versioningit.vcs] +method = "git" +default-tag = "0.0.0" + + # ========================= # Linter and code formatter # ========================= diff --git a/requirements-release.txt b/requirements-release.txt index 7c066778..348c0d4a 100644 --- a/requirements-release.txt +++ b/requirements-release.txt @@ -1,3 +1,3 @@ -bump2version +minibump<1; python_version>='3.10' twine keyring diff --git a/setup.py b/setup.py index 01a3944a..501a5210 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -# (c) 2014-2022 The mqttwarn developers +# (c) 2014-2023 The mqttwarn developers import os import platform from setuptools import find_packages, setup +from versioningit import get_cmdclasses here = os.path.abspath(os.path.dirname(__file__)) README = open(os.path.join(here, "README.rst")).read() @@ -16,6 +17,7 @@ "docopt<1", "requests<3", "future>=0.18.0,<1", + "importlib-metadata; python_version<'3.8'", ] extras = { @@ -170,8 +172,8 @@ setup( + cmdclass=get_cmdclasses(), name="mqttwarn", - version="0.31.0", description="mqttwarn - subscribe to MQTT topics and notify pluggable services", long_description=README, license="EPL 2.0",