Pre-commit hooks

This commit is contained in:
Xoconoch
2025-08-09 13:52:28 -06:00
parent 84cf57e451
commit c341d79e6b
3 changed files with 68 additions and 25 deletions

57
.github/scripts/ensure_compose_image.py vendored Normal file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import sys
from pathlib import Path
try:
import yaml
except Exception as e:
sys.stderr.write("PyYAML is required to run this hook.\n")
raise
EXPECTED_IMAGE = "cooldockerizer93/spotizerr"
def validate_compose_image(path: Path) -> int:
if not path.exists():
sys.stderr.write(f"File not found: {path}\n")
return 1
try:
with path.open("r", encoding="utf-8") as f:
data = yaml.safe_load(f)
except Exception as e:
sys.stderr.write(f"Failed to parse YAML from {path}: {e}\n")
return 1
image = (
(data or {})
.get("services", {})
.get("spotizerr", {})
.get("image")
)
errors = []
if not isinstance(image, str):
errors.append("services.spotizerr.image is missing or not a string")
else:
if image != EXPECTED_IMAGE:
errors.append(
f"services.spotizerr.image must be '{EXPECTED_IMAGE}' (found '{image}')"
)
if errors:
sys.stderr.write("docker-compose.yaml validation failed:\n")
for err in errors:
sys.stderr.write(f" - {err}\n")
return 1
return 0
def main(argv: list[str]) -> int:
compose_path = Path(argv[1]) if len(argv) > 1 else Path("docker-compose.yaml")
return validate_compose_image(compose_path)
if __name__ == "__main__":
sys.exit(main(sys.argv))

View File

@@ -1,32 +1,11 @@
repos: repos:
# Various general + format-specific helpers # Various general + format-specific helpers
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 rev: v4.6.0
hooks: hooks:
- id: check-symlinks
exclude: ^spotizerr-ui/
- id: trailing-whitespace
exclude: ^spotizerr-ui/
- id: mixed-line-ending
args: [--fix=lf]
exclude: ^spotizerr-ui/
- id: check-yaml - id: check-yaml
exclude: 'mkdocs.yml|^spotizerr-ui/' - id: end-of-file-fixer
- id: check-toml - id: trailing-whitespace
exclude: ^spotizerr-ui/
- id: check-json
exclude: ^spotizerr-ui/
- id: check-ast
exclude: ^spotizerr-ui/
- id: debug-statements
exclude: ^spotizerr-ui/
- id: check-merge-conflict
exclude: ^spotizerr-ui/
- id: check-shebang-scripts-are-executable
exclude: ^spotizerr-ui/
- id: check-added-large-files
args: [--maxkb=10000]
exclude: ^spotizerr-ui/
- repo: https://github.com/python-jsonschema/check-jsonschema - repo: https://github.com/python-jsonschema/check-jsonschema
rev: '0.33.0' rev: '0.33.0'
hooks: hooks:
@@ -53,3 +32,10 @@ repos:
exclude: ^spotizerr-ui/ exclude: ^spotizerr-ui/
# NOTE: you might need to add some deps here: # NOTE: you might need to add some deps here:
additional_dependencies: [waitress==3.0.2, types-waitress, types-requests] additional_dependencies: [waitress==3.0.2, types-waitress, types-requests]
- repo: local
hooks:
- id: ensure-compose-image
name: Ensure docker-compose image is cooldockerizer93/spotizerr
entry: python3 .github/scripts/ensure_compose_image.py docker-compose.yaml
language: system
files: ^docker-compose\.ya?ml$

View File

@@ -2,7 +2,7 @@ name: spotizerr
services: services:
spotizerr: spotizerr:
image: cooldockerizer93/spotizerr:beta image: cooldockerizer93/spotizerr:eee
volumes: volumes:
- ./data:/app/data - ./data:/app/data
- ./downloads:/app/downloads # <-- Change this for your music library dir - ./downloads:/app/downloads # <-- Change this for your music library dir