Skip to content

Commit

Permalink
Merge pull request #84 from kpetremann/improve_distribution
Browse files Browse the repository at this point in the history
Pypi distribution
  • Loading branch information
kpetremann authored Jun 14, 2024
2 parents 10de33d + 6cf6ee3 commit 1e73cdd
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 83 deletions.
51 changes: 25 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Run linters and tests'
name: "Run linters and tests"

on: [push, pull_request]

Expand All @@ -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/
50 changes: 50 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -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
95 changes: 47 additions & 48 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paho-mqtt
prometheus-client
8 changes: 6 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
paho-mqtt
prometheus-client
# 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
6 changes: 6 additions & 0 deletions requirements/tests.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
black
isort
pylint
pytest
pytest-mock
ruff
61 changes: 55 additions & 6 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
black
isort
pylint
pytest
pytest-mock
ruff
# 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

0 comments on commit 1e73cdd

Please sign in to comment.