diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5927d6..c6772c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: 'Run linters and tests' +name: "Run linters and tests" on: [push, pull_request] @@ -10,28 +10,27 @@ jobs: python-version: ["3.8", "3.9", "3.10"] steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements/dev.txt - - - name: Lint with Ruff - run: ruff . - - - name: Lint with Black - run: black . --check --diff - - - name: Lint with isort - run: isort . --check --diff - - - name: Test with pytest - run: pytest tests/ + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements/dev.txt + + - name: Lint with Ruff + run: ruff . + + - name: Lint with Black + run: black . --check --diff + + - name: Lint with isort + run: isort . --check --diff + + - name: Test with pytest + run: pytest tests/ diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..6ef4325 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,50 @@ +name: "Publish to pypi" + +on: + push: + tags: + - "v*" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + if: startsWith(github.ref, 'refs/tags/') + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/mqtt-exporter + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 074d979..4bcaca8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,59 +1,58 @@ -name: 'Build and publish docker images (all platforms)' +name: "Build and publish docker images (all platforms)" on: push: branches: - master tags: - - 'v*' + - "v*" jobs: release: runs-on: ubuntu-latest steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ${{ secrets.DOCKERHUB_USERNAME }}/mqtt-exporter - ghcr.io/${{ github.repository_owner }}/mqtt-exporter - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up QEMU - id: qemu - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x - push: true - tags: ${{ steps.meta.outputs.tags }} + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ secrets.DOCKERHUB_USERNAME }}/mqtt-exporter + ghcr.io/${{ github.repository_owner }}/mqtt-exporter + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + push: true + tags: ${{ steps.meta.outputs.tags }} diff --git a/pyproject.toml b/pyproject.toml index 3c175bf..5e3ba85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mqtt-exporter" -version = "1.4.1" +version = "1.4.3" description = "Simple generic MQTT Prometheus exporter for IoT working out of the box" license = { text = "MIT License" } authors = [ diff --git a/requirements/base.in b/requirements/base.in new file mode 100644 index 0000000..26810f7 --- /dev/null +++ b/requirements/base.in @@ -0,0 +1,2 @@ +paho-mqtt +prometheus-client \ No newline at end of file diff --git a/requirements/base.txt b/requirements/base.txt index 26810f7..e946ff3 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,2 +1,6 @@ -paho-mqtt -prometheus-client \ No newline at end of file +# This file was autogenerated by uv via the following command: +# uv pip compile requirements/base.in -o requirements/base.txt +paho-mqtt==2.1.0 + # via -r requirements/base.in +prometheus-client==0.20.0 + # via -r requirements/base.in diff --git a/requirements/tests.in b/requirements/tests.in new file mode 100644 index 0000000..f86ef4b --- /dev/null +++ b/requirements/tests.in @@ -0,0 +1,6 @@ +black +isort +pylint +pytest +pytest-mock +ruff \ No newline at end of file diff --git a/requirements/tests.txt b/requirements/tests.txt index f86ef4b..94adb82 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,6 +1,55 @@ -black -isort -pylint -pytest -pytest-mock -ruff \ No newline at end of file +# This file was autogenerated by uv via the following command: +# uv pip compile requirements/tests.in -o requirements/tests.txt +astroid==3.2.2 + # via pylint +black==24.4.2 + # via -r requirements/tests.in +click==8.1.7 + # via black +dill==0.3.8 + # via pylint +exceptiongroup==1.2.1 + # via pytest +iniconfig==2.0.0 + # via pytest +isort==5.13.2 + # via + # -r requirements/tests.in + # pylint +mccabe==0.7.0 + # via pylint +mypy-extensions==1.0.0 + # via black +packaging==24.0 + # via + # black + # pytest +pathspec==0.12.1 + # via black +platformdirs==4.2.2 + # via + # black + # pylint +pluggy==1.5.0 + # via pytest +pylint==3.2.2 + # via -r requirements/tests.in +pytest==8.2.2 + # via + # -r requirements/tests.in + # pytest-mock +pytest-mock==3.14.0 + # via -r requirements/tests.in +ruff==0.4.7 + # via -r requirements/tests.in +tomli==2.0.1 + # via + # black + # pylint + # pytest +tomlkit==0.12.5 + # via pylint +typing-extensions==4.12.1 + # via + # astroid + # black