Skip to content

Commit

Permalink
first locally working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
miaucl committed Sep 1, 2024
0 parents commit 728951f
Show file tree
Hide file tree
Showing 35 changed files with 2,444 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
59 changes: 59 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build documentation

on:
push:
branches:
- master

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

# Default to bash
defaults:
run:
shell: bash

env:
DEFAULT_PYTHON: "3.12"

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements_dev.txt
- name: Build
run: mkdocs build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./site

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
17 changes: 17 additions & 0 deletions .github/workflows/markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Markdownlint

on: [ push, pull_request ]

jobs:
markdownlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v16
with:
config: '.markdownlint.yaml'
globs: |
**/*.md
!docs/changelog.md
!docs/index.md
!docs/license.md
18 changes: 18 additions & 0 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Mypy

on: [ push, pull_request ]

env:
DEFAULT_PYTHON: "3.12"

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- run: pip install -r requirements_dev.txt
- run: mypy systemctl2mqtt
154 changes: 154 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: Publish

on: 'push'

env:
DEFAULT_PYTHON: "3.12"

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- name: Install pypa/build
run: >-
python3 -m
pip install -r requirements.txt
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

check_version:
name: Check the version
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract tag version
id: extract_tag
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/}
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
- name: Extract version from file
id: extract_file_version
run: |
VERSION=$(grep '__VERSION__' ./systemctl2mqtt/__init__.py | sed -E 's/__VERSION__ = "(.*)"/\1/')
echo "FILE_VERSION=$VERSION" >> $GITHUB_ENV
- name: Extract version from setup config
id: extract_config_version
run: |
VERSION=$(grep 'version' ./setup.cfg | sed -E 's/version = (.*)[[:space:]]*$/\1/')
echo "CONFIG_VERSION=$VERSION" >> $GITHUB_ENV
- name: Compare versions
run: |
if [ "$TAG_VERSION" != "$FILE_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match file version ($FILE_VERSION)."
exit 1
elif [ "$TAG_VERSION" != "$CONFIG_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match config version ($CONFIG_VERSION)."
exit 1
else
echo "Tag version ($TAG_VERSION) matches file version ($FILE_VERSION)."
fi
- name: Check changelog entry
run: |
if [ github.ref =~ 'refs/tags/[0-9]+\\.[0-9]+\\.[0-9]+$' ]; then
if ! grep -q "## $TAG_VERSION" CHANGELOG.md; then
echo "No changelog entry found for version $TAG_VERSION."
exit 1
else
echo "Changelog entry found for version $TAG_VERSION."
fi
else
echo "Pre-release tag, skipping changelog check"
fi
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
needs: check_version
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/systemctl2mqtt # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Create GitHub release and attach binaries
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get version
id: version
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/}
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref }}
name: Release ${{ steps.version.outputs.version }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
10 changes: 10 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Ruff

on: [ push, pull_request ]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.venv
.mypy_cache
.ruff_cache
site
local-test.sh
systemctl2mqtt.egg-info
__pycache__
build
5 changes: 5 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default state for all rules
default: true

# MD013/line-length - Line length
MD013: false
3 changes: 3 additions & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docs/changelog.md
docs/index.md
docs/license.md
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.1
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: local
hooks:
# Run mypy through our wrapper script in order to get the possible
# pyenv and/or virtualenv activated; it may not have been e.g. if
# committing from a GUI tool that was not launched from an activated
# shell.
- id: mypy
name: mypy
entry: scripts/run-in-env.sh mypy --strict
language: script
types: [python]
require_serial: true
files: ^(systemctl2mqtt)/.+\.py$
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
hooks:
- id: markdownlint
args: ["--disable=MD013"]
- id: markdownlint-fix
args: ["--disable=MD013", "--fix"]
44 changes: 44 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cSpell.words": [
"blockinput",
"blockinputrate",
"BLOCKIO",
"blockoutput",
"blockoutputrate",
"gethostname",
"HOMEASSISTANT",
"journalctl",
"levelname",
"markdownlint",
"memorylimit",
"memoryused",
"miaucl",
"mkdocs",
"mosquitto",
"mqtt",
"mypy",
"netinput",
"netinputrate",
"netio",
"netoutput",
"netoutputrate",
"paho",
"Perc",
"pyenv",
"pypi",
"venv",
"virtualenv"
],
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
}
},
"python.testing.pytestArgs": [
"-v",
"--color=yes"
],
"python.analysis.typeCheckingMode": "basic"
}
Loading

0 comments on commit 728951f

Please sign in to comment.